Sling Jobs | Community
Skip to main content
Keerthi0555
Level 5
May 15, 2023
Solved

Sling Jobs

  • May 15, 2023
  • 3 replies
  • 1238 views

Hi Team,

 

I tried working on sling jobs for ReplicationAction,

When I entered EVENT_FILTER it's not working, without FILTER it's working but to log replication event under specific path I gave filter but it's not working,any suggestions on this issue? Thanks in advance.

EventConstants.EVENT_TOPIC +"="+ ReplicationAction.EVENT_TOPIC,
EventConstants.EVENT_FILTER + "=(path=/content/mdt/Regions/*)"
})
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 sunil_kumar_

Hi @keerthi0555 ,
This will not work because the way you define filter is not correct for Replication Event. This EventHandler framework has different way of defining property values for different Event. Instead of using path please use paths So just to answer your question add filter as below. 

property = {
EventConstants.EVENT_TOPIC + "=" + ReplicationAction.EVENT_TOPIC,
EventConstants.EVENT_FILTER +"=("+ReplicationEvent.PATHS+"=/content/mdt/Regions/*)",
}) 

or like this

property = {
EventConstants.EVENT_TOPIC + "=" + ReplicationAction.EVENT_TOPIC,
EventConstants.EVENT_FILTER +"=(paths=/content/mdt/Regions/*)",
})

 Sharing a working ReplicationEventhandler for your reference. Adjust code per your need.

 

import com.day.cq.replication.ReplicationAction; import com.day.cq.replication.ReplicationActionType; import com.day.cq.replication.ReplicationEvent; import org.osgi.service.component.annotations.Component; import org.osgi.service.event.Event; import org.osgi.service.event.EventConstants; import org.osgi.service.event.EventHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Component(service = EventHandler.class, immediate = true, property = { EventConstants.EVENT_TOPIC + "=" + ReplicationAction.EVENT_TOPIC, EventConstants.EVENT_FILTER +"=("+ ReplicationEvent.PATHS+"=/content/mdt/Regions/*)", }) public class ReplicationEventHandler implements EventHandler { private static final Logger LOG = LoggerFactory.getLogger(ReplicationEventHandler.class); public void handleEvent(final Event event) { try { LOG.info("\n Event Type : {} ", event.getTopic()); if (ReplicationAction.fromEvent(event).getType().equals(ReplicationActionType.ACTIVATE)) { LOG.info("\n Page Published : {}", ReplicationAction.fromEvent(event).getPath()); } if (ReplicationAction.fromEvent(event).getType().equals(ReplicationActionType.DEACTIVATE)) { LOG.info("\n Page Deactivated : {}", ReplicationAction.fromEvent(event).getPath()); } }catch (Exception e){ LOG.error("\n Error while Activating/Deactivating - {} " , e.getMessage()); } } }

Check ReplicationEvent documentation for reference.

3 replies

kautuk_sahni
Community Manager
Community Manager
June 7, 2023

@rawvarun @mayursatav @arunpatidar @lukasz-m I kindly request you to review this AEM question and share your expertise in addressing them. Alternatively, if you could provide some guidance to the author regarding the issue, it would be highly appreciated. Thank you in advance for your support.

 

Kautuk Sahni
MayurSatav
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
June 7, 2023

hi @keerthi0555 ,

 

Ensure that the path you specified in the filter is correct and matches the desired location where you want to log replication events. Verify that the path /content/mdt/Regions/* exists and is valid.

sunil_kumar_
sunil_kumar_Accepted solution
Level 5
June 7, 2023

Hi @keerthi0555 ,
This will not work because the way you define filter is not correct for Replication Event. This EventHandler framework has different way of defining property values for different Event. Instead of using path please use paths So just to answer your question add filter as below. 

property = {
EventConstants.EVENT_TOPIC + "=" + ReplicationAction.EVENT_TOPIC,
EventConstants.EVENT_FILTER +"=("+ReplicationEvent.PATHS+"=/content/mdt/Regions/*)",
}) 

or like this

property = {
EventConstants.EVENT_TOPIC + "=" + ReplicationAction.EVENT_TOPIC,
EventConstants.EVENT_FILTER +"=(paths=/content/mdt/Regions/*)",
})

 Sharing a working ReplicationEventhandler for your reference. Adjust code per your need.

 

import com.day.cq.replication.ReplicationAction; import com.day.cq.replication.ReplicationActionType; import com.day.cq.replication.ReplicationEvent; import org.osgi.service.component.annotations.Component; import org.osgi.service.event.Event; import org.osgi.service.event.EventConstants; import org.osgi.service.event.EventHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Component(service = EventHandler.class, immediate = true, property = { EventConstants.EVENT_TOPIC + "=" + ReplicationAction.EVENT_TOPIC, EventConstants.EVENT_FILTER +"=("+ ReplicationEvent.PATHS+"=/content/mdt/Regions/*)", }) public class ReplicationEventHandler implements EventHandler { private static final Logger LOG = LoggerFactory.getLogger(ReplicationEventHandler.class); public void handleEvent(final Event event) { try { LOG.info("\n Event Type : {} ", event.getTopic()); if (ReplicationAction.fromEvent(event).getType().equals(ReplicationActionType.ACTIVATE)) { LOG.info("\n Page Published : {}", ReplicationAction.fromEvent(event).getPath()); } if (ReplicationAction.fromEvent(event).getType().equals(ReplicationActionType.DEACTIVATE)) { LOG.info("\n Page Deactivated : {}", ReplicationAction.fromEvent(event).getPath()); } }catch (Exception e){ LOG.error("\n Error while Activating/Deactivating - {} " , e.getMessage()); } } }

Check ReplicationEvent documentation for reference.