Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards.
SOLVED

Event handling in AEMaaCS / Run Java code after publish

Avatar

Level 5

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...
    }
}

 

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor
3 Replies

Avatar

Correct answer by
Community Advisor

Hi @dylanmccurry 

Have you already checked this thread https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/replication-event-listener... ? Maybe you find something useful there.

Avatar

Community Advisor

Yes, I can confirm that solution in mentioned thread works fine for my client.

Kostiantyn Diachenko


Check out AEM VLT Intellij plugin


Avatar

Level 5

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) {

    }
}