aboutsummaryrefslogtreecommitdiffstats
path: root/rmq/consumer.py
diff options
context:
space:
mode:
authorGravatar Christopher Baklid <[email protected]>2018-05-26 12:54:49 +0200
committerGravatar Christopher Baklid <[email protected]>2018-05-26 12:54:49 +0200
commitea2141dc6fd7284e6f9fa04ee638460286e3b09c (patch)
tree218d332be80bd2f4e177b0d9e4725dd27dec2034 /rmq/consumer.py
parentlint (diff)
simplify threads and use local thread variables to manage user websocket connections
Diffstat (limited to 'rmq/consumer.py')
-rw-r--r--rmq/consumer.py42
1 files changed, 0 insertions, 42 deletions
diff --git a/rmq/consumer.py b/rmq/consumer.py
deleted file mode 100644
index 2c41e26..0000000
--- a/rmq/consumer.py
+++ /dev/null
@@ -1,42 +0,0 @@
-import time
-import traceback
-import pika
-from pika.exceptions import ConnectionClosed
-
-
-def consume(username='guest',
- password='guest',
- host='localhost',
- port=5672,
- queue='',
- callback=None):
-
- while True:
- credentials = pika.PlainCredentials(username, password)
- con_params = pika.ConnectionParameters(host, port, '/', credentials)
-
- try:
- connection = pika.BlockingConnection(con_params)
-
- try:
- channel = connection.channel()
- channel.queue_declare(queue=queue, durable=False)
- channel.basic_qos(prefetch_count=1)
- channel.basic_consume(callback, queue=queue)
-
- print(f"""Connected to host: {host} port: {port} queue: {queue}""", flush=True)
-
- channel.start_consuming()
-
- except Exception:
- exc = traceback.format_exc()
- print(exc, flush=True)
-
- finally:
- connection.close()
-
- except ConnectionClosed:
- print(f"Connection lost, reconnecting to {host}", flush=True)
- pass
-
- time.sleep(2)