What is the best way to tap into and run a bit of Java code whenever a publish occurs in AEMaaCS?
I have an API servlet that is fetching and returning some structured content from AEM. This servlet uses Caffeine to cache some computations in memory for an hour so that results don't get recomputed on every request. When a publish occurs in AEM, I want to run a function to clear this cache.
I tried the following but it doesn't appear to get triggered (at least locally). What's the best way to trigger a bit of Java code to run after a publish occurs?
@component(service = EventHandler.class, property = {
EventConstants.EVENT_TOPIC + "=com/adobe/granite/content/replication/end"
})
public class CustomPublishEvent implements EventHandler {
@reference
public ResourceResolverFactory rrFactory;
@Override
public void handleEvent(Event event) {
// do something here...
}
}
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Have you already checked this thread https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/replication-event-listener... ? Maybe you find something useful there.
Have you already checked this thread https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/replication-event-listener... ? Maybe you find something useful there.
Yes, I can confirm that solution in mentioned thread works fine for my client.
Views
Replies
Total Likes
I gained some insights from that thread and others. The issue was the event topic was incorrect.
To trigger the event on the publisher, you need to subscribe to a different topic:
import org.osgi.service.event.Event;
import org.osgi.service.event.EventConstants;
import com.day.cq.replication.ReplicationAction;
import com.day.cq.replication.ReplicationActionType;
import com.day.cq.replication.ReplicationEvent;
@Component(service = EventHandler.class,
immediate = true,
property = {
EventConstants.EVENT_TOPIC + "=" + ReplicationEvent.EVENT_TOPIC
}
)
public class MyPublishEvent implements EventHandler {
@Override
public void handleEvent(Event event) {
}
}
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies