RabbitMQ and SQS/SNS

RabbitMQ overview

  1. Producers create messages
  2. Messages are sent to the exchanges
  3. Exchanges use bindings to deliver messages to the queues
  4. Messages appear in queues
  5. Consumers are connected to the queues
  6. Consumers get messages from the queue in round-robin
  7. Process and ack/nack

RabbitMQ Overview

Direct exchange

When a queue is created it's automatically bound to the exchange using queue name as a routing key.

channel.basicPublish(
  message,
  "", // exchange name("" = default, direct)
  "queue-name"
);

RabbitMQ Direct Exchange

Fanout exchange

When a message is sent to a fanout exchange it will be delivered to all queues attached to this exchange:

RabbitMQ Fanout Exchange

Topic exchange

Topic exchange allows to achieve scenarios, where messages can arrive to the same queue coming from different sources:

channel.basicPublish(
  message,
  "logs-exchange",
  "error.msg-inbox"
);

channel.queueBind(
  "msg-inbox-errors",
  "logs-exchange",
  "error.msg-inbox"
);

channel.queueBind(
  "msg-inbox-logs",
  "logs-exchange",
  "*.msg-inbox"
);

RabbitMQ Topic Exchange

SQS/SNS overview

In rabbit terms SQS is a direct exchange:

  1. Producers push a message to SQS queue
  2. Consumers pull and read a message from the SQS queue

In rabbit terms SNS is a fanout exchange. SNS Topic implements a Fanout exchange/pattern:

  1. Producers push a message to the SNS
  2. SNS sends a copy to every SQS queue connected
  3. Consumers pull and read a message from the SQS queues

SQS SNS