Hi all,
What is the difference between these two?
I see that Sling Event Listener is more performant.
This apart, why we have these two?
Only one of these two would have sufficed?
When to use what?
Appreciate all your responses.
Thanks,
RK.
Solved! Go to Solution.
Views
Replies
Total Likes
It is the API Preference - AEM Rule of thumb or hierarchy.
The general rule is to prefer the APIs/abstractions the following order:
Both AEM Sling Event Listener and JCR Observation are used to listen for and react to events in the AEM system, but they operate at different levels.
JCR Observation
JCR Observation is a lower-level API that is part of the Java Content Repository (JCR) specification. It allows you to listen for changes to nodes and properties in the repository. JCR Observation is very powerful and flexible, but it can also be more complex to use and can have performance implications if not used carefully.
Example : You might use JCR Observation if you need to listen for changes to a specific type of node or property in the repository, regardless of how or why the change was made. For example, you might use JCR Observation to track changes to user profiles or to implement a custom versioning system.
Sling Event Listener:
Sling Event Listener is a higher-level API that is part of the Apache Sling framework, which AEM is built on. Sling Event Listener is designed to listen for events that are specific to the Sling framework, such as resource events (added, changed, removed) and OSGi events (services registered, modified, unregistered). Sling Event Listener is generally easier to use and more performant than JCR Observation, especially for high-level events.
example : you might use Sling Event Listener to clear a cache when a page is published or to send a notification when a new user is registered.
It is better to Prefer Sling Event Listener over JCR Observation wherever it is possible.
It is the API Preference - AEM Rule of thumb or hierarchy.
The general rule is to prefer the APIs/abstractions the following order:
Both AEM Sling Event Listener and JCR Observation are used to listen for and react to events in the AEM system, but they operate at different levels.
JCR Observation
JCR Observation is a lower-level API that is part of the Java Content Repository (JCR) specification. It allows you to listen for changes to nodes and properties in the repository. JCR Observation is very powerful and flexible, but it can also be more complex to use and can have performance implications if not used carefully.
Example : You might use JCR Observation if you need to listen for changes to a specific type of node or property in the repository, regardless of how or why the change was made. For example, you might use JCR Observation to track changes to user profiles or to implement a custom versioning system.
Sling Event Listener:
Sling Event Listener is a higher-level API that is part of the Apache Sling framework, which AEM is built on. Sling Event Listener is designed to listen for events that are specific to the Sling framework, such as resource events (added, changed, removed) and OSGi events (services registered, modified, unregistered). Sling Event Listener is generally easier to use and more performant than JCR Observation, especially for high-level events.
example : you might use Sling Event Listener to clear a cache when a page is published or to send a notification when a new user is registered.
It is better to Prefer Sling Event Listener over JCR Observation wherever it is possible.
I don't think that you can compare those.
That means, if you can only compare JCR Observations with the ResourceChangeListener approach.
JCR observation:
Sling ResourceChangeListener
Views
Likes
Replies
Views
Likes
Replies