← Back to team overview

txamqp-user team mailing list archive

Re: Multiple consumer queue in same channel

 

Hello

More update as I work with it.

I finally bit the bullet and separated the two queues into their own
channel. Thus I do two ClientCreator() call and everything seems to be
working.

Now that this works, I was wondering if using multiple channel for
multiple queue recommended? Or it does not really matter?

>From what I could understand from reading:
http://hopper.squarespace.com/blog/2008/10/6/multithreading-amqp-clients.html
- unique channel for each consumer queue is actually suggested.

On Tue, Sep 28, 2010 at 1:10 PM, Ritesh Nadhani <riteshn@xxxxxxxxx> wrote:
> 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
>



-- 
Ritesh
http://www.riteshn.com



References