Skip to content
Browse files

Handling local/remote nodes better now. Update list_queues example too.

  • Loading branch information...
1 parent dd1ce32 commit e3e25410bc16c080f5486c2f51fb221b377c83dd @clemesha-ooi clemesha-ooi committed Aug 19, 2010
Showing with 20 additions and 14 deletions.
  1. +20 −14 examples/list_queues.py
View
34 examples/list_queues.py
@@ -5,28 +5,30 @@
from twotp.node import Process, readCookie, buildNodeName
-def rabbitmqctl_client(nodename="rabbit@localhost"):
- cookie = readCookie() #"~/.erlang.cookie" must exist
- nodeName = buildNodeName(nodename)
- process = Process(nodeName, cookie)
- return RabbitMQControlService(process, nodeName)
+def rabbitmqctl_client(local_nodename, remote_nodename, erlang_cookie=None):
+ if erlang_cookie:
+ cookie = erlang_cookie
+ else:
+ cookie = readCookie()
+ local_nodename = buildNodeName(local_nodename)
+ process = Process(local_nodename, cookie)
+ return RabbitMQControlService(process, remote_nodename)
@inlineCallbacks
-def list_queues():
- client = rabbitmqctl_client()
+def list_queues(client):
allqueues = yield client.list_queues()
+ print "All Qs => ", allqueues
for q in allqueues["result"]:
print "\n ", q, "\n"
returnValue(allqueues["result"])
@inlineCallbacks
-def queued_messages(queue_name):
+def queued_messages(queue_name, client):
"""
Returns the number of existing messages in queue 'queue_name'.
Returns -1 if 'queue_name' does not exist.
"""
- client = rabbitmqctl_client()
allqueues = yield client.list_queues()
for q in allqueues["result"]:
if q[0] == queue_name:
@@ -35,8 +37,12 @@ def queued_messages(queue_name):
returnValue(-1) #'queue_name' was not found.
-
-#reactor.callWhenRunning(list_queues)
-reactor.callWhenRunning(queued_messages, "stocks")
-reactor.run()
-
+if __name__ == "__main__":
+ import sys
+ cookie = open(sys.argv[1]).read().strip()
+ local_nodename = "example@localhost"
+ remote_nodename = "rabbit@amoeba.ucsd.edu"
+ client = rabbitmqctl_client(local_nodename, remote_nodename, erlang_cookie=cookie)
+ print "client=> ", client
+ reactor.callWhenRunning(list_queues, client)
+ reactor.run()

0 comments on commit e3e2541

Please sign in to comment.
Something went wrong with that request. Please try again.