diff options
author | Rafael H. Schloming <rhs@apache.org> | 2009-10-11 20:39:01 +0000 |
---|---|---|
committer | Rafael H. Schloming <rhs@apache.org> | 2009-10-11 20:39:01 +0000 |
commit | a3e5e307fbebe7791161bc080a37d67d9b5cb631 (patch) | |
tree | 2df21813483ba6585ce43386a4d19d2e01126d9c /python/examples/api/ping | |
parent | fbc01ca9a7908de4a8b3e75930b9cb1662ddb741 (diff) | |
download | qpid-python-a3e5e307fbebe7791161bc080a37d67d9b5cb631.tar.gz |
added ability to specify reply-to and message properties for ping; also added server example
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@824145 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'python/examples/api/ping')
-rwxr-xr-x | python/examples/api/ping | 41 |
1 files changed, 34 insertions, 7 deletions
diff --git a/python/examples/api/ping b/python/examples/api/ping index 59b367cca6..7d3686e7cf 100755 --- a/python/examples/api/ping +++ b/python/examples/api/ping @@ -22,6 +22,16 @@ import optparse, time from qpid.messaging import * from qpid.util import URL +def nameval(st): + idx = st.find("=") + if idx >= 0: + name = st[0:idx] + value = st[idx+1:] + else: + name = st + value = None + return name, value + parser = optparse.OptionParser(usage="usage: %prog [options] ADDRESS [ CONTENT ... ]", description="Drain messages from the supplied address.") parser.add_option("-b", "--broker", default="localhost", @@ -30,9 +40,12 @@ parser.add_option("-c", "--count", type=int, default=1, help="stop after count messages have been sent, zero disables (default %default)") parser.add_option("-t", "--timeout", type=float, default=None, help="exit after the specified time") -parser.add_option("-m", "--map", action="store_true", - help="interpret content as map") parser.add_option("-i", "--id", help="use the supplied id instead of generating one") +parser.add_option("-r", "--reply-to", help="specify reply-to address") +parser.add_option("-P", "--property", dest="properties", action="append", default=[], + help="specify message property") +parser.add_option("-M", "--map", dest="entries", action="append", default=[], + help="specify map entry for message body") opts, args = parser.parse_args() @@ -45,12 +58,23 @@ if args: addr = args.pop(0) else: parser.error("address is required") + +content = None + if args: - content = " ".join(args) - if opts.map: - content = eval(content) + text = " ".join(args) +else: + text = None + +if opts.entries: + content = {} + if text: + content["text"] = text + for e in opts.entries: + name, val = nameval(e) + content[name] = val else: - content = None + content = text # XXX: should make URL default the port for us conn = Connection.open(url.host, url.port or AMQP_PORT, @@ -62,8 +86,11 @@ count = 0 start = time.time() while (opts.count == 0 or count < opts.count) and \ (opts.timeout is None or time.time() - start < opts.timeout): - msg = Message(content) + msg = Message(content, reply_to=opts.reply_to) msg.properties["ping-id"] = "%s:%s" % (ping_id, count) + for p in opts.properties: + name, val = nameval(p) + msg.properties[name] = val try: snd.send(msg) |