Expand my Community achievements bar.

SOLVED

Sling Jobs

Avatar

Level 4

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/*)"
})
1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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.

View solution in original post

3 Replies

Avatar

Administrator

@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

Avatar

Community Advisor

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.

Avatar

Correct answer by
Community Advisor

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.