Howdy fellow devs 👋! Capturing events in a very common use case in any software system and AEM is no exception. There are many use cases where we need to perform some operation when something specific happens in AEM.
There are various ways by which event handling can be done in AEM -
1. Event Listener - JCR level events with the observation (discussed in this post)
2. Event Handler - Sling level events (discussed in this post)
3. Workflow and Launchers (discussed in previous three posts)
4. Schedulers with cron expressions (will be discussed in the next post)
We can create an Event Handler by following below steps -
1. Write a service class that implements the EventHandler interface.
2. Register the service with property EventConstants.EVENT_TOPIC.
3. Implement the handleEvent(Event event) method to trigger the job.
Let us create a custom event handler that will be triggered when a page is activated and executes a workflow on the path for which the replication is triggered. The main thing to see here is how we capture the event. Execution of the workflow has the same logic we discussed in the last post discussing trigger workflow programmatically.