Files
Vinta ChenandClaude fa22df7ed6 docs: add Messaging category intro
The Messaging category page had no intro, showing only the table with a generic meta description.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-09-27 10:24:36 +08:00

3.1 KiB

Instead of a Python messaging library per broker, an asyncio service can run on FastStream. Otherwise, use confluent-kafka, pika, or paho-mqtt.

How to choose:

  • An asyncio service on Kafka, RabbitMQ, MQTT, NATS, or Redis: FastStream
  • Kafka, including Confluent's Schema Registry: confluent-kafka
  • RabbitMQ, with the client its team recommends: pika
  • IoT devices and sensors that speak MQTT: paho-mqtt

confluent-kafka is Confluent's Kafka client, a binding on top of librdkafka, the C client. produce() only queues a message, so call poll() to get delivery reports. Its README says production apps should serialize with Schema Registry instead of producing raw bytes.

pika is a pure-Python implementation of AMQP 0-9-1, and RabbitMQ's tutorials use it as the Python client the RabbitMQ team recommends. Start with BlockingConnection, as those tutorials do: it's the adapter for a procedural style. Ack each message after processing it, so RabbitMQ redelivers it when a worker dies.

paho-mqtt is the Eclipse Foundation's MQTT client, and MQTT is a lightweight publish/subscribe protocol for IoT devices and low-bandwidth links. Create a client, connect it, and run one of its network loops. loop_forever() blocks until you disconnect, and loop_start() runs the loop in a background thread. Both reconnect for you. Subscribe in on_connect(), so a reconnect renews your subscriptions.

FastStream is an asynchronous framework for event-driven services: FastAPI's decorators, type-driven validation, and dependency injection, pointed at Kafka, RabbitMQ, NATS, Redis, or MQTT instead of HTTP. Write handlers with @broker.subscriber() and @broker.publisher(), run the app with faststream run, and test it in memory with no broker running. It wraps your broker's own client and leaves out retries, delayed delivery, and task orchestration by design: for background jobs, see Task Queues.

In asyncio code, pick a client that won't block the event loop. FastStream is asynchronous throughout, confluent-kafka has AsyncIO clients for apps like a FastAPI service, and pika has an asyncio connection adapter.