Override Replication Behavior | Community
Skip to main content
ravir73578276
Level 3
June 5, 2023
Solved

Override Replication Behavior

  • June 5, 2023
  • 3 replies
  • 1513 views

I have few pages in AEM. The pages have a jcr property "replicate":"true". As soon as the replication action triggers on the page. I need to  perform certain actions on the page on replicate event (like make a 3rd party api call to send the page data.) but at the same time I don't want my page to be replicated to publish instance if the replicate property is set to false.

How I can achieve this ?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by EstebanBustamante

I think you can listen to the REPLICATION event and do your logic when triggered. You just need to create a new Event Listener for that, here is an example of how to do it: https://aemhints.com/2020/11/08/event-listener-in-aem-6-5/ 

 

 

(service = EventHandler.class, immediate = true, property = { Constants.SERVICE_DESCRIPTION + "=Activation Event Listener ", EventConstants.EVENT_TOPIC + "=" + ReplicationAction.EVENT_TOPIC } ) @Designate(ocd = EventListener.EventListenerPageActivationListenerConfiguration.class) public class EventListener implements EventHandler { ..

 

3 replies

Vaibhavi_J
Level 7
June 5, 2023
EstebanBustamante
Community Advisor and Adobe Champion
EstebanBustamanteCommunity Advisor and Adobe ChampionAccepted solution
Community Advisor and Adobe Champion
June 5, 2023

I think you can listen to the REPLICATION event and do your logic when triggered. You just need to create a new Event Listener for that, here is an example of how to do it: https://aemhints.com/2020/11/08/event-listener-in-aem-6-5/ 

 

 

(service = EventHandler.class, immediate = true, property = { Constants.SERVICE_DESCRIPTION + "=Activation Event Listener ", EventConstants.EVENT_TOPIC + "=" + ReplicationAction.EVENT_TOPIC } ) @Designate(ocd = EventListener.EventListenerPageActivationListenerConfiguration.class) public class EventListener implements EventHandler { ..

 

Esteban Bustamante
lukasz-m
Community Advisor
Community Advisor
June 5, 2023

Hi @ravir73578276,

You should use Preprocessor, to achieve your goal. Here are the main arguments why:

  • this is part of AEM replication api, and it is dedicated entry point that is run just before replication is triggered
  • you do not need to create any additional replication agents or configurations
  • as this is part of replication flow, it is guarantee it will be run, unlike event listener you do not have to worry if you have picked up appropriate event topic, or if the event will be blacklisted etc
  • it gives you information about replication action type (e.g. Activation, Deactivation etc), path and others - so you can easily build some conditions that will run your code only in specific cases or for given paths
  • finally it allows you to stop replication process

Below you can find nice article that compares workflows, event listener and preprocessor, with explanation, when to use which mechanism. It also contains simple preprocessor code

In case you would like to see more advanced example you can check this one from ACS Commons: