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:
./rabbit.sh start
You can stop it with ./rabbit.sh stop and view the logs of the server with ./rabbit.sh logs.
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.
func PublishJSON[T any](ch *amqp.Channel, exchange, key string, val T) error
go run ./cmd/server
no exchange 'peril_direct' in vhost '/'
While there are no hard errors, the message will be "unroutable" because there are no queues bound to the exchange yet, but we'll fix that later.