Skip to content

docs: run a broker inside another framework's lifespan - #81

Merged
lesnik512 merged 1 commit into
mainfrom
docs/broker-in-other-lifespan
Oct 17, 2026
Merged

lesnik512 merged 1 commit into
mainfrom
docs/broker-in-other-lifespan

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Adds a README section for running a broker inside another framework's lifespan, such as FastAPI's. setup_di needs a FastStream app, so the broker goes in FastStream(broker) with manage_lifespan=False, and the lifespan calls start() and stop() inside async with container:. start() runs the on_startup hooks, where the middleware is installed.

The section also says that start() and stop() do not run a FastStream(lifespan=...), links the modern-di shared container recipe, and says FastStream's FastAPI routers need only modern-di-fastapi.

Checked against modern-di-faststream main with a NatsBroker under TestNatsBroker and FastAPI's TestClient: the subscriber and the endpoint resolve the same APP-scoped instance, and the finalizer runs once when the container closes.

Closes #79

@lesnik512
lesnik512 merged commit 2679a3f into main Oct 17, 2026
12 checks passed
@lesnik512
lesnik512 deleted the docs/broker-in-other-lifespan branch October 17, 2026 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

setup_di cannot be used with a broker run without a FastStream app

1 participant