From aa684bcebe62afe04062487c523b94b7e8c3c90a Mon Sep 17 00:00:00 2001 From: mdivecky Date: Mon, 28 Sep 2020 18:28:26 +0200 Subject: [PATCH] Cleanup & indentation fix --- worker/worker.py | 49 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/worker/worker.py b/worker/worker.py index 51afba8..8d1f591 100644 --- a/worker/worker.py +++ b/worker/worker.py @@ -11,39 +11,38 @@ channel = connection.channel() channel.queue_declare(queue='signal-receive') def demo_echo(text, sender, destination): - connection = pika.BlockingConnection(pika.ConnectionParameters(rabbitmq_host)) - channel = connection.channel() - channel.queue_declare(queue='signal-send') + connection = pika.BlockingConnection(pika.ConnectionParameters(rabbitmq_host)) + channel = connection.channel() + channel.queue_declare(queue='signal-send') - message = [ - text, - destination, - sender - ] + message = [ + text, + destination, + sender + ] - message_json = json.dumps(message) + message_json = json.dumps(message) - channel.basic_publish(exchange='', - routing_key='signal-send', - body=message_json) + channel.basic_publish(exchange='', + routing_key='signal-send', + body=message_json) - connection.close() + connection.close() def callback(ch, method, properties, body): - body = json.loads(body) - text = body[0] - timestamp = body[1] - sender = body[2] - reciever = body[3] - demo_echo(text, sender, reciever) - print(body) + body = json.loads(body) + text = body[0] + timestamp = body[1] + sender = body[2] + reciever = body[3] + demo_echo(text, sender, reciever) - # This could be used to distribute messages to multiple servers. Just acknowledge message only if you should. (eq. based on rec number) - channel.basic_ack(delivery_tag=method.delivery_tag) + # This could be used to distribute messages to multiple servers. Just acknowledge message only if you should. (eq. based on rec number) + channel.basic_ack(delivery_tag=method.delivery_tag) @@ -51,10 +50,10 @@ channel.basic_consume('signal-receive', callback, auto_ack=False) try: - print("starting consuming") - channel.start_consuming() + print("starting consuming") + channel.start_consuming() except KeyboardInterrupt: - channel.stop_consuming() + channel.stop_consuming() connection.close()