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:
- Saves order 93 with the status
PROCESSING. - Sends the message to the broker, and waits until the message is in the queue.
- 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:
- Takes the next message from the broker.
- Places the order: runs the transaction, takes the payment, and sets the order to
PLACED. The order becomesFAILEDif no mug is left or the payment is declined. - Tells the broker it is done with the message.
- Takes the next message.