Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Multiple Listeners for single Event

Avatar

Level 3

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!!

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

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.

View solution in original post

4 Replies

Avatar

Level 3

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

 

Avatar

Level 3

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.

Avatar

Correct answer by
Employee Advisor

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.

Avatar

Community Advisor

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.