-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
40 lines (24 loc) · 798 Bytes
/
run.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
import pika
import json
# Run all docker commands from README.md file
URL = 'amqp://guest:guest@localhost'
params = pika.URLParameters(URL)
params.socket_timeout = 5
connection = pika.BlockingConnection(params)
channel = connection.channel()
channel.queue_declare(queue='sagar')
# Publish message
personal_information = {
"name": "Sagar",
"profession": "Software-developer",
"hobbies": ["Unknown"]
}
channel.basic_publish(exchange='amq.topic', routing_key='sagar', body=json.dumps(personal_information))
# Consume message
def callback(ch, method, properties, body):
print(" [x] Received " + str(body))
# set up subscription on the queue
channel.basic_consume('sagar', callback, auto_ack=True)
# start consuming (blocks)
channel.start_consuming()
connection.close()