Skip to content

Commit 4a7931d

Browse files
committed
Merge remote branch 'origin/bug23556'
2 parents 1d82921 + 4eb4b9a commit 4a7931d

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

python/emit_log_topic.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env python
2+
import pika
3+
import sys
4+
5+
connection = pika.AsyncoreConnection(pika.ConnectionParameters(
6+
host='127.0.0.1',
7+
credentials=pika.PlainCredentials('guest', 'guest')))
8+
channel = connection.channel()
9+
10+
channel.exchange_declare(exchange='topic_logs',
11+
type='topic')
12+
13+
routing_key = sys.argv[1] if len(sys.argv) > 1 else 'anonymous.info'
14+
message = ' '.join(sys.argv[2:]) or 'Hello World!'
15+
channel.basic_publish(exchange='topic_logs',
16+
routing_key=routing_key,
17+
body=message)
18+
print " [x] Sent %r:%r" % (routing_key, message)
19+
connection.close()

python/receive_logs_topic.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python
2+
import pika
3+
import sys
4+
5+
connection = pika.AsyncoreConnection(pika.ConnectionParameters(
6+
host='127.0.0.1',
7+
credentials=pika.PlainCredentials('guest', 'guest')))
8+
channel = connection.channel()
9+
10+
channel.exchange_declare(exchange='topic_logs',
11+
type='topic')
12+
13+
result = channel.queue_declare(auto_delete=True)
14+
queue_name = result.queue
15+
16+
binding_keys = sys.argv[1:]
17+
if not binding_keys:
18+
print >> sys.stderr, "Usage: %s [binding_key]..." % (sys.argv[0],)
19+
sys.exit(1)
20+
21+
for binding_key in binding_keys:
22+
channel.queue_bind(exchange='topic_logs',
23+
queue=queue_name,
24+
routing_key=binding_key)
25+
26+
print ' [*] Waiting for logs. To exit press CTRL+C'
27+
28+
def callback(ch, method, header, body):
29+
print " [x] %r:%r" % (method.routing_key, body,)
30+
31+
channel.basic_consume(callback,
32+
queue=queue_name,
33+
no_ack=True)
34+
35+
pika.asyncore_loop()

0 commit comments

Comments
 (0)