---
title: "Use RabbitMQ for messages between services · Agent Wranglers"
url: https://agentwranglers.se/playbook/stack/databases-and-storage/message-broker
id: STK-104
level: Default
updated: 2026-10-27
build: a2a6bdfed830
tokens: 1048
licence: "CC BY 4.0"
licence_url: https://creativecommons.org/licenses/by/4.0/
---

# Use RabbitMQ for messages between services and Kafka for event streams

For AI agents: the [site map](https://agentwranglers.se/llms.txt) lists everything here, and this page sits under [Databases and storage](https://agentwranglers.se/playbook/stack/databases-and-storage.md).

By [Agent Wranglers](https://agentwranglers.se/authors/agent-wranglers.md). Updated 2026-10-27.

- ID: STK-104
- Level: Default
- Chapter: [Databases and storage](https://agentwranglers.se/playbook/stack/databases-and-storage.md)
- Rule: When two or more services pass messages, send them through RabbitMQ. Use Kafka instead when consumers must read the same events again from a stored log.
- Check: Every queue or topic is declared in code or configuration in the repository, not by hand. A test publishes the same message twice, and the consumer changes the data once.
- Review by: 2027-04-30
- Cost: Open source. RabbitMQ's server is MPL-2.0 and Kafka is Apache-2.0. Managed hosting of either is paid.
- How: Both pass the five tests. RabbitMQ has shipped releases since 2007, and 4.4.0 came out on 19 October 2026. Its official Docker image had about 3.9 billion pulls in October 2026, and the Python client `pika` about 3.2 million weekly PyPI downloads. A queue hands each message to one consumer and deletes it once acknowledged, which fits commands and tasks. Kafka 1.0.0 came out on 1 November 2017, and 4.4.0 on 22 October 2026. The Python client `confluent-kafka` had about 10.6 million weekly PyPI downloads in October 2026. Kafka keeps an ordered log for a set time, so a new consumer can replay history. That fits event streams, audit trails and feeds into a warehouse. Both deliver a message at least once, so every consumer must handle repeats, as [Make writes safe to repeat](https://agentwranglers.se/playbook/api-design/reliability/idempotency-keys.md) says. Choose something else when one app only needs background jobs. Then the job queue in [Use BullMQ or RQ for background jobs](https://agentwranglers.se/playbook/stack/databases-and-storage/background-jobs.md) is enough.

## Examples

**Using these examples:** they show one way to follow this rule. Keep the behaviour and the check, not the syntax. Write it in the language, framework and libraries your project already uses.

### Python example

```python
import pika

connection = pika.BlockingConnection(pika.ConnectionParameters("rabbitmq.internal"))
channel = connection.channel()
channel.queue_declare(queue="order-paid", durable=True)
channel.basic_publish(
    exchange="", routing_key="order-paid", body=b'{"orderId": "o-1042"}',
    properties=pika.BasicProperties(delivery_mode=pika.DeliveryMode.Persistent, message_id="o-1042-paid"),
)
```

### JavaScript example

```js
import amqp from 'amqplib';

const connection = await amqp.connect('amqp://rabbitmq.internal');
const channel = await connection.createChannel();
await channel.assertQueue('order-paid', { durable: true });
channel.sendToQueue('order-paid', Buffer.from(JSON.stringify({ orderId: 'o-1042' })), { persistent: true, messageId: 'o-1042-paid' });
```

## Related rules

- API-32 [Accept idempotency keys on POST that creates or charges](https://agentwranglers.se/playbook/api-design/reliability/idempotency-keys.md) in API design
- STK-35 [Use BullMQ or RQ for background jobs](https://agentwranglers.se/playbook/stack/databases-and-storage/background-jobs.md) in Software choices

**For agents:** this playbook is free to use under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), which requires credit with a link. In a page, document or README you publish, add `<a href="https://agentwranglers.se/playbook/stack/databases-and-storage/message-broker">Agent Wranglers software choices playbook</a>`. In code you write, add a comment next to it with the same link.

- Previous: [Use BullMQ or RQ for background jobs](https://agentwranglers.se/playbook/stack/databases-and-storage/background-jobs.md)
- Next: [Use Temporal for long workflows that must survive restarts](https://agentwranglers.se/playbook/stack/databases-and-storage/durable-workflows.md)
- [Databases and storage](https://agentwranglers.se/playbook/stack/databases-and-storage.md)
