-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqueue-test.py
More file actions
executable file
·63 lines (50 loc) · 1.57 KB
/
queue-test.py
File metadata and controls
executable file
·63 lines (50 loc) · 1.57 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/python
import sys
from qpid.messaging import *
import json
import pprint
pp = pprint.PrettyPrinter(indent=4)
class novaQueue:
def __init__(self):
self.broker = "192.168.95.20:5672"
self.connection = Connection(self.broker)
# setup the options to browse the exchange
self.addr_opts = {
"create": "always",
"mode": "browse",
"node": {
"type": "topic",
"x-declare": {
"durable": True,
"auto-delete": False,
},
},
}
# attache to the 'nova' exchange with the options
self.address = "%s ; %s" % ('nova', json.dumps(self.addr_opts))
def get(self):
try:
# open the connection and create a session
self.connection.open()
session = self.connection.session()
# attach a receiver to the session
receiver = session.receiver(self.address)
# loop waiting for new messages
while True:
message = receiver.fetch(timeout=120)
pp.pprint(message.content)
print "\n"
#try:
# # pull out the messages that we care about
# if message.content['event_type'] == 'compute.instance.create.end':
# instance = message.content['payload']
# pp.pprint(instance)
#except:
# pass
session.acknowledge()
except MessagingError,m:
print m
finally:
self.connection.close()
q = novaQueue()
q.get()