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
3.15k stars 161 forks source link

Feature: subscriber iteration support #1881

Open Lancetnik opened 3 weeks ago

Lancetnik commented 3 weeks ago

We should support alternative way to consume messages instead of decorator callbacks

I think, iteration should be impelemnet something like this

subscriber = broker.subscriber("test")
...
async for msg in subscriber:
    ...

This functional is pretty close to subscriber.get_one() already exists - https://github.com/airtai/faststream/blob/main/faststream/broker/subscriber/proto.py#L90

Also, implementation should be close to this method as well - https://github.com/airtai/faststream/blob/main/faststream/nats/subscriber/usecase.py#L369 , but use native underlying libraries iterations everywhere it is possible