Multiple Listeners for single Event | Community
Skip to main content
Level 3
October 3, 2022
Solved

Multiple Listeners for single Event

  • October 3, 2022
  • 3 replies
  • 2319 views

Hi all,

 

I am new to AEM Listener.I have created listners for a single event but right now I have a scenario where I want to call two different listeners on one event trigger.

 

For example: I have a event(Page Activation)which triggers two listener (ex:OSGi API based listener) , (ex:Sling API based listener). 

I want to know which listener will be called first.

 

In short, I want to know if there is any preference given to any listener. Or is there any way to call specified listener first and then the others.

 

Thank you!!

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 joerghoh

In OSGI there is no guaranteed order in which the listeners are called; also I think that the listeners could be called in parallel. If you need a stable order, you should catch it just once and call your handlers yourself.

3 replies

Level 4
October 3, 2022

Hi @janhavi_singh ,

 

Can you explain the scenario why you need to use two listeners for the same event ?

 

If you are able to trigger the two listeners then, add some logs in the handleEvent() and onChange() method and can monitor the logs to see which is getting called first.

 

Thanks,

Sweta

 

Level 3
October 5, 2022

I want one listener to send a mail to the author once the page is published(event) is triggered and the other to listener for the page publish event.

joerghoh
Adobe Employee
joerghohAdobe EmployeeAccepted solution
Adobe Employee
October 3, 2022

In OSGI there is no guaranteed order in which the listeners are called; also I think that the listeners could be called in parallel. If you need a stable order, you should catch it just once and call your handlers yourself.

arunpatidar
Community Advisor
Community Advisor
October 3, 2022

If you want to call only osgi API listener then use only replication event.

https://github.com/arunpatidar02/aem63app-repo/blob/master/java/ReplicationEvent2.java 

 

No, there is no way you can specify which one to call first both will be triggered asynchronously. Although if you want to delay an event you can do it by yourself using thread and make wait one of them.

 

But creating multiple trigger on same event acting on same/dependent property not a good design. 

Probably both can be merged into one handler.

Arun Patidar