Skip to content

Commit 099ceed

Browse files
committed
Make eewids-parser ready for multiple workers
1 parent 710def9 commit 099ceed

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

eewids-parser/eewids-parser.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,29 +59,27 @@ def main(rab_host, rab_port):
5959
send_channel = connection.channel()
6060

6161
# declare exchange
62-
# TODO maybe you need to check if it already exists!
6362
send_channel.exchange_declare(exchange='capture',
6463
exchange_type='topic',
6564
durable=True,)
6665

67-
# create queue for receiving raw capture data
68-
# TODO you probably do not want a random queue, but one which is used by multiple workers!!!
69-
result = recv_channel.queue_declare(queue='eewids-parser', exclusive=False)
70-
queue_name = result.method.queue
71-
#recv_queue = recv_channel.queue.declare(exclusive=True)
66+
# declare queue for receiving raw capture data
67+
recv_channel.queue_declare(queue='eewids-parser',
68+
durable=True,
69+
exclusive=False)
70+
7271
# TODO change routing key on capture tool and here, make it meaningful and global/as argument
73-
# FIXME do not abort if it does not exist
74-
recv_channel.queue_bind(exchange='capture-raw', queue=queue_name, routing_key='*')
72+
recv_channel.queue_bind(exchange='capture-raw', queue='eewids-parser', routing_key='*')
7573

7674
def callback(ch, method, properties, body):
7775

7876
parsed_data = p.packet_parse(body)
7977
distribute(parsed_data, send_channel)
78+
ch.basic_ack(delivery_tag=method.delivery_tag)
8079

81-
# TODO look up right arguments to make sure that this is dividable through multiple workers!
80+
recv_channel.basic_qos(prefetch_count=1)
8281
recv_channel.basic_consume(on_message_callback=callback,
83-
queue=queue_name,
84-
auto_ack=True)
82+
queue='eewids-parser')
8583

8684
print(' [*] Starting parsing. To exit press CTRL+C')
8785
recv_channel.start_consuming()

0 commit comments

Comments
 (0)