Producing messages
With the runtime
Publish a message with its URN and payload. The BabelQueue runtime builds the
canonical envelope and pushes it to your broker:
from babelqueue import BabelQueue
app = BabelQueue("redis://localhost:6379/0", queue="orders")
app.publish("urn:babel:orders:created", {
"order_id": 1042,
"amount": 99.90,
})
With the codec only
If you manage the broker connection yourself, build the envelope with
EnvelopeCodec and publish the JSON to your own client:
from babelqueue import EnvelopeCodec
env = EnvelopeCodec.make("urn:babel:orders:created", {"order_id": 1042, "amount": 99.90})
body = EnvelopeCodec.encode(env) # -> UTF-8 JSON string
# redis.rpush("queues:orders", body)
# / channel.basic_publish(body=body, ...)
The payload above is wrapped in the canonical schema_version: 1 envelope —
identical to what every other SDK emits, with meta.lang set to "python":
{
"job": "urn:babel:orders:created",
"trace_id": "7b3f9c2a-e41d-4f88-9b2a-1c0d5e6f7a8b",
"data": { "order_id": 1042, "amount": 99.90 },
"meta": { "id": "f1e2d3c4-b5a6-4789-90ab-cdef01234567", "queue": "orders", "lang": "python", "schema_version": 1, "created_at": 1749132727000 },
"attempts": 0
}
Next: Consuming messages.