liveBook · Manning

Handler

As explained in Learn Docker in a Month of Lunches, Second Edition

A message handler is a software component that receives messages or events and performs processing in response.

A message handler subscribes to a queue and processes messages or events. An application typically uses a handler for each message type, such as a handler that saves new to-do items to a database. section 21.3

The queue buffers work when incoming activity spikes. Multiple handler containers can share messages, limiting concurrent processing; messages wait in the queue if handlers cannot keep up. Because processing happens asynchronously, a saved item may not appear immediately: the application reaches eventual consistency after its messages are handled. section 21.3

Handlers also let applications add event-driven features without changing the publisher:

  • Add a separate audit handler to log each new item while the existing handler saves it to SQL. section 21.4
  • Other possible responses include saving items to Elasticsearch for querying or adding reminders to Google Calendar. section 21.4
# run the audit message handler, keeping the same scale 
# for the save handler:
docker compose -f docker-compose.yml `
 -f docker-compose-audit.yml up -d --scale save-handler=3
# check that the audit handler is listening:
docker logs todo-list-audit-handler-1
# browse to http:/./localhost:8080 and add some new items
# check the audit trail:
docker logs todo-list-audit-handler-1

Use the Compose override to start an audit handler, keep the save handler scaled, and inspect the audit log as items are added. section 21.4

How Learn Docker in a Month of Lunches, Second Edition covers it

How deep it goes
Explains subscriptions, buffering, scaling, and asynchronous effects, while using existing handler images rather than detailing handler internals.
Examples
Uses to-do item saving, audit logging, Elasticsearch indexing, calendar reminders, and a text-mutating handler.
What you can do after
Operate and configure handlers with Docker Compose, including scaling a handler group and adding an audit subscriber.
How it connects
Connects message queues with event-driven architecture, eventual consistency, and SQL databases.

Also explained in

Compare how 22 books explain handler →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Docker in a Month of Lunches, Second Edition. The section links point to the parts of the book it draws on.