Selaa lähdekoodia

BroadcastConsumer: Needed unique queue name to be broadcast, so queue name generated using the current hostname.

Ask Solem 15 vuotta sitten
vanhempi
commit
1da4812289
2 muutettua tiedostoa jossa 8 lisäystä ja 1 poistoa
  1. 6 0
      celery/messaging.py
  2. 2 1
      celery/worker/listener.py

+ 6 - 0
celery/messaging.py

@@ -3,6 +3,7 @@
 Sending and Receiving Messages
 
 """
+import socket
 
 from carrot.connection import DjangoBrokerConnection, AMQPConnectionException
 from carrot.messaging import Publisher, Consumer, ConsumerSet
@@ -98,6 +99,11 @@ class BroadcastConsumer(Consumer):
     exchange_type = conf.BROADCAST_EXCHANGE_TYPE
     no_ack = True
 
+    def __init__(self, *args, **kwargs):
+        hostname = kwargs.pop("hostname", None) or socket.gethostname()
+        self.queue = "%s_%s" % (self.queue, hostname)
+        super(BroadcastConsumer, self).__init__(*args, **kwargs)
+
 
 def establish_connection(connect_timeout=conf.BROKER_CONNECTION_TIMEOUT):
     """Establish a connection to the message broker."""

+ 2 - 1
celery/worker/listener.py

@@ -178,7 +178,8 @@ class CarrotListener(object):
         self.connection = self._open_connection()
         self.logger.debug("CarrotListener: Connection Established.")
         self.task_consumer = get_consumer_set(connection=self.connection)
-        self.broadcast_consumer = BroadcastConsumer(self.connection)
+        self.broadcast_consumer = BroadcastConsumer(self.connection,
+                                                    hostname=self.hostname)
         self.task_consumer.register_callback(self.receive_message)
         self.event_dispatcher = EventDispatcher(self.connection,
                                                 enabled=self.send_events)