Skip to content

Instantly share code, notes, and snippets.

@hmarr
Created September 6, 2013 14:16
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hmarr/6464419 to your computer and use it in GitHub Desktop.
Save hmarr/6464419 to your computer and use it in GitHub Desktop.

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 rabbitmq.com 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