Replication listener for a defined path | Community
Skip to main content
salvadorm142499
Level 3
October 16, 2015
Solved

Replication listener for a defined path

  • October 16, 2015
  • 6 replies
  • 1991 views

Hi all,

I would like to create a replication listener for a defined path. The reason is I wouldn't like to fire the listener for each replication event, I am afraid about the performance of the author instance on production when replicating.

Any help?

Many thanks, Salva.

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 smacdonald2008

THere is more information here:

http://blogs.adobe.com/experiencedelivers/experience-management/event_handling_incq/

But there does not look like there is a way to only fire on a path. Code:

@Component
@Service
@Property(name="event.topics",value= {ReplicationAction.EVENT_TOPIC, Example.EVENT_TOPIC})
public class ExampleEventHandler implements EventHandler {
 Logger log = LoggerFactory.getLogger(this.getClass());
 public void handleEvent(Event event) {
  if (event.getTopic().equals(Example.EVENT_TOPIC)){
   log.info("Example {}, with description {} has been created...",event.getProperty(Example.PN_NAME),event.getProperty(Example.PN_DESC));
  } else if (event.getTopic().equals(ReplicationAction.EVENT_TOPIC)){
   ReplicationAction action = ReplicationAction.fromEvent(event);
   log.info("User {} has tried to replicate {}",action.getUserId(),action.getPath());
  }
 }
}

As stated - you can get the path and invoke app logic if a path is correct. But once the hanlder is installed and running - it will fire when ever a replication event occurs. That is - the Handler listens for all replication events. 

6 replies

salvadorm142499
Level 3
October 16, 2015

I could filter my application logic if event.getPath().contains(desiredPath) but I would like to fire a listener when replicating under a defined path.

Let's imagine I want to fire this event only for /path1/path2/path3 that means a 1% of the replications. (The other 99% of events fired are pointless)

Sham_HC
Level 10
October 16, 2015

It deponds what you will be implementing in the listener. Should not be an issue if you followed best coding & is simple operation.

Sham_HC
Level 10
October 16, 2015

If you need to restrict the amount of repository events you want to process directly on API level, JCR observation is the right thing for you. not possible with sling eventing. Read more details at https://cqdump.wordpress.com/2012/11/13/cq-coding-patterns-sling-vs-jcr-part-2/

smacdonald2008
smacdonald2008Accepted solution
Level 10
October 16, 2015

THere is more information here:

http://blogs.adobe.com/experiencedelivers/experience-management/event_handling_incq/

But there does not look like there is a way to only fire on a path. Code:

@Component
@Service
@Property(name="event.topics",value= {ReplicationAction.EVENT_TOPIC, Example.EVENT_TOPIC})
public class ExampleEventHandler implements EventHandler {
 Logger log = LoggerFactory.getLogger(this.getClass());
 public void handleEvent(Event event) {
  if (event.getTopic().equals(Example.EVENT_TOPIC)){
   log.info("Example {}, with description {} has been created...",event.getProperty(Example.PN_NAME),event.getProperty(Example.PN_DESC));
  } else if (event.getTopic().equals(ReplicationAction.EVENT_TOPIC)){
   ReplicationAction action = ReplicationAction.fromEvent(event);
   log.info("User {} has tried to replicate {}",action.getUserId(),action.getPath());
  }
 }
}

As stated - you can get the path and invoke app logic if a path is correct. But once the hanlder is installed and running - it will fire when ever a replication event occurs. That is - the Handler listens for all replication events. 

salvadorm142499
Level 3
October 16, 2015

Thanks,

This is the answer to my problem without solution ;)

Level 2
August 13, 2024

hey @salvadorm142499 i am also facing the same issue can please provide the solution for this

smacdonald2008
Level 10
October 16, 2015

Here is a community article that talks about how to build a Replication Event Handler. 

http://helpx.adobe.com/experience-manager/using/replication_events.html

This lets you figure out the JCR path. If you have intense application logic - only invoke it if the JCR path is correct.