txamqp-user team mailing list archive
-
txamqp-user team
-
Mailing list archive
-
Message #00068
Re: Multiple consumer queue in same channel
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.
Follow ups
References