Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Replication listener for a defined path

salvadorm142499
Level 3
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
smacdonald2008
Correct answer by
Level 10
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
salvadorm142499
Level 3
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)

Sham_HC
Level 10
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.

Sham_HC
Level 10
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/

smacdonald2008
Correct answer by
Level 10
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

salvadorm142499
Level 3
Level 3

Thanks,

This is the answer to my problem without solution 😉

smacdonald2008
Level 10
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.