-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-client.py
executable file
·46 lines (33 loc) · 1.31 KB
/
run-client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
import asyncio
import logging
from amqpclient.aio import AsyncSubscriber, AsyncConnection
EXCHANGE = "test_sub_reconnect"
if __name__ == "__main__":
import sys
import argparse
parser = argparse.ArgumentParser(description='Test Tornado async ampq pub/sub')
parser.add_argument('--host', metavar='address', nargs='?', default='localhost',
help="server address"
)
parser.add_argument('--logging' , choices=['debug', 'info', 'warning', 'error'], default='info',
help="set log level"
)
parser.add_argument('--reconnect-delay', type=float, default=5, help="Reconnect delay")
args = parser.parse_args(sys.argv[1:])
logger = logging.getLogger()
logger.addHandler(logging.StreamHandler())
logger.setLevel(getattr(logging, args.logging.upper()))
ioloop = asyncio.get_event_loop()
def message_handler( request ):
logger.info("===> Received {} {}".format(request.key, request.body))
connection = AsyncConnection(
host=args.host,
reconnect_delay=args.reconnect_delay,
reconnect_latency=args.latency,
logger=logger,
)
sub = AsyncSubscriber(connection=connection)
asyncio.ensure_future(sub.connect(EXCHANGE, message_handler))
ioloop.run_forever()
print("Done.")