txamqp-user team mailing list archive
-
txamqp-user team
-
Mailing list archive
-
Message #00070
Re: Multiple consumer queue in same channel
Just as an addition, I tried for some more time. Using my Google
skills the closest I could find an issue was:
http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/2008-October/001758.html
I think I found the corresponding code in testlib.py - using
protocol._InstanceFactory but that code seems to indicate that we will
need a connection for each channel/queue. Or am I missing something?
On Tue, Sep 28, 2010 at 12:37 AM, Ritesh Nadhani <riteshn@xxxxxxxxx> wrote:
> Hmm, unfortunately it didnt work. Maybe its lack of my understanding
> of inlineCallbacks (this is the first I am using it). Anyway, I have
> code pasted at:
>
> http://www.bpaste.net/show/9823/ - modified from txamqp samples.
>
> As can be seen form the code, I am not sure how the control flow is
> given back to other deferred when we are doing while True: or am I
> missing something?
>
> Thus which queue, I consume first seems to be only getting the message
> and I am missing the other one.
>
> Where am I going wrong?
>
> I think I should reread how inlineCallbacks work again anyway....
>
> On Mon, Sep 27, 2010 at 7:52 AM, Esteve Fernandez
> <esteve.fernandez@xxxxxxxxx> wrote:
>> Hi Ritesh,
>>
>> you can have two functions that returns a Deferred, each consuming
>> from a different queue and build a DeferredList with those two
>> Deferreds. For example:
>>
>>
>> @defer.inlineCallbacks
>> def consume(consumerTag):
>> queue = yield conn.queue(consumerTag)
>>
>> while True:
>> msg = yield queue.get()
>> doSomething(msg)
>> if msg is STOP_TOKEN: # STOP_TOKEN is something the producer
>> may send to stop the consumer
>> break
>>
>> @defer.inlineCallbacks
>> def myFunc():
>> d1 = consume("consumerTag1")
>> d2 = consume("consumerTag2")
>>
>> dl = DeferredList([d1, d2], fireOnOneCallback=True)
>> yield dl
>> print "Finished"
>>
>> the key is in fireOnOneCallback=True, this way when any of the two
>> functions finish, the Deferred will be fired and the code flow will
>> continue.
>>
>> Cheers.
>>
>
>
>
> --
> Ritesh
> http://www.riteshn.com
>
--
Ritesh
http://www.riteshn.com
Follow ups
References