Skip to content
Snippets Groups Projects
Commit 4a402dff authored by Bo-Chun Chen's avatar Bo-Chun Chen
Browse files

Remove disconnect call from publish and consume

user should explicitly call disconnect
Modify README regarding explicity disconnect call
parent c99e1303
No related branches found
No related tags found
1 merge request!18Redesign RabbitMQ
......@@ -44,4 +44,7 @@ rc_rmq.start_consume({
'cb': callback_function
})
# don't forget to close connection
rc_rmq.disconnect()
```
......@@ -74,6 +74,7 @@ class RCRMQ(object):
def disconnect(self):
self._channel.close()
self._connection.close()
self._connection = None
def delete_queue(self):
self._channel.queue_delete(self.QUEUE)
......@@ -89,9 +90,6 @@ class RCRMQ(object):
routing_key=self.ROUTING_KEY,
body=json.dumps(obj['msg']))
if not self._consuming:
self.disconnect()
def start_consume(self, obj):
if 'queue' in obj:
self.QUEUE = obj['queue']
......@@ -112,7 +110,5 @@ class RCRMQ(object):
except KeyboardInterrupt:
self._channel.stop_consuming()
self.disconnect()
def stop_consume(self):
self._channel.basic_cancel(self._consumer_tag)
......@@ -13,6 +13,7 @@ def add_account(username, full='', reason=''):
"reason": reason
}
})
rc_rmq.disconnect()
def worker(ch, method, properties, body):
msg = json.loads(body)
......@@ -39,5 +40,6 @@ def consume(username, callback=worker, debug=False):
'routing_key': 'confirm.' + username,
'cb': callback
})
rc_rmq.disconnect()
return { 'success' : True }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment