forked from SweetIQ/tx-easy-pika
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
33 lines (26 loc) · 918 Bytes
/
test.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
from datetime import datetime
from txeasypika import QueueConnection
from twisted.internet import reactor
def callback(channel, tag, message):
print "Received a message:"
print message
channel.basic_ack(tag)
queues = QueueConnection()
# Create an exchange
queues.exchange_declare(exchange="test-exchange")
# Set up a listener on a queue
queues.bind("my-queue", "test-exchange", "test-routing-key", callback)
# Now publish some messages to that queue
# Note that this message will not be published until we have started the
# Twisted reactor and we have successfully connected to Rabbit.
for i in range(5):
queues.basic_publish("test-exchange", "test-routing-key", {
"value": i,
"message_data": "This is a message",
"nested_field": {
"an_array": ["this has an array"],
"a_date": datetime.now()
}
})
# Start up the reactor
reactor.run()