def loop(self, timeout=5):
""" main loop for the consumer client """
consumer_tag = "callback_%s" % self.name
chan = self.connection.channel()
def callback(msg):
""" callback for message received """
if options.verbose:
print "Client %s saw this message: '%s'" % (self.name, msg.body)
if self.check_end(msg): # we have been asked to quit
self._quit = True
chan.basic_consume(queue=self.name, no_ack=True, callback=callback,
consumer_tag=consumer_tag)
signal.signal(signal.SIGALRM, alarm_handler)
signal.alarm(timeout)
while True:
chan.wait()
if self._quit:
break
# cancel alarm for receive wait
signal.alarm(0)
chan.basic_cancel(consumer_tag)
chan.close()
return self._quit
评论列表
文章目录