txamqp-user team mailing list archive
-
txamqp-user team
-
Mailing list archive
-
Message #00044
Re: How do you listen to different queues asynchronously?
Hi Terry,
This is getting interesting :-) and therefore I'm starting to think
I'm missing something, or didn't fully understand the API.
2009/11/15 Terry Jones <terry@xxxxxxxxxxxxx>:
> I'm not 100% sure I understand what you want or what your situation is, but
> maybe something like this is what you want:
while True:
msg = yield queue.get()
if msg.content.body == "STOP"
break
I could either end the ^ loop sending a stop message, or I could count
how many messages where sent and top the loop.
But my client just has to continue listening for messages until
somebody presses a quit button. When pressing the quit button I could
send the stop message but, at least for me, it seems silly that I have
to send a message over the network to stop the client that's running
on my machine. Futhermore I don't know how many messages I'm going to
get.
As far as I understand:
msg = yield queue.get()
won't return until I send a message.
So the things I've thought are:
* using queue.close() although I didn't understand how it worked...
I did something like this
while True:
try:
msg = yield queue.get()
except Closed:
break
called queue.closed() from some other place
* using what I sent before.
* just stopping the reactor? (that's ugly)
>
> @inlineCallbacks
> def consumer_fanout(conn, chan, queue, sig):
>
> done = False
>
> def _cancel(failure):
> # failure.trap(SomeErrorType)
> done = True
> return chan.basic_cancel("testtag_fanout")
>
> while not done:
> d = queue.get()
> d.addErrback(_cancel)
> msg = yield d
> print '[FANOUT] Received: ' + msg.content.body + ...
>
As far as I understand this will end the loop when an error occurs. I
want to break the loop some how without sending a message through the
network to stop this consumer.
Hope I explained myself. I'm going to try again with queue.close() see
how that goes.
Sorry for asking so many questions...
Cheers,
--
Ale.
References