-
Notifications
You must be signed in to change notification settings - Fork 1
/
rabbitmq-transit.py
executable file
·89 lines (60 loc) · 2.22 KB
/
rabbitmq-transit.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!//usr/bin/python
""""
quick rabbitmq end to end test perf data plugin
"""
import socket
import argparse
import sys
import csv
from pprint import pprint
import re
import pika
import logging
import time
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-p', '--publish', help="publish a string",
dest="publish")
parser.add_argument('-c', '--consume', help="empty a queue ",
dest="consume")
parser.add_argument('-i', '--iterations', help="how many items to publish",
dest="iterations", type=int)
args = parser.parse_args()
logging.basicConfig()
logging.getLogger('pika').setLevel(logging.ERROR)
""" do action on argument """
if args.publish and args.consume:
print "Error: use publish and consume independently"
return 2
if args.publish:
iterations = 100 if not args.iterations else args.iterations
params = {}
fields = { 'eventbus_test' : True, 'x-match': 'all' }
con = pika.BlockingConnection(pika.ConnectionParameters('prod-rabbit-02'))
channel = con.channel()
channel.queue_declare(queue='test',durable=True,arguments=params)
for num in range(0, iterations):
#channel.basic_publish(exchange='eventbus.headers',routing_key='test',body=args.publish)
channel.basic_publish(exchange='eventbus.headers',routing_key='',body=args.publish,
properties=pika.BasicProperties(headers = fields))
con.close()
return 0
if args.consume:
iterations = 100 if not args.iterations else args.iterations
con = pika.BlockingConnection(pika.ConnectionParameters('prod-rabbit-02'))
channel = con.channel()
i = 0
print "Consuming on %s, Ctrl+C to exit" % args.consume
time.sleep(1)
try:
for num in range(0, iterations):
b = channel.basic_get(args.consume, no_ack=True)
#print "iteration %s: message body: %s" % (i, b)
#channel.basic_ack(m.delivery_tag)
i = i + 1
except KeyboardInterrupt:
print "\nExiting"
channel.close()
con.close()
if __name__ == "__main__":
sys.exit(main())