Expand my Community achievements bar.

SOLVED

Override Replication Behavior

Avatar

Level 3

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 ?

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

View solution in original post

3 Replies

Avatar

Correct answer by
Community Advisor

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

Avatar

Community Advisor

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: