Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrabbit.py
More file actions
Latest commit
39 lines (31 loc) · 1.11 KB
/
Copy pathrabbit.py
File metadata and controls
39 lines (31 loc) · 1.11 KB
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
importpika
classRabbit():
globalmessage
defsendMessage(self):
connection=pika.BlockingConnection(pika.ConnectionParameters(
host='localhost'))
channel=connection.channel()
channel.queue_declare(queue='hello')
channel.basic_publish(exchange='',
routing_key='hello',
body='Hello World!')
connection.close()
defreadMessage(self):
connection=pika.BlockingConnection(pika.ConnectionParameters(
host='localhost'))
channel=connection.channel()
channel.queue_declare(queue='hello')
defcallback(ch, method, properties, body):
self.message=body
channel.stop_consuming()
channel.basic_consume(callback,
queue='hello',
no_ack=True)
channel.start_consuming()
defrelayMessage(self):
self.readMessage()
returnself.message
if__name__=="__main__":
rabbit=Rabbit()
rabbit.sendMessage()
print(rabbit.readMessage())