Author: mcpierce
Date: Tue Dec  4 20:56:40 2012
New Revision: 1417173

URL: http://svn.apache.org/viewvc?rev=1417173&view=rev
Log:
BZ878940 - Fixes and improvements to spout.pl and drain.pl

Initial changes from Petr Matousek with additions from Darryl Pierce for
show usage information.

Modified:
    qpid/branches/0.20/qpid/cpp/bindings/qpid/examples/perl/drain.pl
    qpid/branches/0.20/qpid/cpp/bindings/qpid/examples/perl/spout.pl

Modified: qpid/branches/0.20/qpid/cpp/bindings/qpid/examples/perl/drain.pl
URL: 
http://svn.apache.org/viewvc/qpid/branches/0.20/qpid/cpp/bindings/qpid/examples/perl/drain.pl?rev=1417173&r1=1417172&r2=1417173&view=diff
==============================================================================
--- qpid/branches/0.20/qpid/cpp/bindings/qpid/examples/perl/drain.pl (original)
+++ qpid/branches/0.20/qpid/cpp/bindings/qpid/examples/perl/drain.pl Tue Dec  4 
20:56:40 2012
@@ -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
+

Modified: qpid/branches/0.20/qpid/cpp/bindings/qpid/examples/perl/spout.pl
URL: 
http://svn.apache.org/viewvc/qpid/branches/0.20/qpid/cpp/bindings/qpid/examples/perl/spout.pl?rev=1417173&r1=1417172&r2=1417173&view=diff
==============================================================================
--- qpid/branches/0.20/qpid/cpp/bindings/qpid/examples/perl/spout.pl (original)
+++ qpid/branches/0.20/qpid/cpp/bindings/qpid/examples/perl/spout.pl Tue Dec  4 
20:56:40 2012
@@ -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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to