diff options
author | Darryl L. Pierce <mcpierce@apache.org> | 2012-12-04 20:56:40 +0000 |
---|---|---|
committer | Darryl L. Pierce <mcpierce@apache.org> | 2012-12-04 20:56:40 +0000 |
commit | 35e278f3c3f8b6a78ac4a9fcc57cf1c72452fd3e (patch) | |
tree | 7ced531be74288596e33a3bc97ba606f0407cd9c | |
parent | 615591405aab9b974032f20f388f435bbab4fa8b (diff) | |
download | qpid-python-35e278f3c3f8b6a78ac4a9fcc57cf1c72452fd3e.tar.gz |
BZ878940 - Fixes and improvements to spout.pl and drain.pl
Initial changes from Petr Matousek with additions from Darryl Pierce for
show usage information.
git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/0.20@1417173 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | qpid/cpp/bindings/qpid/examples/perl/drain.pl | 40 | ||||
-rw-r--r-- | qpid/cpp/bindings/qpid/examples/perl/spout.pl | 43 |
2 files changed, 64 insertions, 19 deletions
diff --git a/qpid/cpp/bindings/qpid/examples/perl/drain.pl b/qpid/cpp/bindings/qpid/examples/perl/drain.pl index 60ac0c50ed..78dd8b95c3 100644 --- a/qpid/cpp/bindings/qpid/examples/perl/drain.pl +++ b/qpid/cpp/bindings/qpid/examples/perl/drain.pl @@ -22,13 +22,15 @@ use warnings; use cqpid_perl; use Getopt::Long; +use Pod::Usage; my $url = "127.0.0.1"; -my $timeout = 60; +my $timeout = 0; my $forever = 0; -my $count = 1; +my $count = 0; my $connectionOptions = ""; my $address = "amq.direct"; +my $help; my $result = GetOptions( "broker|b=s" => \ $url, @@ -36,11 +38,10 @@ my $result = GetOptions( "forever|f" => \ $forever, "connection-options=s" => \ $connectionOptions, "count|c=i" => \ $count, -); + "help|h" => \ $help + ) || pod2usage(-verbose => 0); -if (! $result) { - print "Usage: perl drain.pl [OPTIONS]\n"; -} +pod2usage(-verbose => 1) if $help; if ($#ARGV ge 0) { $address = $ARGV[0] @@ -50,6 +51,10 @@ sub getTimeout { return ($forever) ? $cqpid_perl::Duration::FOREVER : new cqpid_perl::Duration($timeout*1000); } +sub printProperties { + my $h = shift(); + return qq[{${\(join', ',map"'$_': '$h->{$_}'",keys%$h)}}] +} my $connection = new cqpid_perl::Connection($url, $connectionOptions); @@ -63,7 +68,8 @@ eval { my $i = 0; while($receiver->fetch($message, $timeout)) { - print "Message(properties=" . $message->getProperties() . ",content='"; + my $redelivered = ($message->getRedelivered) ? "redelivered=True, " : ""; + print "Message(" . $redelivered . "properties=" . printProperties($message->getProperties()) . ", content='"; if ($message->getContentType() eq "amqp/map") { my $content = cqpid_perl::decodeMap($message); map{ print "\n$_ => $content->{$_}"; } keys %{$content}; @@ -72,7 +78,7 @@ eval { print $message->getContent(); } print "')\n"; - + my $replyto = $message->getReplyTo(); if ($replyto->getName()) { print "Replying to " . $message->getReplyTo()->str() . "...\n"; @@ -96,3 +102,21 @@ if ($@) { die $@; } +__END__ + +=head1 NAME + +drain - Drains messages from the specified address + +=head1 SYNOPSIS + + Options: + -h, --help show this message + -b VALUE, --broker VALUE url of broker to connect to + -t VALUE, --timeout VALUE timeout in seconds to wait before exiting + -f, --forever ignore timeout and wait forever + --connection-options VALUE connection options string in the form {name1:value1, name2:value2} + -c VALUE, --count VALUE number of messages to read before exiting + +=cut + diff --git a/qpid/cpp/bindings/qpid/examples/perl/spout.pl b/qpid/cpp/bindings/qpid/examples/perl/spout.pl index 7365e732bf..eaa9572ac4 100644 --- a/qpid/cpp/bindings/qpid/examples/perl/spout.pl +++ b/qpid/cpp/bindings/qpid/examples/perl/spout.pl @@ -22,6 +22,7 @@ use warnings; use cqpid_perl; use Getopt::Long; +use Pod::Usage; use Time::Local; my $url = "127.0.0.1"; @@ -34,6 +35,7 @@ my @entries; my $content = ""; my $connectionOptions = ""; my $address = "amq.direct"; +my $help; my $result = GetOptions( "broker|b=s" => \ $url, @@ -44,20 +46,16 @@ my $result = GetOptions( "property|p=s@" => \ @properties, "map|m=s@" => \ @entries, "content=s" => \ $content, - "connection-options=s" => \ $connectionOptions, -); - - -if (! $result) { - print "Usage: perl drain.pl [OPTIONS]\n"; -} + "connection-options=s" => \ $connectionOptions, + "help|h" => \ $help + ) || pod2usage(-verbose => 0); +pod2usage(-verbose => 1) if $help; if ($#ARGV ge 0) { $address = $ARGV[0] } - sub setEntries { my ($content) = @_; @@ -73,7 +71,7 @@ sub setProperties { foreach (@properties) { my ($name, $value) = split("=", $_); - $message->getProperties()->{$name} = $value; + $message->setProperty($name, $value); } } @@ -108,9 +106,9 @@ eval { my $s = "$s[3]$s[4]$s[5]"; my $n = $s; - for (my $i = 0; + for (my $i = 0; ($i < $count || $count == 0) and - ($timeout == 0 || abs($n - $s) < $timeout); + ($timeout == 0 || abs($n - $s) < $timeout); $i++) { $sender->send($message); @@ -134,3 +132,26 @@ if ($@) { } +__END__ + +=head1 NAME + +spout - Send messages to the specified address + +=head1 SYNOPSIS + + Usage: spout [OPTIONS] ADDRESS + + Options: + -h, --help show this message + -b VALUE, --broker VALUE url of broker to connect to + -t VALUE, --timeout VALUE exit after the specified time + -c VALUE, --count VALUE stop after count messageshave been sent, zero disables + -i VALUE, --id VALUE use the supplied id instead of generating one + --reply-to VALUE specify reply-to value + -P VALUE, --property VALUE specify message property + -M VALUE, --map VALUE specify entry for map content + --content VALUE specify textual content + --connection-options VALUE connection options string in the form {name1:value1, name2:value2} + +=cut |