diff options
Diffstat (limited to 'qpid/cpp/bindings/qpid/examples/perl/drain.pl')
-rw-r--r-- | qpid/cpp/bindings/qpid/examples/perl/drain.pl | 40 |
1 files changed, 32 insertions, 8 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 + |