An Endless Sea Of Rabbit Puns: RabbitMQ Fundamentals

Basics

  • What's a message queue?
  • What does a message queue get you?
  • Why RabbitMQ specifically?

Message Queues

  • Some sort of broker that you send message payloads to over the wire (usually via TCP)
  • Figures out who should get the message, and gets it to them.

Why A Message Queue

  • Performance
  • Simplifies complex communication topologies
  • Implicitly handles retries and buffering
  • Promotes decoupled software design

Why RabbitMQ?

  • Pros:
    • It's pretty much the fastest
    • It's pretty much the most reliable
    • It scales really well
    • It's massively flexible
  • Cons:
    • Client libs not as clean and simple as e.g. Redis.
    • Corollary: AMPQ protocol is...complex.

Charting The Seas - Topology Building Blocks

Basic Topology Blocks

  • Queues (obviously)
  • Exchanges
  • Bindings
  • Routing Keys (optional)

Fundamental Concept

  • Publishers just publish
  • Subscribers just listen
  • Neither one is aware of, dependent on, or directly interacts with the other

Queues

  • The buckets wot messages go in
  • Always the Final Destination
  • Can be persisted to disk
  • Can be replicated across instances for HA
  • Messages sit here until subscribers pull them off

Exchanges

  • The only things publishers can publish to
  • 3 basic types (will come back to this)

Bindings

  • The thing that links, or binds exchanges to queues
  • Once an exchange is bound to a queue, the message has a complete pathway to travel along.

Routing Keys

  • Specialized message metadata
  • Used by the binding + exchange to make routing decisions on a message-by-message basis

Charting The Seas - Basic Topology Patterns

Exchange Types

  • Remember I said there were 3 basic exchange types
    • Direct Exchanges
    • Fanout Exchanges
    • Topic Exchanges

Direct Exchange

Each message is routed to one queue based on binding, where routing key matches exactly.

 

Think "unicast"

Fanout Exchange

Routing Key is ignored. A copy of the message is sent to each queue the exchange is bound to.

 

Think "multicast"

Topic Exchange

Routing key must be dot-delimited. Binding defines regex-style matching.

 

Imagine keys like "sad.orange.rabbit" and "lazy.purple.lizard", and a queue that wants all "color" keys, and another queue that only wants "reptile" keys.

Rabbot

  • NodeJS RabbitMQ utility library
  • Provides an out-of-the-box RPC-style messaging pattern
  • Handles client->broker connections/retries
  • Sits on top of amqplib package, which is the core AMPQ 0.9.1 javascript implementation.

Links

 

The RabbitMQ docs/tutorials are pretty great, full of Javascript/Python/Java/C#/Go/Ruby/Swift/PHP examples, make use of them.

RabbitMQ Overview

By Ben Leggett

RabbitMQ Overview

  • 794