From ab4dd08f13ecf77b4b380833225e7ce5db4e8a79 Mon Sep 17 00:00:00 2001 From: "Bo-Chun Louis Chen(VM)" <louistw@uab.edu> Date: Mon, 23 Mar 2020 19:50:19 +0000 Subject: [PATCH] Separate queue binding from connect function Since publish doesn't have to do binding, separate binding make it cleaner and less trouble --- rc_rmq.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/rc_rmq.py b/rc_rmq.py index 788387c..37afa3f 100644 --- a/rc_rmq.py +++ b/rc_rmq.py @@ -65,11 +65,11 @@ class RCRMQ(object): exchange_type=self.EXCHANGE_TYPE, durable=True) - if self.QUEUE is not None: - self._channel.queue_declare(queue=self.QUEUE, durable=self.DURABLE) - self._channel.queue_bind(exchange=self.EXCHANGE, - queue=self.QUEUE, - routing_key=self.ROUTING_KEY) + def bind_queue(self): + self._channel.queue_declare(queue=self.QUEUE, durable=self.DURABLE) + self._channel.queue_bind(exchange=self.EXCHANGE, + queue=self.QUEUE, + routing_key=self.ROUTING_KEY) def disconnect(self): self._channel.close() @@ -103,6 +103,8 @@ class RCRMQ(object): if self._connection is None: self.connect() + self.bind_queue() + self._consumer_tag = self._channel.basic_consume(self.QUEUE,obj['cb']) self._consuming = True try: -- GitLab