What Each Part Does

Order 93 passes through three parts: the producer, the broker, and the consumer. Each has one job.

The producer

The producer is the part of the commerce service that handles placeOrder. For order 93, it:

  1. Saves order 93 with the status PROCESSING.
  2. Sends the message to the broker, and waits until the message is in the queue.
  3. Responds to the storefront.

The producer waits for the broker in step 2 so that the storefront receives “processing” only after the order is in the queue. It does not wait for the order to be placed.

The broker

The broker:

  • Keeps each message in the queue until a consumer takes it.
  • Gives the next message to a consumer when the consumer asks for one.
  • Removes the message when the consumer says it is done with it.

The broker keeps and passes on a message without reading it.

The consumer

A program whose only job is to take messages and do the work is called a worker. Our consumer is the order worker. It:

  1. Takes the next message from the broker.
  2. Places the order: runs the transaction, takes the payment, and sets the order to PLACED. The order becomes FAILED if no mug is left or the payment is declined.
  3. Tells the broker it is done with the message.
  4. Takes the next message.