RabbitMQ and SQS/SNS
RabbitMQ overview
- Producers create messages
- Messages are sent to the exchanges
- Exchanges use bindings to deliver messages to the queues
- Messages appear in queues
- Consumers are connected to the queues
- Consumers get messages from the queue in round-robin
- Process and ack/nack
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"
);
Fanout exchange
When a message is sent to a fanout exchange it will be delivered to all queues attached to this 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"
);
SQS/SNS overview
In rabbit terms SQS is a direct exchange:
- Producers push a message to SQS queue
- 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:
- Producers push a message to the SNS
- SNS sends a copy to every SQS queue connected
- Consumers pull and read a message from the SQS queues