You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rh...@apache.org on 2010/02/13 14:02:07 UTC
svn commit: r909810 - /qpid/trunk/qpid/python/examples/api/drain
Author: rhs
Date: Sat Feb 13 13:02:06 2010
New Revision: 909810
URL: http://svn.apache.org/viewvc?rev=909810&view=rev
Log:
added count and print formatting options to drain
Modified:
qpid/trunk/qpid/python/examples/api/drain
Modified: qpid/trunk/qpid/python/examples/api/drain
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/python/examples/api/drain?rev=909810&r1=909809&r2=909810&view=diff
==============================================================================
--- qpid/trunk/qpid/python/examples/api/drain (original)
+++ qpid/trunk/qpid/python/examples/api/drain Sat Feb 13 13:02:06 2010
@@ -27,6 +27,10 @@
description="Drain messages from the supplied address.")
parser.add_option("-b", "--broker", default="localhost",
help="connect to specified BROKER (default %default)")
+parser.add_option("-c", "--count", type=int,
+ help="number of messages to drain")
+parser.add_option("-f", "--forever", action="store_true",
+ help="ignore timeout and wait forever")
parser.add_option("-r", "--reconnect", action="store_true",
help="enable auto reconnect")
parser.add_option("-d", "--reconnect-delay", type=float, default=3,
@@ -35,8 +39,8 @@
help="maximum number of reconnect attempts")
parser.add_option("-t", "--timeout", type=float, default=0,
help="timeout in seconds to wait before exiting (default %default)")
-parser.add_option("-f", "--forever", action="store_true",
- help="ignore timeout and wait forever")
+parser.add_option("-p", "--print", dest="format", default="%(M)s",
+ help="format string for printing messages (default %default)")
parser.add_option("-v", dest="verbose", action="store_true",
help="enable logging")
@@ -57,6 +61,17 @@
else:
timeout = opts.timeout
+class Formatter:
+
+ def __init__(self, message):
+ self.message = message
+ self.environ = {"M": self.message,
+ "P": self.message.properties,
+ "C": self.message.content}
+
+ def __getitem__(self, st):
+ return eval(st, self.environ)
+
# XXX: should make URL default the port for us
conn = Connection.open(url.host, url.port or AMQP_PORT,
username=url.user,
@@ -67,9 +82,12 @@
ssn = conn.session()
rcv = ssn.receiver(addr)
-while True:
+count = 0
+while not opts.count or count < opts.count:
try:
- print rcv.fetch(timeout=timeout)
+ msg = rcv.fetch(timeout=timeout)
+ print opts.format % Formatter(msg)
+ count += 1
ssn.acknowledge()
except Empty:
break
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org