airtai / faststream

FastStream is a powerful and easy-to-use Python framework for building asynchronous services interacting with event streams such as Apache Kafka, RabbitMQ, NATS and Redis.
https://faststream.airt.ai/latest/
Apache License 2.0
2.51k stars 128 forks source link

Add lifespan context manager like FastAPI #531

Closed davorrunje closed 10 months ago

Lancetnik commented 1 year ago

Why we should add it? And which lifecycle points it should be triggered (before/after broker start, before/after broker close)?

Lancetnik commented 1 year ago

Also, is it the same with #521?

davorrunje commented 1 year ago

Also, is it the same with #521?

yes, it is the duplicate

davorrunje commented 1 year ago

Why we should add it? And which lifecycle points it should be triggered (before/after broker start, before/after broker close)?

Lifespan context manager is more convenient when you have to do some cleanup on broker close. That was changed about a year ago in FastAPI and it makes sense to me. See:

https://fastapi.tiangolo.com/advanced/events/

Lancetnik commented 1 year ago

We have more places to user would like to interact, so in which one lifespan should start and end? Before broker connection up and after broker connection down, I suppose?

davorrunje commented 1 year ago

We have more places to user would like to interact, so in which one lifespan should start and end? Before broker connection up and after broker connection down, I suppose?

yes

Lancetnik commented 1 year ago

Little note: we should pass extra CLI options to the lifespan too (like in the on_startup hook)

davorrunje commented 10 months ago

Just released: https://github.com/airtai/faststream/releases/tag/0.3.0rc0