FastStream
KubeMQ broker adapter for the FastStream async messaging framework, with native support for all five KubeMQ messaging patterns.
kubemq-faststream is a KubeMQ
broker adapter for the FastStream async
messaging framework. It registers KubeMQBroker as a first-class FastStream broker, so
all five KubeMQ patterns — Events, Events Store, Queues, Commands, and
Queries — become ordinary @broker.subscriber(...) endpoints, fully wired into
FastStream's lifecycle, dependency injection, middleware, and testing infrastructure.
New to the idea? See what is an integration for how SDK-level integrations differ from server-side connectors.
Why FastStream + KubeMQ
- All five patterns as FastStream endpoints — one keyword on the subscriber
(
events=,events_store=,queues=,commands=,queries=) selects the pattern; no per-pattern client wiring. - Idiomatic decorator API — register handlers with
@broker.subscriber(...)and auto-publish results with@broker.publisher(...), exactly like every other FastStream broker. - Full FastStream pipeline — parser, decoder, broker and subscriber middleware, and FastDepends dependency injection run for every message.
- In-memory testing —
TestKubeMQBrokerroutes published messages to matching subscribers without a live broker, exercising the real parse/decode/middleware path. - Runs inside your web app — drop the broker into a FastAPI, Starlette, Django, or Flask process and consume KubeMQ messages on the same event loop.
Installation
uv add kubemq-faststreampip install kubemq-faststreamRequirements: Python 3.11+ and a running KubeMQ broker.
| Requirement | Supported versions |
|---|---|
| Language | Python 3.11, 3.12, 3.13 |
| FastStream | >= 0.6.7, < 0.7.0 |
| KubeMQ SDK | >= 4.1.5, < 5 |
| Package | kubemq-faststream 0.1.0 |
Start a broker locally with Docker:
docker run -d \ --name kubemq \ -p 50000:50000 \ -p 9090:9090 \ -e KUBEMQ_TOKEN=YOUR_LICENSE_KEY \ europe-docker.pkg.dev/kubemq/images/kubemq:nextkubemq-faststream is a native gRPC SDK client: it talks to KubeMQ over the gRPC port
50000, the same transport the native SDKs use. It is always on — there is no
server-side connector to enable and no HTTP flag to set. Port 9090 is the shared HTTP
server (REST and the HTTP connectors) and is not used by FastStream.
Architecture
When it connects, KubeMQBroker creates three KubeMQ SDK async clients — one per
transport family — each on its own gRPC channel and all sharing a single set of
connection settings (URL, client ID, auth token, TLS, message-size limits, keepalive).
Your subscriber keyword routes each publish, request, and handler registration to the
matching client.
KubeMQBroker fans your handlers across three SDK clients, all reaching the KubeMQ broker over gRPC on :50000.
A minimal app wires the broker into FastStream, registers a subscriber, and publishes
after startup:
import asyncio
from faststream import FastStream
from kubemq_faststream import KubeMQBroker
broker = KubeMQBroker("kubemq://localhost:50000")
app = FastStream(broker)
@broker.subscriber(queues="orders")
async def handle_order(order: dict) -> None:
print(f"Processing order: {order}")
@app.after_startup
async def publish() -> None:
await broker.publish({"id": "ORD-001", "item": "Widget"}, queues="orders")
if __name__ == "__main__":
asyncio.run(app.run())Messaging patterns
Each KubeMQ pattern maps to a subscriber keyword. The pages below document the FastStream
API for each — the decorators, options, and broker.publish/broker.request calls — and
link to the underlying KubeMQ concept.
Events
Fire-and-forget pub/sub with the events= subscriber and broker.publish, plus optional group load balancing.
Events Store
Persistent pub/sub with replay from first, a sequence, or a point in time via StartPosition.
Queues
Point-to-point messaging with AckPolicy-controlled settlement, DLQ, TTL, delay, and batching.
Commands & Queries
Request-reply RPC with broker.request: void-response commands and cacheable data-response queries.
Composition
KubeMQRouter prefix composition and @broker.publisher auto-publish decorators.
Capabilities
KubeMQBrokerover native gRPC — connect withkubemq://host:50000(orkubemq+tls://for TLS) straight to the KubeMQ gRPC port.KubeMQRoutercomposition — group handlers into routers whoseprefixpropagates to every channel.@broker.publisherauto-publish — stack on a subscriber to publish its return value to another channel.AckPolicysettlement — choose how queue messages are acked, nacked, or rejected.StartPositionreplay — replay Events Store streams from first, a sequence, or a point in time.- Server-side query caching — pass
cache_keyandcache_ttlon a query request. - Health check —
await broker.ping()verifies broker connectivity.
Next steps
Getting Started
Install, start a broker, and run your first subscriber and publisher end to end.
Concepts
The broker lifecycle, the three-client model, dependency injection, and how patterns map to clients.
Guides
Configuration and security, testing with TestKubeMQBroker, and observability middleware.
Reference
Constructor options, environment variables, URL formats, enums, and the public API surface.
New to KubeMQ? Start with the KubeMQ Getting Started guide for the core concepts behind these patterns.
Was this page helpful?