From 5df95cd94368227152d2844842c8c7aa3e83f06d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl>
Date: Tue, 21 Jun 2016 15:14:21 +0200
Subject: [PATCH] ConnectionUp will tell if this is a first connect or a
 reconnect

---
 coolamqp/events.py         | 3 +++
 coolamqp/handler.py        | 4 +++-
 examples/send_to_myself.py | 2 +-
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/coolamqp/events.py b/coolamqp/events.py
index 20a246d..469a3ac 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 33049f8..0fd75ac 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 c8cd4a6..c43e0ec 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)
-- 
GitLab