Event Listeners – What Every Developer Should Know

An event consumer in a component that actively listens for some messages or events and process them any way we want to handle it. An event can be — when a T-shirt order is placed on amazon and amazon uses that event to send email back to user to let share some details about the order.
Event listener in general has main three components.
1. Event Dispatcher
Upon receiving an event from a producer, the event dispatcher dispatches it to all relevant handlers. When an event occurs event dispatcher checks for all the event-handlers registered with it and then the event is passed to the event-handlers which are responsible for taking care of that event type.
Example:

- Order Create Event & Order Cancelled Event: These are the initial triggers in the system. When an order is created or cancelled, these events are generated.
- Event Dispatcher: This is the central mechanism that processes the incoming events. It acts as a router, directing the events to the appropriate handlers.
- Notify Users: This step indicates that when either an order is created or cancelled, a notification is sent out to users. This could be an email, SMS, or any other form of user notification.
- Notify Delivery: Similarly, the delivery system is also notified when these events occur. This could involve updating delivery schedules, informing delivery personnel, or adjusting logistics planning.
2. Event Handler
Event handlers are responsible for informing event dispatcher (normally at the time of application start) the type of event it can handle. Generally, each event handler typically handles a specific type of event. Each event handler is a event processor which then actually do something about that event.

3. Event Processor
Event processors receive events from event handlers. Once an event is received, they are responsible for performing business logic or carrying out specific tasks in response to events. This may involve interacting with databases, invoking external services, updating system state, or triggering further actions within the system.

In conclusion, an high level event listener architecture looks like this.

Conclusion
Event consumer architecture as simple as it can get. It has three main component Dispatcher, Handler and Processor. They are core to event driven architecture.