liveBook · Manning

Message

As explained in Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform

A message is a discrete piece of data transmitted between software components to communicate an event, command, or information.

A message is a discrete communication between microservices, carrying an event notification or command. A video-streaming service sends a “Viewed” message so a history service can record viewing activity in its own database. section 5.4 section 5.6.1

Choose the messaging style according to how the sender and receiver must interact:

  • Use direct messaging when one service targets another by name, needs an immediate success or failure response, or must sequence dependent actions. HTTP provides this interaction, but couples both services tightly. section 5.6.1 section 5.9
  • Use indirect messaging when a service broadcasts an event to zero or more interested recipients or when sender and receiver should evolve independently. RabbitMQ provides this interaction. section 5.9

Recording a viewed video

Start the example with `cd chapter-5/example-2` and `docker compose up --build`, play the video at `http://localhost:4001/video`, and inspect the Docker Compose output. Each refresh should produce a “Viewed” message and a new record in the history database’s `videos` collection. Shut it down afterward with `docker compose down`. section 5.7.5

Table 5.2 When to use each type of communication (view table figure)

Situation

What to use

I need to direct a message to a particular microservice by name.

Direct messaging: HTTP

I need confirmation that the message handling was successful or that it failed.

Direct messaging: HTTP

I need to sequence subsequent messages after completion of the first.

Direct messaging: HTTP

I want one microservice to orchestrate the activity of other microservices.

Direct messaging: HTTP

I need to broadcast a message across the application to notify zero or more microservices of an event in the system (and I don’t care if the messages are handled or not).

Indirect messaging: RabbitMQ

I want to decouple the sender and the receiver (so they can more easily change and evolve independently).

Indirect messaging: RabbitMQ

I want the performance of sender and receiver to be independent (the sender can emit as many messages as it likes, and the receiver will process these in its own time).

Indirect messaging: RabbitMQ

I want to be sure that if message handling fails, it will automatically be retried again later until it succeeds (so no messages are lost due to intermittent failures).

Indirect messaging: RabbitMQ

I need to load balance handling of a message so it’s handled by one out of a pool of workers.

Either HTTP or RabbitMQ

I need to distribute the handling of a message to multiple workers who can act in parallel.

Indirect messaging: RabbitMQ

Compare direct HTTP and indirect RabbitMQ messaging by recipient selection, response requirements, sequencing, orchestration, broadcasting, and service coupling. section 5.9

How Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform covers it

How deep it goes
Defines messages through working direct and indirect communication examples, but defers message-format and protocol internals.
Examples
Uses a “Viewed” event, video-streaming and history services, Docker Compose output, and MongoDB collection records.
What you can do after
Apply it via HTTP or RabbitMQ and verify message handling through service logs and database records.
How it connects
Connects messages to microservices, direct messaging, indirect messaging, HTTP, RabbitMQ, events, commands, and databases.

Also explained in

Compare how 7 books explain message →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform. The section links point to the parts of the book it draws on.