RabbitMQ for beginners
Rabbit is a message-queueing software called a massage broker.
RabbitMQ example
Example: Users upload information to a website, and site will handle this information and generate a PDF and email it back to the user.
- The user sends a PDF creation request to the web application.
- The web application (the producer) sends a message to RabbitMQ, including data from the request, like name and email.
- An exchange accepts the messages from a producer application and routes them to correct message queues for PDF creation.
- The PDF processing worker (the consumer) receives the task and starts the processing of the PDF.
An exchange is responsible for the routing of the messages to the different queues.
Exchanges
There are different types of exchanges: Direct, Topic and Fanout.
- Direct: A direct exchange delivers messages to queues based on a massage routing key.
- Topic: The topic exchange does a wildcard match between the routing key and the routing pattern specified in the binding.
- Fanout: A fanout exchange routes messages to all of the queues that are bound to it.
Server concepts
- Producer: application that sends the messages.
- Consumer: application that receives the messages.
- Queue: buffer that store messages.
- Exchange: receives messages from producers and pushes them to queues depending on rules defined by the exchange type. To receive messages, a queue needs to be bound to at least one exchange.
- Binding: is a link between a queue and an exchange.
- Routing Key: is a key that the exchange looks at to decide how to route the message to queues. The routing key is like an address for the message.