Polyconseil / aioamqp

AMQP implementation using asyncio
Other
280 stars 88 forks source link

[WIP] First implementation of a new consumer API #118

Open lumasepa opened 7 years ago

lumasepa commented 7 years ago

First implementation of a new consumer API, as I propose in #87

I would like a review from polyconseil and some feedback, I think that this API can be a good one.

dzen commented 7 years ago

Hello @lumasepa

Thank you for this huge contribution. Using an asyncio.Queue was the first design of aioamqp, and I removed it.

The first things is that when on high load, RabbitMQ will fill your entire ram of messages, how can we correctly avoid it ?

lumasepa commented 7 years ago

I know the problem, you are rigth, what about using a limited size Queue (the size can be a parameter of the basic_consume method) and in case of filling it we can use the AMQP basic.reject with requeue set to true. The standar describes basic.reject as the next and I think that it can solve this problem.

What you think about it, @dzen ?

lumasepa commented 7 years ago

Other option is the limited size Queue and raising an exception in case of fulling it. That allows the user to choose what to do with this situation, for example stop consuming or stop the flow of the channel.

RemiCardona commented 7 years ago

Hello @lumasepa, I'm sorry for the late reply. @dzen and I talked about your PR and we have a few comments:

    for channel, body, envelope, properties in (yield from consumer.fetch_message()):
        print(body)

Better yet, maybe it's possible to yield from the consumer object directly. That would be even more user friendly:

    for channel, body, envelope, properties in (yield from consumer):
        print(body)
lumasepa commented 7 years ago

Hello, I'm going to answer your points in order

message = yield from consumer.fetch_message()
for channel, body, envelope, properties in message:
    print(body)

as you can see the asyncronous operation is done only once (not each time that the for iterates) so is not the same behaviour that the while, fetch_message and get_message API have. For this pattern was created the __aiter__ and __anext__ protocol in conjuntion with the async for in python 3.5.

allan-simon commented 6 years ago

hello what is the status of this PR ?

hellysmile commented 6 years ago

Hello there! I am working on https://github.com/aio-libs/aioamqp_consumer as separate project, please take a look on it!

Maybe we can cooperate on more feature rich project together!