Skip to content

Instantly share code, notes, and snippets.

What would you like to do?

RabbitMQ Basics

As demonstrated by the tutorials on the website, RabbitMQ can be used for everything from queuing background work to building RPC systems. To use RabbitMQ effectively, it is important to understand the core concepts: queues, exchanges, bindings, and messages. The documentation on is excellent, so I won't go into much depth, but it's worth briefly mentioning the core ideas.

Basic Terminology

Exchanges are where messages are sent. Every time a message is pushed in to RabbitMQ, it goes through an exchange.

Messages are pulled off queues. Messages leave queues in the order they arrive. Each message will be pulled off a queue at most once (except for in exceptional circumstances - more on that later).

Exchanges are responsible for dispatching messages to queues. For a queue to receive messages, it must be connected to an exchange using a binding. If multiple queues are bound to an exchange, the messages being fed in to the exchange will be sent to all bound queues.

Routing & Topic Exchanges

With standard "direct" exchanges, every incoming message will be sent to all bound queues. This works for simple cases, such as basic pub-sub systems. However, RabbitMQ also allows more complex message routing.

When binding a queue to an exchange, a "binding key" may be specified. Queues bound with a binding key only receive messages that have been tagged with a matching "routing key". Binding keys may contain wildcard characters (* and #), which enable partial matches. For example, a queue with the binding key payment.# would receive messages with the routing keys payment.success and payment.failure, but ignore a message with the routing key mandate.failure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.