diff --git a/coolamqp/events.py b/coolamqp/events.py index 20a246da40aefa54828bbee6e31afe8c75be6e38..469a3ac8463ec1e65e5dc61a06ef5408d593d864 100644 --- a/coolamqp/events.py +++ b/coolamqp/events.py @@ -14,6 +14,9 @@ class ConnectionDown(ClusterEvent): class ConnectionUp(ClusterEvent): """Connection to broker has been (re)established""" + def __init__(self, initial=False): + self.initial = initial #: public, is this first connection up in this cluster ever? + class MessageReceived(ClusterEvent): """A message has been received from the broker""" diff --git a/coolamqp/handler.py b/coolamqp/handler.py index 33049f8b8f00bd0eb57d7464b559077da2a8bbea..0fd75ac30646224f29b9a4593ee6f8167c571ddd 100644 --- a/coolamqp/handler.py +++ b/coolamqp/handler.py @@ -33,6 +33,7 @@ class ClusterHandlerThread(threading.Thread): self.queues_by_consumer_tags = {} # listened queues, by their consumer tags self.backend = None + self.first_connect = True def _reconnect(self): exponential_backoff_delay = 1 @@ -80,7 +81,8 @@ class ClusterHandlerThread(threading.Thread): exponential_backoff_delay = 60 else: self.cluster.connected = True - self.event_queue.put(ConnectionUp()) + self.event_queue.put(ConnectionUp(initial=self.first_connect)) + self.first_connect = False break # we connected :) diff --git a/examples/send_to_myself.py b/examples/send_to_myself.py index c8cd4a66b7435addab63e4843c53bfb3a98954ec..c43e0ec06ba9484e14f2a93e699a1390d0e0d04a 100644 --- a/examples/send_to_myself.py +++ b/examples/send_to_myself.py @@ -6,7 +6,7 @@ QUEUE_NAME = 'f' logging.basicConfig() -cluster = Cluster([ClusterNode('xx', 'xx', 'xx', 'xx', heartbeat=10)]).start() +cluster = Cluster([ClusterNode('192.168.224.31:5672', 'smok', 'smok', 'smok', heartbeat=10)]).start() a_queue = Queue(QUEUE_NAME, auto_delete=True) cluster.consume(a_queue)