Expand my Community achievements bar.

SOLVED

Replication listener for a defined path

Avatar

Level 3

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.

1 Accepted Solution

Avatar

Correct answer by
Level 10

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. 

View solution in original post

6 Replies

Avatar

Level 3

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)

Avatar

Level 10

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

Avatar

Level 10

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/

Avatar

Correct answer by
Level 10

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. 

Avatar

Level 3

Thanks,

This is the answer to my problem without solution ;)

Avatar

Level 10

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.