Replication Event Listener stopped working on AEMaaCS Publisher | Community
Skip to main content
konstantyn_diachenko
Community Advisor
Community Advisor
November 15, 2024
Solved

Replication Event Listener stopped working on AEMaaCS Publisher

  • November 15, 2024
  • 3 replies
  • 4000 views

Hi there,

 

I have a Replication Event Listener that is running on AEMaaCS publisher. 1 week ago it worked fine, it received replication events as expected. Today I noticed that it stopped receiving replication events from the author when I publish any page. However, it still receives replication events that are triggered by org.apache.sling.sitemap.impl.SitemapScheduler on the publisher. 

 

Below you can find my service declaration:

@8220494( service = EventHandler.class, property = { "event.topics=com/day/cq/replication" }, configurationPolicy = ConfigurationPolicy.REQUIRE, immediate = true )

 

Does anyone face this issue too? Does it make sense to reimplement EventHandler on com.day.cq.replication.Preprocessor?

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 konstantyn_diachenko

Hi @daniel-strmecki ,

 

Nothing special. Just simple steps to start OSGi component on publisher. 

1. Created OSGi service:

@Component(
service = EventHandler.class,
property = {
"event.topics=com/day/cq/replication"
},
configurationPolicy = ConfigurationPolicy.REQUIRE,
immediate = true
)
@Designate(ocd = MyReplicationEventListener.Configuration.class)
public class MyReplicationEventListener implements EventHandler {

2. Created OSGi configuration and put in under config.publish to start this component only on publisher.

 

Of course, I has this condition in this listener to handle event only on leader POD:

 

if (!discoveryService.getTopology().getLocalInstance().isLeader()) { log.info("Skipping event {} because it's not a leader.", event); return; }

 

 

According to the logs, it caught replication events on AEMaaCS publisher.

Thank you for the code example. I was looking for it. I read that recently they have fixed Flush Rules for the AEMaaCS. I am going to try this approach.

 


I tried to re-implement according to ACS Commons Dispatcher Flush Rules implementation for cloud.

They build their logic on author environment by listening of org/apache/sling/distribution/agent/package/distributed.

 

However, I realized that can't properly handle such events on author instance. I have a logic to handle replicated paths with /etc/map and resource.resolver.mapping on publisher and I don't want to apply these mappings on author instance as well.  

 

I modified my event listener and now it's listening com/adobe/granite/replication instead of com/day/cq/replication. This setup works for me as well.

 

Besides of that, I am sure that initial implementation worked as expected, but event handler was black-listed by reaching 5s timeout. 

3 replies

daniel-strmecki
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
November 15, 2024

Hi @konstantyn_diachenko,

AFAIK the example you shared will catch the replication event on Author, not on Publisher. I can confirm this approach is working fine on my project. Also, you should not re-implement this with com.day.cq.replication.Preprocessor as that API is not supported on AEMaaCS.

 

Good luck,

Daniel

konstantyn_diachenko
Community Advisor
Community Advisor
November 15, 2024

Hi @daniel-strmecki

I tested this listener on publisher on local env and on AEMaaCS. It worked fine.

 

I am running this listener on publisher in purpose.

 

I know an alternative variant for listening of replication changes - listen org/apache/sling/api/resource/Resource/ADDED and org/apache/sling/api/resource/Resource/CHANGED. Is it a good alternative?

Kostiantyn Diachenko, Community Advisor, Certified Senior AEM Developer, creator of free AEM VLT Tool, maintainer of AEM Tools plugin.
daniel-strmecki
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
November 15, 2024

Hi @konstantyn_diachenko,

how are you running it on Publisher? Can you explain?

Catching replication events on Publisher in AEMaaCS is more tricky compared to On-Prem, as there are multiple publisher PODs and you usually want to catch the event and process it only once. Therefore, you can use the DiscoveryService to process it only on the leader POD.

Replication is done via Sling Distribution on AEMaaCS. I think this example from ACS Commons may be good to take a look: https://github.com/Adobe-Consulting-Services/acs-aem-commons/blob/master/bundle-cloud/src/main/java/com/adobe/acs/commons/replication/dispatcher/impl/CloudDispatcherFlushRulesExecutor.java

 

Hope it helps,

Daniel

joerghoh
Adobe Employee
Adobe Employee
November 17, 2024

The most obvious reason for such an event handler to stop it got blocked because it took too much time. The OSGI implementation blocks event handlers which consume 5s of execution time per invocation. That means if you need to more complex operations or even external calls, you should delegate that work to a dedicated threadpool.

konstantyn_diachenko
Community Advisor
Community Advisor
November 18, 2024

Hi @joerghoh , thank you for this assumption. After additional investigation I think that it's most obvious reason.

Actually, I know about 5s limitation for an event handler and always follow the best practice - to catch event and start Sling Job.

In this event handler I do the following:

  1. check that this event handler is running on leader POD
  2. check that event paths are allowed
  3. start Sling job

All of these steps have to be fast.

Kostiantyn Diachenko, Community Advisor, Certified Senior AEM Developer, creator of free AEM VLT Tool, maintainer of AEM Tools plugin.
AMANATH_ULLAH
Community Advisor
Community Advisor
November 18, 2024

@konstantyn_diachenko 

As @joerghoh mentioned, this issue occurs when your event handler takes more time and gets blacklisted

To resolve this issue, You can configure your Event Handler to ignore timeout using IgnoreTimeout property in org.apache.felix.eventadmin.impl.EventAdmin OSGI configuration or else  prefer using sling jobs

Amanath Ullah
konstantyn_diachenko
Community Advisor
Community Advisor
November 18, 2024

Hi @amanath_ullah , thank you for your suggestion. If I face it again, I will definitely white-list my event handler for the event admin.

Kostiantyn Diachenko, Community Advisor, Certified Senior AEM Developer, creator of free AEM VLT Tool, maintainer of AEM Tools plugin.