In RabbitMQ, an exchange is where publishers send messages, typically with a routing key.
The exchange takes the message, uses the routing key as a filter, and sends the message to any queues that are listening for that routing key.
Publishers don't know about queues at all. They just send messages to exchanges, sometimes with a routing key.
Terminology
Exchange: A routing agent that sends messages to queues.
Binding: A link between an exchange and a queue that uses a routing key to decide which messages go to the queue.
Queue: A buffer in the RabbitMQ server that holds messages until they are consumed.
Channel: A virtual connection inside a connection that allows you to create queues, exchanges, and publish messages.
Connection: A TCP connection to the RabbitMQ server.
Rabbit Script
Start RabbitMQ in the background with the provided script, if it isn't already running:
npm run rabbit:start
Assignment
Let's update our server to publish pause/resume messages to an exchange on a specific routing key. The server can then communicate with all the various players of the game to let them know when the game is paused or resumed. We'll handle the queues and consumption of the messages later.
The ConfirmChannel type from the amqplib package is a wrapper around the standard Channel type, but with additional functionality for confirming message delivery, via a callback.