liveBook · Manning

Message subject

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

A message subject is a string attached to a message to identify its type or routing category in a messaging system.

A message subject is a string that identifies the type of a message in a messaging system. In NATS, publishers choose the naming scheme, and subscribers listen for subjects they care about. section 21.2

Naming a to-do event

The to-do application publishes a new-item event with the subject events.todo.newitem. A subscriber listening to that exact subject receives the event, while publishing still succeeds when no subscriber is connected. section 21.2

Use message subjects to support asynchronous features:

  • Subscribe multiple handlers to the same subject so each can react independently, such as saving data and writing an audit trail. section 21.4
  • Keep subject names meaningful and consistent; events.todo.newitem communicates both the application area and event type. section 21.2
# run a subscriber listening for "events.todo.newitem" messages
docker run -d --name todo-sub `
 --network todo-list_app-net `
 diamol/nats-sub:2e events.todo.newitem
# check the subscriber logs:
docker logs todo-sub
# browse to http:/./localhost:8080 and add some new items
# check that the new item events are published:
docker logs todo-sub

Run a subscriber for events.todo.newitem, add items through the application, and inspect the logs to verify that matching messages arrive. section 21.2

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

How deep it goes
Defines subject naming and demonstrates matching subscribers, but does not detail subject-pattern features or delivery guarantees.
Examples
Uses events.todo.newitem, a NATS logging subscriber, and an audit handler as concrete examples.
What it assumes
Assumes basic familiarity with messages, publishers, subscribers, and containers; introduces subject naming through a to-do workflow.
What you can do after
Apply NATS subjects by publishing events and running subscribers that verify matching messages.
How it connects
Connects message queues with publishers, subscribers, message handlers, and asynchronous messaging.

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.