Quickstart
Install
Section titled “Install”uv add lexigram-queueOptional extras for production backends:
# Redisuv add "lexigram-queue[redis]"
# RabbitMQuv add "lexigram-queue[rabbitmq]"
# Kafkauv add "lexigram-queue[kafka]"
# SQSuv add "lexigram-queue[sqs]"Minimal Example
Section titled “Minimal Example”import asyncio
from lexigram import Applicationfrom lexigram.contracts.queue import BusMessage, QueueProtocolfrom lexigram.di.module import module, Modulefrom lexigram.queue import QueueModulefrom lexigram.queue.config import QueueConfig, NamedQueueConfig
# 1. Configure an in-memory queueconfig = QueueConfig(backends=[ NamedQueueConfig(name="default", driver="memory", primary=True),])
# 2. Wire the module@module(imports=[QueueModule.configure(config)])class AppModule(Module): pass
async def main() -> None: async with Application.boot(name="app", modules=[AppModule]) as app: queue = await app.container.resolve(QueueProtocol)
# Subscribe before publishing async def on_message(msg: BusMessage) -> None: print(f"Received: {msg.payload}")
await queue.subscribe("greetings", on_message)
# Publish msg = BusMessage(topic="greetings", payload="Hello, world!") await queue.publish("greetings", msg)
await asyncio.sleep(0.1) # let the handler run
asyncio.run(main())What You Configured
Section titled “What You Configured”- Driver:
"memory"— no external broker needed. - Primary flag:
primary=True— this backend gets the unnamedQueueProtocolbinding. - Named injection: Use
Annotated[QueueProtocol, Named("default")]to inject a specific backend.
Next Steps
Section titled “Next Steps”- Guide — core concepts
- How-Tos — common recipes
- Configuration — all options