diff options
Diffstat (limited to 'qpid/cpp/bindings/qpid/examples')
-rw-r--r-- | qpid/cpp/bindings/qpid/examples/perl/README | 26 | ||||
-rw-r--r-- | qpid/cpp/bindings/qpid/examples/perl/client.pl | 66 | ||||
-rw-r--r-- | qpid/cpp/bindings/qpid/examples/perl/drain.pl | 98 | ||||
-rw-r--r-- | qpid/cpp/bindings/qpid/examples/perl/hello_world.pl | 56 | ||||
-rw-r--r-- | qpid/cpp/bindings/qpid/examples/perl/hello_xml.pl | 76 | ||||
-rw-r--r-- | qpid/cpp/bindings/qpid/examples/perl/map_receiver.pl | 47 | ||||
-rw-r--r-- | qpid/cpp/bindings/qpid/examples/perl/map_sender.pl | 50 | ||||
-rw-r--r-- | qpid/cpp/bindings/qpid/examples/perl/server.pl | 62 | ||||
-rw-r--r-- | qpid/cpp/bindings/qpid/examples/perl/spout.pl | 136 |
9 files changed, 617 insertions, 0 deletions
diff --git a/qpid/cpp/bindings/qpid/examples/perl/README b/qpid/cpp/bindings/qpid/examples/perl/README new file mode 100644 index 0000000000..1e113f1fa0 --- /dev/null +++ b/qpid/cpp/bindings/qpid/examples/perl/README @@ -0,0 +1,26 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + + +The examples in this directory are written against the raw Perl +binding ("cqpid"). This binding is identical to the C++ messaging (in +namespace qpid::messaging). + +It is desired that a layer will be written over this interface (called +"qpid") that provides a more Perl-specific API. When this occurs, +these examples will be changed to use the new Perl API. + diff --git a/qpid/cpp/bindings/qpid/examples/perl/client.pl b/qpid/cpp/bindings/qpid/examples/perl/client.pl new file mode 100644 index 0000000000..19d9d3f14f --- /dev/null +++ b/qpid/cpp/bindings/qpid/examples/perl/client.pl @@ -0,0 +1,66 @@ +#!/usr/bin/perl +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +use strict; +use warnings; + +use cqpid_perl; + +my $url = ( @ARGV == 1 ) ? $ARGV[0] : "amqp:tcp:127.0.0.1:5672"; +my $connectionOptions = ( @ARGV > 1 ) ? $ARGV[1] : ""; + + +my $connection = new cqpid_perl::Connection($url, $connectionOptions); + +eval { +$connection->open(); +my $session = $connection->createSession(); + +my $sender = $session->createSender("service_queue"); + +#create temp queue & receiver... +my $responseQueue = new cqpid_perl::Address("#response-queue; {create:always, delete:always}"); +my $receiver = $session->createReceiver($responseQueue); + +#Now send some messages... + +my @s = ( + "Twas brillig, and the slithy toves", + "Did gire and gymble in the wabe.", + "All mimsy were the borogroves,", + "And the mome raths outgrabe." + ); + +my $request = new cqpid_perl::Message(); +$request->setReplyTo($responseQueue); +for (my $i=0; $i<4; $i++) { + $request->setContent($s[$i]); + $sender->send($request); + my $response = $receiver->fetch(); + print $request->getContent() . " -> " . $response->getContent() . "\n"; +} + +$connection->close(); +}; + +if ($@) { + die $@; +} + + diff --git a/qpid/cpp/bindings/qpid/examples/perl/drain.pl b/qpid/cpp/bindings/qpid/examples/perl/drain.pl new file mode 100644 index 0000000000..60ac0c50ed --- /dev/null +++ b/qpid/cpp/bindings/qpid/examples/perl/drain.pl @@ -0,0 +1,98 @@ +#!/usr/bin/perl +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +use strict; +use warnings; + +use cqpid_perl; +use Getopt::Long; + +my $url = "127.0.0.1"; +my $timeout = 60; +my $forever = 0; +my $count = 1; +my $connectionOptions = ""; +my $address = "amq.direct"; + +my $result = GetOptions( + "broker|b=s" => \ $url, + "timeout|t=i" => \ $timeout, + "forever|f" => \ $forever, + "connection-options=s" => \ $connectionOptions, + "count|c=i" => \ $count, +); + +if (! $result) { + print "Usage: perl drain.pl [OPTIONS]\n"; +} + +if ($#ARGV ge 0) { + $address = $ARGV[0] +} + +sub getTimeout { + return ($forever) ? $cqpid_perl::Duration::FOREVER : new cqpid_perl::Duration($timeout*1000); +} + + +my $connection = new cqpid_perl::Connection($url, $connectionOptions); + +eval { + $connection->open(); + my $session = $connection->createSession(); + my $receiver = $session->createReceiver($address); + my $timeout = getTimeout(); + + my $message = new cqpid_perl::Message(); + my $i = 0; + + while($receiver->fetch($message, $timeout)) { + print "Message(properties=" . $message->getProperties() . ",content='"; + if ($message->getContentType() eq "amqp/map") { + my $content = cqpid_perl::decodeMap($message); + map{ print "\n$_ => $content->{$_}"; } keys %{$content}; + } + else { + print $message->getContent(); + } + print "')\n"; + + my $replyto = $message->getReplyTo(); + if ($replyto->getName()) { + print "Replying to " . $message->getReplyTo()->str() . "...\n"; + my $sender = $session->createSender($replyto); + my $response = new cqpid_perl::Message("received by the server."); + $sender->send($response); + } + $session->acknowledge(); + + if ($count and (++$i ==$count)) { + last; + } + } + $receiver->close(); + $session->close(); + $connection->close(); +}; + +if ($@) { + $connection->close(); + die $@; +} + diff --git a/qpid/cpp/bindings/qpid/examples/perl/hello_world.pl b/qpid/cpp/bindings/qpid/examples/perl/hello_world.pl new file mode 100644 index 0000000000..a96b98a002 --- /dev/null +++ b/qpid/cpp/bindings/qpid/examples/perl/hello_world.pl @@ -0,0 +1,56 @@ +#!/usr/bin/perl +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +use strict; +use warnings; +use Data::Dumper; + +use cqpid_perl; + +my $broker = ( @ARGV > 0 ) ? $ARGV[0] : "localhost:5672"; +my $address = ( @ARGV > 1 ) ? $ARGV[0] : "amq.topic"; +my $connectionOptions = ( @ARGV > 2 ) ? $ARGV[1] : ""; + +my $connection = new cqpid_perl::Connection($broker, $connectionOptions); + +eval { + $connection->open(); + my $session = $connection->createSession(); + + my $receiver = $session->createReceiver($address); + my $sender = $session->createSender($address); + + $sender->send(new cqpid_perl::Message("Hello world!")); + + #my $duration = new cqpid_perl::Duration(1000); + #print ">>>" . $duration->getMilliseconds() . "\n"; + + my $message = $receiver->fetch($cqpid_perl::Duration::SECOND); + + #$message->setDurable(1); + #print "Durable: " . $message->getDurable() . "\n"; + #print Dumper($message->getProperties()); + + print $message->getContent() . "\n"; + $session->acknowledge(); + + $connection->close(); +}; + +die $@ if ($@); diff --git a/qpid/cpp/bindings/qpid/examples/perl/hello_xml.pl b/qpid/cpp/bindings/qpid/examples/perl/hello_xml.pl new file mode 100644 index 0000000000..cebf2ceee6 --- /dev/null +++ b/qpid/cpp/bindings/qpid/examples/perl/hello_xml.pl @@ -0,0 +1,76 @@ +#!/usr/bin/perl +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +use strict; +use warnings; + +use cqpid_perl; + +my $broker = ( @ARGV > 0 ) ? $ARGV[0] : "localhost:5672"; +my $connectionOptions = ( @ARGV > 1 ) ? $ARGV[1] : ""; + +my $query = <<END; + let \$w := ./weather + return \$w/station = 'Raleigh-Durham International Airport (KRDU)' + and \$w/temperature_f > 50 + and \$w/temperature_f - \$w/dewpoint > 5 + and \$w/wind_speed_mph > 7 + and \$w/wind_speed_mph < 20 +END + +my $address = <<END; +xml-exchange; { +create: always, +node: { type: topic, x-declare: { type: xml } }, +link: { +x-bindings: [{ exchange: xml-exchange, key: weather, arguments: { xquery:" $query" } }] +}} +END + + +my $connection = new cqpid_perl::Connection($broker, $connectionOptions); + +eval { + $connection->open(); + my $session = $connection->createSession(); + + my $receiver = $session->createReceiver($address); + + my $message = new cqpid_perl::Message(); + + my $content = <<END; + <weather> + <station>Raleigh-Durham International Airport (KRDU)</station> + <wind_speed_mph>16</wind_speed_mph> + <temperature_f>70</temperature_f> + <dewpoint>35</dewpoint> + </weather> +END + + $message->setContent($content); + my $sender = $session->createSender('xml-exchange/weather'); + $sender->send($message); + + my $response = $receiver->fetch(); + print $response->getContent() . "\n"; + + $connection->close(); +}; + +die $@ if ($@); diff --git a/qpid/cpp/bindings/qpid/examples/perl/map_receiver.pl b/qpid/cpp/bindings/qpid/examples/perl/map_receiver.pl new file mode 100644 index 0000000000..2e2611e38f --- /dev/null +++ b/qpid/cpp/bindings/qpid/examples/perl/map_receiver.pl @@ -0,0 +1,47 @@ +#! /usr/bin/perl5 +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +use strict; +use warnings; +use Data::Dumper; + +use cqpid_perl; + +my $url = ( @ARGV > 0 ) ? $ARGV[0] : "amqp:tcp:127.0.0.1:5672"; +my $address = ( @ARGV > 1 ) ? $ARGV[0] : "message_queue; {create: always}"; +my $connectionOptions = ( @ARGV > 2 ) ? $ARGV[1] : ""; + +my $connection = new cqpid_perl::Connection($url, $connectionOptions); + +eval { + $connection->open(); + my $session = $connection->createSession(); + my $receiver = $session->createReceiver($address); + + my $content = cqpid_perl::decodeMap($receiver->fetch()); + #my $content = cqpid_perl::decodeList($receiver->fetch()); + + print Dumper($content); + + $session->acknowledge(); + $receiver->close(); + $connection->close(); +}; + +die $@ if ($@); diff --git a/qpid/cpp/bindings/qpid/examples/perl/map_sender.pl b/qpid/cpp/bindings/qpid/examples/perl/map_sender.pl new file mode 100644 index 0000000000..4107cd48b9 --- /dev/null +++ b/qpid/cpp/bindings/qpid/examples/perl/map_sender.pl @@ -0,0 +1,50 @@ +#! /usr/bin/perl5 +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +use strict; +use warnings; +use Data::Dumper; + +use cqpid_perl; + +my $url = ( @ARGV > 0 ) ? $ARGV[0] : "amqp:tcp:127.0.0.1:5672"; +my $address = ( @ARGV > 1 ) ? $ARGV[1] : "message_queue; {create: always}"; +my $connectionOptions = ( @ARGV > 2 ) ? $ARGV[2] : ""; + +my $connection = new cqpid_perl::Connection($url, $connectionOptions); + +eval { + $connection->open(); + + my $session = $connection->createSession(); + my $sender = $session->createSender($address); + + my $message = new cqpid_perl::Message(); + my $content = { id => 987654321, + name => "Widget", + percent => sprintf("%.2f", 0.99), + colours => [ qw (red green white) ], + }; + cqpid_perl::encode($content, $message); + $sender->send($message, 1); + + $connection->close(); +}; + +die $@ if ($@); diff --git a/qpid/cpp/bindings/qpid/examples/perl/server.pl b/qpid/cpp/bindings/qpid/examples/perl/server.pl new file mode 100644 index 0000000000..b14da565b9 --- /dev/null +++ b/qpid/cpp/bindings/qpid/examples/perl/server.pl @@ -0,0 +1,62 @@ +#!/usr/bin/perl +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +use strict; +use warnings; + +use cqpid_perl; + +my $url = ( @ARGV == 1 ) ? $ARGV[0] : "amqp:tcp:127.0.0.1:5672"; +my $connectionOptions = ( @ARGV > 1 ) ? $ARGV[1] : ""; + + +my $connection = new cqpid_perl::Connection($url, $connectionOptions); + +eval { + $connection->open(); + my $session = $connection->createSession(); + + my $receiver = $session->createReceiver("service_queue; {create: always}"); + + while (1) { + my $request = $receiver->fetch(); + my $address = $request->getReplyTo(); + if ($address) { + my $sender = $session->createSender($address); + my $s = $request->getContent(); + $s = uc($s); + my $response = new cqpid_perl::Message($s); + $sender->send($response); + print "Processed request: " . $request->getContent() . " -> " . $response->getContent() . "\n"; + $session->acknowledge(); + } + else { + print "Error: no reply address specified for request: " . $request->getContent() . "\n"; + $session->reject($request); + } + } + +$connection->close(); +}; + +if ($@) { + die $@; +} + + diff --git a/qpid/cpp/bindings/qpid/examples/perl/spout.pl b/qpid/cpp/bindings/qpid/examples/perl/spout.pl new file mode 100644 index 0000000000..7365e732bf --- /dev/null +++ b/qpid/cpp/bindings/qpid/examples/perl/spout.pl @@ -0,0 +1,136 @@ +#!/usr/bin/perl +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +use strict; +use warnings; + +use cqpid_perl; +use Getopt::Long; +use Time::Local; + +my $url = "127.0.0.1"; +my $timeout = 0; +my $count = 1; +my $id = ""; +my $replyto = ""; +my @properties; +my @entries; +my $content = ""; +my $connectionOptions = ""; +my $address = "amq.direct"; + +my $result = GetOptions( + "broker|b=s" => \ $url, + "timeout|t=i" => \ $timeout, + "count|c=i" => \ $count, + "id|i=s" => \ $id, + "replyto=s" => \ $replyto, + "property|p=s@" => \ @properties, + "map|m=s@" => \ @entries, + "content=s" => \ $content, + "connection-options=s" => \ $connectionOptions, +); + + +if (! $result) { + print "Usage: perl drain.pl [OPTIONS]\n"; +} + + +if ($#ARGV ge 0) { + $address = $ARGV[0] +} + + +sub setEntries { + my ($content) = @_; + + foreach (@entries) { + my ($name, $value) = split("=", $_); + $content->{$name} = $value; + } +} + + +sub setProperties { + my ($message) = @_; + + foreach (@properties) { + my ($name, $value) = split("=", $_); + $message->getProperties()->{$name} = $value; + } +} + +my $connection = new cqpid_perl::Connection($url, $connectionOptions); + +eval { + $connection->open(); + my $session = $connection->createSession(); + my $sender = $session->createSender($address); + + my $message = new cqpid_perl::Message(); + setProperties($message) if (@properties); + if (@entries) { + my $content = {}; + setEntries($content); + cqpid_perl::encode($content, $message); + } + elsif ($content) { + $message->setContent($content); + $message->setContentType("text/plain"); + } + + my $receiver; + if ($replyto) { + my $responseQueue = new cqpid_perl::Address($replyto); + $receiver = $session->createReceiver($responseQueue); + $message->setReplyTo($responseQueue); + } + + my $start = localtime; + my @s = split(/[:\s]/, $start); + my $s = "$s[3]$s[4]$s[5]"; + my $n = $s; + + for (my $i = 0; + ($i < $count || $count == 0) and + ($timeout == 0 || abs($n - $s) < $timeout); + $i++) { + + $sender->send($message); + + if ($receiver) { + my $response = $receiver->fetch(); + print "$i -> " . $response->getContent() . "\n"; + } + + my $now = localtime; + my @n = split(/[:\s]/, $now); + my $n = "$n[3]$n[4]$n[5]"; + } + $session->sync(); + $connection->close(); +}; + +if ($@) { + $connection->close(); + die $@; +} + + |