Generate unique consumer tags when connecting to the queues

(imported from commit cd9c78db46ae1a36b46bebf5cb0d226e15f71ba4)
This commit is contained in:
Leo Franchi
2013-02-15 11:01:28 -05:00
parent 1f24133292
commit c2074813ca

View File

@@ -2,6 +2,7 @@ from django.conf import settings
import pika
import logging
import simplejson
import random
# This simple queuing library doesn't expose much of the power of
# rabbitmq/pika's queuing system; its purpose is to just provide an
@@ -24,6 +25,9 @@ class SimpleQueueClient(object):
credentials = pika.PlainCredentials(
'humbug', settings.RABBITMQ_PASSWORD))
def _generate_ctag(self, queue_name):
return "%s_%s" % (queue_name, str(random.getrandbits(16)))
def ready(self):
return self.channel is not None
@@ -51,7 +55,8 @@ class SimpleQueueClient(object):
callback(ch, method, properties, body)
ch.basic_ack(delivery_tag=method.delivery_tag)
self.channel.basic_consume(wrapped_callback, queue=queue_name)
self.channel.basic_consume(wrapped_callback, queue=queue_name,
consumer_tag=self._generate_ctag(queue_name))
def register_json_consumer(self, queue_name, callback):
def wrapped_callback(ch, method, properties, body):