http://git-wip-us.apache.org/repos/asf/qpid-site/blob/1859e58c/content/releases/qpid-proton-0.17.0/messenger/perl/examples/index.html ---------------------------------------------------------------------- diff --git a/content/releases/qpid-proton-0.17.0/messenger/perl/examples/index.html b/content/releases/qpid-proton-0.17.0/messenger/perl/examples/index.html new file mode 100644 index 0000000..c46ec59 --- /dev/null +++ b/content/releases/qpid-proton-0.17.0/messenger/perl/examples/index.html @@ -0,0 +1,162 @@ +<!DOCTYPE html> +<!-- + - + - 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. + - +--> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> + <head> + <title>Perl AMQP Messenger Examples - Apache Qpid™</title> + <meta http-equiv="X-UA-Compatible" content="IE=edge"/> + <meta name="viewport" content="width=device-width, initial-scale=1.0"/> + <link rel="stylesheet" href="/site.css" type="text/css" async="async"/> + <link rel="stylesheet" href="/deferred.css" type="text/css" defer="defer"/> + <script type="text/javascript">var _deferredFunctions = [];</script> + <script type="text/javascript" src="/deferred.js" defer="defer"></script> + <!--[if lte IE 8]> + <link rel="stylesheet" href="/ie.css" type="text/css"/> + <script type="text/javascript" src="/html5shiv.js"></script> + <![endif]--> + + <!-- Redirects for `go get` and godoc.org --> + <meta name="go-import" + content="qpid.apache.org git https://git-wip-us.apache.org/repos/asf/qpid-proton.git"/> + <meta name="go-source" + content="qpid.apache.org +https://github.com/apache/qpid-proton/blob/go1/README.md +https://github.com/apache/qpid-proton/tree/go1{/dir} +https://github.com/apache/qpid-proton/blob/go1{/dir}/{file}#L{line}"/> + </head> + <body> + <div id="-content"> + <div id="-top" class="panel"> + <a id="-menu-link"><img width="16" height="16" src="" alt="Menu"/></a> + + <a id="-search-link"><img width="22" height="16" src="" alt="Search"/></a> + + <ul id="-global-navigation"> + <li><a id="-logotype" href="/index.html">Apache Qpid<sup>™</sup></a></li> + <li><a href="/documentation.html">Documentation</a></li> + <li><a href="/download.html">Download</a></li> + <li><a href="/discussion.html">Discussion</a></li> + </ul> + </div> + + <div id="-menu" class="panel" style="display: none;"> + <div class="flex"> + <section> + <h3>Project</h3> + + <ul> + <li><a href="/overview.html">Overview</a></li> + <li><a href="/components/index.html">Components</a></li> + <li><a href="/releases/index.html">Releases</a></li> + </ul> + </section> + + <section> + <h3>Messaging APIs</h3> + + <ul> + <li><a href="/proton/index.html">Qpid Proton</a></li> + <li><a href="/components/jms/index.html">Qpid JMS</a></li> + <li><a href="/components/messaging-api/index.html">Qpid Messaging API</a></li> + </ul> + </section> + + <section> + <h3>Servers and tools</h3> + + <ul> + <li><a href="/components/java-broker/index.html">Broker for Java</a></li> + <li><a href="/components/cpp-broker/index.html">C++ broker</a></li> + <li><a href="/components/dispatch-router/index.html">Dispatch router</a></li> + </ul> + </section> + + <section> + <h3>Resources</h3> + + <ul> + <li><a href="/dashboard.html">Dashboard</a></li> + <li><a href="https://cwiki.apache.org/confluence/display/qpid/Index">Wiki</a></li> + <li><a href="/resources.html">More resources</a></li> + </ul> + </section> + </div> + </div> + + <div id="-search" class="panel" style="display: none;"> + <form action="http://www.google.com/search" method="get"> + <input type="hidden" name="sitesearch" value="qpid.apache.org"/> + <input type="text" name="q" maxlength="255" autofocus="autofocus" tabindex="1"/> + <button type="submit">Search</button> + <a href="/search.html">More ways to search</a> + </form> + </div> + + <div id="-middle" class="panel"> + <ul id="-path-navigation"><li><a href="/index.html">Home</a></li><li><a href="/releases/index.html">Releases</a></li><li><a href="/releases/qpid-proton-0.17.0/index.html">Qpid Proton 0.17.0</a></li><li>Perl AMQP Messenger Examples</li></ul> + + <div id="-middle-content"> + <h1 id="perl-amqp-messenger-examples">Perl AMQP Messenger Examples</h1> + +<h2 id="example-files">Example files</h2> + +<ul> +<li><a href="client.pl.html">client.pl</a></li> +<li><a href="recv.pl.html">recv.pl</a></li> +<li><a href="recv_async.pl.html">recv_async.pl</a></li> +<li><a href="send.pl.html">send.pl</a></li> +<li><a href="send_async.pl.html">send_async.pl</a></li> +<li><a href="server.pl.html">server.pl</a></li> +</ul> + +<h2 id="more-information">More information</h2> + +<ul> +<li><a href="https://github.com/apache/qpid-proton/tree/0.17.0/examples/perl/messenger">Source location</a></li> +</ul> + + + <hr/> + + <ul id="-apache-navigation"> + <li><a href="http://www.apache.org/">Apache</a></li> + <li><a href="http://www.apache.org/licenses/">License</a></li> + <li><a href="http://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li> + <li><a href="http://www.apache.org/foundation/thanks.html">Thanks!</a></li> + <li><a href="/security.html">Security</a></li> + <li><a href="http://www.apache.org/"><img id="-apache-feather" width="48" height="14" src="" alt="Apache"/></a></li> + </ul> + + <p id="-legal"> + Apache Qpid, Messaging built on AMQP; Copyright © 2015 + The Apache Software Foundation; Licensed under + the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache + License, Version 2.0</a>; Apache Qpid, Qpid, Qpid Proton, + Proton, Apache, the Apache feather logo, and the Apache Qpid + project logo are trademarks of The Apache Software + Foundation; All other marks mentioned may be trademarks or + registered trademarks of their respective owners + </p> + </div> + </div> + </div> + </body> +</html>
http://git-wip-us.apache.org/repos/asf/qpid-site/blob/1859e58c/content/releases/qpid-proton-0.17.0/messenger/perl/examples/recv.pl ---------------------------------------------------------------------- diff --git a/content/releases/qpid-proton-0.17.0/messenger/perl/examples/recv.pl b/content/releases/qpid-proton-0.17.0/messenger/perl/examples/recv.pl new file mode 100755 index 0000000..801f6a2 --- /dev/null +++ b/content/releases/qpid-proton-0.17.0/messenger/perl/examples/recv.pl @@ -0,0 +1,99 @@ +#!/usr/bin/env 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 warnings; + +use Scalar::Util qw(reftype); +use Data::Dumper; + +use qpid_proton; + +sub usage { + exit(0); +} + +my @addresses = @ARGV; +@addresses = ("~0.0.0.0") unless $addresses[0]; + +my $messenger = new qpid::proton::Messenger(); +my $msg = new qpid::proton::Message(); + +$messenger->start(); + +foreach (@addresses) +{ + print "Subscribing to $_\n"; + $messenger->subscribe($_); +} + +for(;;) +{ + $messenger->receive(10); + + while ($messenger->incoming() > 0) + { + $messenger->get($msg); + + print "\n"; + print "Address: " . $msg->get_address() . "\n"; + print "Subject: " . $msg->get_subject() . "\n" unless !defined($msg->get_subject()); + print "Body: "; + + my $body = $msg->get_body(); + my $body_type = $msg->get_body_type(); + + if (!defined($body_type)) { + print "The body type wasn't defined!\n"; + } elsif ($body_type == qpid::proton::BOOL) { + print "[BOOL]\n"; + print "" . ($body ? "TRUE" : "FALSE") . "\n"; + } elsif ($body_type == qpid::proton::MAP) { + print "[HASH]\n"; + print Dumper(\%{$body}) . "\n"; + } elsif ($body_type == qpid::proton::ARRAY) { + print "[ARRAY]\n"; + print Data::Dumper->Dump($body) . "\n"; + } elsif ($body_type == qpid::proton::LIST) { + print "[LIST]\n"; + print Data::Dumper->Dump($body) . "\n"; + } else { + print "[$body_type]\n"; + print "$body\n"; + } + + print "Properties:\n"; + my $props = $msg->get_properties(); + foreach (keys $props) { + print "\t$_=$props->{$_}\n"; + } + print "Instructions:\n"; + my $instructions = $msg->get_instructions; + foreach (keys $instructions) { + print "\t$_=" . $instructions->{$_} . "\n"; + } + print "Annotations:\n"; + my $annotations = $msg->get_annotations(); + foreach (keys $annotations) { + print "\t$_=" . $annotations->{$_} . "\n"; + } + } +} + +die $@ if ($@); http://git-wip-us.apache.org/repos/asf/qpid-site/blob/1859e58c/content/releases/qpid-proton-0.17.0/messenger/perl/examples/recv.pl.html ---------------------------------------------------------------------- diff --git a/content/releases/qpid-proton-0.17.0/messenger/perl/examples/recv.pl.html b/content/releases/qpid-proton-0.17.0/messenger/perl/examples/recv.pl.html new file mode 100644 index 0000000..2727713 --- /dev/null +++ b/content/releases/qpid-proton-0.17.0/messenger/perl/examples/recv.pl.html @@ -0,0 +1,228 @@ +<!DOCTYPE html> +<!-- + - + - 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. + - +--> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> + <head> + <title>recv.pl - Apache Qpid™</title> + <meta http-equiv="X-UA-Compatible" content="IE=edge"/> + <meta name="viewport" content="width=device-width, initial-scale=1.0"/> + <link rel="stylesheet" href="/site.css" type="text/css" async="async"/> + <link rel="stylesheet" href="/deferred.css" type="text/css" defer="defer"/> + <script type="text/javascript">var _deferredFunctions = [];</script> + <script type="text/javascript" src="/deferred.js" defer="defer"></script> + <!--[if lte IE 8]> + <link rel="stylesheet" href="/ie.css" type="text/css"/> + <script type="text/javascript" src="/html5shiv.js"></script> + <![endif]--> + + <!-- Redirects for `go get` and godoc.org --> + <meta name="go-import" + content="qpid.apache.org git https://git-wip-us.apache.org/repos/asf/qpid-proton.git"/> + <meta name="go-source" + content="qpid.apache.org +https://github.com/apache/qpid-proton/blob/go1/README.md +https://github.com/apache/qpid-proton/tree/go1{/dir} +https://github.com/apache/qpid-proton/blob/go1{/dir}/{file}#L{line}"/> + </head> + <body> + <div id="-content"> + <div id="-top" class="panel"> + <a id="-menu-link"><img width="16" height="16" src="" alt="Menu"/></a> + + <a id="-search-link"><img width="22" height="16" src="" alt="Search"/></a> + + <ul id="-global-navigation"> + <li><a id="-logotype" href="/index.html">Apache Qpid<sup>™</sup></a></li> + <li><a href="/documentation.html">Documentation</a></li> + <li><a href="/download.html">Download</a></li> + <li><a href="/discussion.html">Discussion</a></li> + </ul> + </div> + + <div id="-menu" class="panel" style="display: none;"> + <div class="flex"> + <section> + <h3>Project</h3> + + <ul> + <li><a href="/overview.html">Overview</a></li> + <li><a href="/components/index.html">Components</a></li> + <li><a href="/releases/index.html">Releases</a></li> + </ul> + </section> + + <section> + <h3>Messaging APIs</h3> + + <ul> + <li><a href="/proton/index.html">Qpid Proton</a></li> + <li><a href="/components/jms/index.html">Qpid JMS</a></li> + <li><a href="/components/messaging-api/index.html">Qpid Messaging API</a></li> + </ul> + </section> + + <section> + <h3>Servers and tools</h3> + + <ul> + <li><a href="/components/java-broker/index.html">Broker for Java</a></li> + <li><a href="/components/cpp-broker/index.html">C++ broker</a></li> + <li><a href="/components/dispatch-router/index.html">Dispatch router</a></li> + </ul> + </section> + + <section> + <h3>Resources</h3> + + <ul> + <li><a href="/dashboard.html">Dashboard</a></li> + <li><a href="https://cwiki.apache.org/confluence/display/qpid/Index">Wiki</a></li> + <li><a href="/resources.html">More resources</a></li> + </ul> + </section> + </div> + </div> + + <div id="-search" class="panel" style="display: none;"> + <form action="http://www.google.com/search" method="get"> + <input type="hidden" name="sitesearch" value="qpid.apache.org"/> + <input type="text" name="q" maxlength="255" autofocus="autofocus" tabindex="1"/> + <button type="submit">Search</button> + <a href="/search.html">More ways to search</a> + </form> + </div> + + <div id="-middle" class="panel"> + <ul id="-path-navigation"><li><a href="/index.html">Home</a></li><li><a href="/releases/index.html">Releases</a></li><li><a href="/releases/qpid-proton-0.17.0/index.html">Qpid Proton 0.17.0</a></li><li><a href="/releases/qpid-proton-0.17.0/messenger/perl/examples/index.html">Perl AMQP Messenger Examples</a></li><li>recv.pl</li></ul> + + <div id="-middle-content"> + +<h1>recv.pl</h1> +<div class="highlight"><pre><span class="k">use</span> <span class="n">warnings</span><span class="p">;</span> + +<span class="k">use</span> <span class="nn">Scalar::</span><span class="n">Util</span> <span class="sx">qw(reftype)</span><span class="p">;</span> +<span class="k">use</span> <span class="nn">Data::</span><span class="n">Dumper</span><span class="p">;</span> + +<span class="k">use</span> <span class="n">qpid_proton</span><span class="p">;</span> + +<span class="k">sub </span><span class="nf">usage</span> <span class="p">{</span> + <span class="nb">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span> +<span class="p">}</span> + +<span class="k">my</span> <span class="nv">@addresses</span> <span class="o">=</span> <span class="nv">@ARGV</span><span class="p">;</span> +<span class="nv">@addresses</span> <span class="o">=</span> <span class="p">(</span><span class="s">"~0.0.0.0"</span><span class="p">)</span> <span class="k">unless</span> <span class="nv">$addresses</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span> + +<span class="k">my</span> <span class="nv">$messenger</span> <span class="o">=</span> <span class="k">new</span> <span class="nn">qpid::proton::</span><span class="n">Messenger</span><span class="p">();</span> +<span class="k">my</span> <span class="nv">$msg</span> <span class="o">=</span> <span class="k">new</span> <span class="nn">qpid::proton::</span><span class="n">Message</span><span class="p">();</span> + +<span class="nv">$messenger</span><span class="o">-></span><span class="n">start</span><span class="p">();</span> + +<span class="k">foreach</span> <span class="p">(</span><span class="nv">@addresses</span><span class="p">)</span> +<span class="p">{</span> + <span class="k">print</span> <span class="s">"Subscribing to $_\n"</span><span class="p">;</span> + <span class="nv">$messenger</span><span class="o">-></span><span class="n">subscribe</span><span class="p">(</span><span class="nv">$_</span><span class="p">);</span> +<span class="p">}</span> + +<span class="k">for</span><span class="p">(;;)</span> +<span class="p">{</span> + <span class="nv">$messenger</span><span class="o">-></span><span class="n">receive</span><span class="p">(</span><span class="mi">10</span><span class="p">);</span> + + <span class="k">while</span> <span class="p">(</span><span class="nv">$messenger</span><span class="o">-></span><span class="n">incoming</span><span class="p">()</span> <span class="o">></span> <span class="mi">0</span><span class="p">)</span> + <span class="p">{</span> + <span class="nv">$messenger</span><span class="o">-></span><span class="n">get</span><span class="p">(</span><span class="nv">$msg</span><span class="p">);</span> + + <span class="k">print</span> <span class="s">"\n"</span><span class="p">;</span> + <span class="k">print</span> <span class="s">"Address: "</span> <span class="o">.</span> <span class="nv">$msg</span><span class="o">-></span><span class="n">get_address</span><span class="p">()</span> <span class="o">.</span> <span class="s">"\n"</span><span class="p">;</span> + <span class="k">print</span> <span class="s">"Subject: "</span> <span class="o">.</span> <span class="nv">$msg</span><span class="o">-></span><span class="n">get_subject</span><span class="p">()</span> <span class="o">.</span> <span class="s">"\n"</span> <span class="k">unless</span> <span class="o">!</span><span class="nb">defined</span><span class="p">(</span><span class="nv">$msg</span><span class="o">-></span><span class="n">get_subject</span><span class="p">());</span> + <span class="k">print</span> <span class="s">"Body: "</span><span class="p">;</span> + + <span class="k">my</span> <span class="nv">$body</span> <span class="o">=</span> <span class="nv">$msg</span><span class="o">-></span><span class="n">get_body</span><span class="p">();</span> + <span class="k">my</span> <span class="nv">$body_type</span> <span class="o">=</span> <span class="nv">$msg</span><span class="o">-></span><span class="n">get_body_type</span><span class="p">();</span> + + <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nb">defined</span><span class="p">(</span><span class="nv">$body_type</span><span class="p">))</span> <span class="p">{</span> + <span class="k">print</span> <span class="s">"The body type wasn't defined!\n"</span><span class="p">;</span> + <span class="p">}</span> <span class="k">elsif</span> <span class="p">(</span><span class="nv">$body_type</span> <span class="o">==</span> <span class="nn">qpid::proton::</span><span class="n">BOOL</span><span class="p">)</span> <span class="p">{</span> + <span class="k">print</span> <span class="s">"[BOOL]\n"</span><span class="p">;</span> + <span class="k">print</span> <span class="s">""</span> <span class="o">.</span> <span class="p">(</span><span class="nv">$body</span> <span class="p">?</span> <span class="s">"TRUE"</span> <span class="p">:</span> <span class="s">"FALSE"</span><span class="p">)</span> <span class="o">.</span> <span class="s">"\n"</span><span class="p">;</span> + <span class="p">}</span> <span class="k">elsif</span> <span class="p">(</span><span class="nv">$body_type</span> <span class="o">==</span> <span class="nn">qpid::proton::</span><span class="n">MAP</span><span class="p">)</span> <span class="p">{</span> + <span class="k">print</span> <span class="s">"[HASH]\n"</span><span class="p">;</span> + <span class="k">print</span> <span class="n">Dumper</span><span class="p">(</span><span class="o">\</span><span class="nv">%</span><span class="p">{</span><span class="nv">$body</span><span class="p">})</span> <span class="o">.</span> <span class="s">"\n"</span><span class="p">;</span> + <span class="p">}</span> <span class="k">elsif</span> <span class="p">(</span><span class="nv">$body_type</span> <span class="o">==</span> <span class="nn">qpid::proton::</span><span class="n">ARRAY</span><span class="p">)</span> <span class="p">{</span> + <span class="k">print</span> <span class="s">"[ARRAY]\n"</span><span class="p">;</span> + <span class="k">print</span> <span class="nn">Data::</span><span class="n">Dumper</span><span class="o">-></span><span class="n">Dump</span><span class="p">(</span><span class="nv">$body</span><span class="p">)</span> <span class="o">.</span> <span class="s">"\n"</span><span class="p">;</span> + <span class="p">}</span> <span class="k">elsif</span> <span class="p">(</span><span class="nv">$body_type</span> <span class="o">==</span> <span class="nn">qpid::proton::</span><span class="n">LIST</span><span class="p">)</span> <span class="p">{</span> + <span class="k">print</span> <span class="s">"[LIST]\n"</span><span class="p">;</span> + <span class="k">print</span> <span class="nn">Data::</span><span class="n">Dumper</span><span class="o">-></span><span class="n">Dump</span><span class="p">(</span><span class="nv">$body</span><span class="p">)</span> <span class="o">.</span> <span class="s">"\n"</span><span class="p">;</span> + <span class="p">}</span> <span class="k">else</span> <span class="p">{</span> + <span class="k">print</span> <span class="s">"[$body_type]\n"</span><span class="p">;</span> + <span class="k">print</span> <span class="s">"$body\n"</span><span class="p">;</span> + <span class="p">}</span> + + <span class="k">print</span> <span class="s">"Properties:\n"</span><span class="p">;</span> + <span class="k">my</span> <span class="nv">$props</span> <span class="o">=</span> <span class="nv">$msg</span><span class="o">-></span><span class="n">get_properties</span><span class="p">();</span> + <span class="k">foreach</span> <span class="p">(</span><span class="nb">keys</span> <span class="nv">$props</span><span class="p">)</span> <span class="p">{</span> + <span class="k">print</span> <span class="s">"\t$_=$props->{$_}\n"</span><span class="p">;</span> + <span class="p">}</span> + <span class="k">print</span> <span class="s">"Instructions:\n"</span><span class="p">;</span> + <span class="k">my</span> <span class="nv">$instructions</span> <span class="o">=</span> <span class="nv">$msg</span><span class="o">-></span><span class="n">get_instructions</span><span class="p">;</span> + <span class="k">foreach</span> <span class="p">(</span><span class="nb">keys</span> <span class="nv">$instructions</span><span class="p">)</span> <span class="p">{</span> + <span class="k">print</span> <span class="s">"\t$_="</span> <span class="o">.</span> <span class="nv">$instructions</span><span class="o">-></span><span class="p">{</span><span class="nv">$_</span><span class="p">}</span> <span class="o">.</span> <span class="s">"\n"</span><span class="p">;</span> + <span class="p">}</span> + <span class="k">print</span> <span class="s">"Annotations:\n"</span><span class="p">;</span> + <span class="k">my</span> <span class="nv">$annotations</span> <span class="o">=</span> <span class="nv">$msg</span><span class="o">-></span><span class="n">get_annotations</span><span class="p">();</span> + <span class="k">foreach</span> <span class="p">(</span><span class="nb">keys</span> <span class="nv">$annotations</span><span class="p">)</span> <span class="p">{</span> + <span class="k">print</span> <span class="s">"\t$_="</span> <span class="o">.</span> <span class="nv">$annotations</span><span class="o">-></span><span class="p">{</span><span class="nv">$_</span><span class="p">}</span> <span class="o">.</span> <span class="s">"\n"</span><span class="p">;</span> + <span class="p">}</span> + <span class="p">}</span> +<span class="p">}</span> + +<span class="nb">die</span> <span class="vg">$@</span> <span class="k">if</span> <span class="p">(</span><span class="vg">$@</span><span class="p">);</span> +</pre></div> + +<p><a href="recv.pl">Download this file</a></p> + + + <hr/> + + <ul id="-apache-navigation"> + <li><a href="http://www.apache.org/">Apache</a></li> + <li><a href="http://www.apache.org/licenses/">License</a></li> + <li><a href="http://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li> + <li><a href="http://www.apache.org/foundation/thanks.html">Thanks!</a></li> + <li><a href="/security.html">Security</a></li> + <li><a href="http://www.apache.org/"><img id="-apache-feather" width="48" height="14" src="" alt="Apache"/></a></li> + </ul> + + <p id="-legal"> + Apache Qpid, Messaging built on AMQP; Copyright © 2015 + The Apache Software Foundation; Licensed under + the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache + License, Version 2.0</a>; Apache Qpid, Qpid, Qpid Proton, + Proton, Apache, the Apache feather logo, and the Apache Qpid + project logo are trademarks of The Apache Software + Foundation; All other marks mentioned may be trademarks or + registered trademarks of their respective owners + </p> + </div> + </div> + </div> + </body> +</html> http://git-wip-us.apache.org/repos/asf/qpid-site/blob/1859e58c/content/releases/qpid-proton-0.17.0/messenger/perl/examples/recv_async.pl ---------------------------------------------------------------------- diff --git a/content/releases/qpid-proton-0.17.0/messenger/perl/examples/recv_async.pl b/content/releases/qpid-proton-0.17.0/messenger/perl/examples/recv_async.pl new file mode 100755 index 0000000..9a2195a --- /dev/null +++ b/content/releases/qpid-proton-0.17.0/messenger/perl/examples/recv_async.pl @@ -0,0 +1,84 @@ +# +# 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 qpid_proton; +use async; + +package async::Receiver; + +@ISA = (async::CallbackAdapter); + +sub on_start { + my ($self) = @_; + my $args = $_[1] || ("amqp://~0.0.0.0"); + my $messenger = $self->{_messenger}; + + foreach $arg ($args) { + $messenger->subscribe($arg); + } + + $messenger->receive(); +} + +sub on_receive { + my ($self) = @_; + my $msg = $_[1]; + my $message = $self->{_message}; + my $text = ""; + + if (defined($msg->get_body)) { + $text = $msg->get_body; + if ($text eq "die") { + $self->stop; + } + } else { + $text = $message->get_subject; + } + + $text = "" if (!defined($text)); + + print "Received: $text\n"; + + if ($msg->get_reply_to) { + print "Sending reply to: " . $msg->get_reply_to . "\n"; + $message->clear; + $message->set_address($msg->get_reply_to()); + $message->set_body("Reply for ", $msg->get_body); + $self->send($message); + } +} + +sub on_status { + my ($self) = @_; + my $messenger = $self->{_messenger}; + my $status = $_[1]; + + print "Status: ", $status, "\n"; +} + +sub on_stop { + print "Stopped.\n" +} + +package main; + +our $messenger = new qpid::proton::Messenger(); +our $app = new async::Receiver($messenger); + +$app->run(); http://git-wip-us.apache.org/repos/asf/qpid-site/blob/1859e58c/content/releases/qpid-proton-0.17.0/messenger/perl/examples/recv_async.pl.html ---------------------------------------------------------------------- diff --git a/content/releases/qpid-proton-0.17.0/messenger/perl/examples/recv_async.pl.html b/content/releases/qpid-proton-0.17.0/messenger/perl/examples/recv_async.pl.html new file mode 100644 index 0000000..9149553 --- /dev/null +++ b/content/releases/qpid-proton-0.17.0/messenger/perl/examples/recv_async.pl.html @@ -0,0 +1,214 @@ +<!DOCTYPE html> +<!-- + - + - 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. + - +--> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> + <head> + <title>recv_async.pl - Apache Qpid™</title> + <meta http-equiv="X-UA-Compatible" content="IE=edge"/> + <meta name="viewport" content="width=device-width, initial-scale=1.0"/> + <link rel="stylesheet" href="/site.css" type="text/css" async="async"/> + <link rel="stylesheet" href="/deferred.css" type="text/css" defer="defer"/> + <script type="text/javascript">var _deferredFunctions = [];</script> + <script type="text/javascript" src="/deferred.js" defer="defer"></script> + <!--[if lte IE 8]> + <link rel="stylesheet" href="/ie.css" type="text/css"/> + <script type="text/javascript" src="/html5shiv.js"></script> + <![endif]--> + + <!-- Redirects for `go get` and godoc.org --> + <meta name="go-import" + content="qpid.apache.org git https://git-wip-us.apache.org/repos/asf/qpid-proton.git"/> + <meta name="go-source" + content="qpid.apache.org +https://github.com/apache/qpid-proton/blob/go1/README.md +https://github.com/apache/qpid-proton/tree/go1{/dir} +https://github.com/apache/qpid-proton/blob/go1{/dir}/{file}#L{line}"/> + </head> + <body> + <div id="-content"> + <div id="-top" class="panel"> + <a id="-menu-link"><img width="16" height="16" src="" alt="Menu"/></a> + + <a id="-search-link"><img width="22" height="16" src="" alt="Search"/></a> + + <ul id="-global-navigation"> + <li><a id="-logotype" href="/index.html">Apache Qpid<sup>™</sup></a></li> + <li><a href="/documentation.html">Documentation</a></li> + <li><a href="/download.html">Download</a></li> + <li><a href="/discussion.html">Discussion</a></li> + </ul> + </div> + + <div id="-menu" class="panel" style="display: none;"> + <div class="flex"> + <section> + <h3>Project</h3> + + <ul> + <li><a href="/overview.html">Overview</a></li> + <li><a href="/components/index.html">Components</a></li> + <li><a href="/releases/index.html">Releases</a></li> + </ul> + </section> + + <section> + <h3>Messaging APIs</h3> + + <ul> + <li><a href="/proton/index.html">Qpid Proton</a></li> + <li><a href="/components/jms/index.html">Qpid JMS</a></li> + <li><a href="/components/messaging-api/index.html">Qpid Messaging API</a></li> + </ul> + </section> + + <section> + <h3>Servers and tools</h3> + + <ul> + <li><a href="/components/java-broker/index.html">Broker for Java</a></li> + <li><a href="/components/cpp-broker/index.html">C++ broker</a></li> + <li><a href="/components/dispatch-router/index.html">Dispatch router</a></li> + </ul> + </section> + + <section> + <h3>Resources</h3> + + <ul> + <li><a href="/dashboard.html">Dashboard</a></li> + <li><a href="https://cwiki.apache.org/confluence/display/qpid/Index">Wiki</a></li> + <li><a href="/resources.html">More resources</a></li> + </ul> + </section> + </div> + </div> + + <div id="-search" class="panel" style="display: none;"> + <form action="http://www.google.com/search" method="get"> + <input type="hidden" name="sitesearch" value="qpid.apache.org"/> + <input type="text" name="q" maxlength="255" autofocus="autofocus" tabindex="1"/> + <button type="submit">Search</button> + <a href="/search.html">More ways to search</a> + </form> + </div> + + <div id="-middle" class="panel"> + <ul id="-path-navigation"><li><a href="/index.html">Home</a></li><li><a href="/releases/index.html">Releases</a></li><li><a href="/releases/qpid-proton-0.17.0/index.html">Qpid Proton 0.17.0</a></li><li><a href="/releases/qpid-proton-0.17.0/messenger/perl/examples/index.html">Perl AMQP Messenger Examples</a></li><li>recv_async.pl</li></ul> + + <div id="-middle-content"> + +<h1>recv_async.pl</h1> +<div class="highlight"><pre><span class="k">use</span> <span class="n">qpid_proton</span><span class="p">;</span> +<span class="k">use</span> <span class="n">async</span><span class="p">;</span> + +<span class="nb">package</span> <span class="nn">async::</span><span class="n">Receiver</span><span class="p">;</span> + +<span class="nv">@ISA</span> <span class="o">=</span> <span class="p">(</span><span class="nn">async::</span><span class="n">CallbackAdapter</span><span class="p">);</span> + +<span class="k">sub </span><span class="nf">on_start</span> <span class="p">{</span> + <span class="k">my</span> <span class="p">(</span><span class="nv">$self</span><span class="p">)</span> <span class="o">=</span> <span class="nv">@_</span><span class="p">;</span> + <span class="k">my</span> <span class="nv">$args</span> <span class="o">=</span> <span class="nv">$_</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">||</span> <span class="p">(</span><span class="s">"amqp://~0.0.0.0"</span><span class="p">);</span> + <span class="k">my</span> <span class="nv">$messenger</span> <span class="o">=</span> <span class="nv">$self</span><span class="o">-></span><span class="p">{</span><span class="n">_messenger</span><span class="p">};</span> + + <span class="k">foreach</span> <span class="nv">$arg</span> <span class="p">(</span><span class="nv">$args</span><span class="p">)</span> <span class="p">{</span> + <span class="nv">$messenger</span><span class="o">-></span><span class="n">subscribe</span><span class="p">(</span><span class="nv">$arg</span><span class="p">);</span> + <span class="p">}</span> + + <span class="nv">$messenger</span><span class="o">-></span><span class="n">receive</span><span class="p">();</span> +<span class="p">}</span> + +<span class="k">sub </span><span class="nf">on_receive</span> <span class="p">{</span> + <span class="k">my</span> <span class="p">(</span><span class="nv">$self</span><span class="p">)</span> <span class="o">=</span> <span class="nv">@_</span><span class="p">;</span> + <span class="k">my</span> <span class="nv">$msg</span> <span class="o">=</span> <span class="nv">$_</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span> + <span class="k">my</span> <span class="nv">$message</span> <span class="o">=</span> <span class="nv">$self</span><span class="o">-></span><span class="p">{</span><span class="n">_message</span><span class="p">};</span> + <span class="k">my</span> <span class="nv">$text</span> <span class="o">=</span> <span class="s">""</span><span class="p">;</span> + + <span class="k">if</span> <span class="p">(</span><span class="nb">defined</span><span class="p">(</span><span class="nv">$msg</span><span class="o">-></span><span class="n">get_body</span><span class="p">))</span> <span class="p">{</span> + <span class="nv">$text</span> <span class="o">=</span> <span class="nv">$msg</span><span class="o">-></span><span class="n">get_body</span><span class="p">;</span> + <span class="k">if</span> <span class="p">(</span><span class="nv">$text</span> <span class="ow">eq</span> <span class="s">"die"</span><span class="p">)</span> <span class="p">{</span> + <span class="nv">$self</span><span class="o">-></span><span class="n">stop</span><span class="p">;</span> + <span class="p">}</span> + <span class="p">}</span> <span class="k">else</span> <span class="p">{</span> + <span class="nv">$text</span> <span class="o">=</span> <span class="nv">$message</span><span class="o">-></span><span class="n">get_subject</span><span class="p">;</span> + <span class="p">}</span> + + <span class="nv">$text</span> <span class="o">=</span> <span class="s">""</span> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nb">defined</span><span class="p">(</span><span class="nv">$text</span><span class="p">));</span> + + <span class="k">print</span> <span class="s">"Received: $text\n"</span><span class="p">;</span> + + <span class="k">if</span> <span class="p">(</span><span class="nv">$msg</span><span class="o">-></span><span class="n">get_reply_to</span><span class="p">)</span> <span class="p">{</span> + <span class="k">print</span> <span class="s">"Sending reply to: "</span> <span class="o">.</span> <span class="nv">$msg</span><span class="o">-></span><span class="n">get_reply_to</span> <span class="o">.</span> <span class="s">"\n"</span><span class="p">;</span> + <span class="nv">$message</span><span class="o">-></span><span class="n">clear</span><span class="p">;</span> + <span class="nv">$message</span><span class="o">-></span><span class="n">set_address</span><span class="p">(</span><span class="nv">$msg</span><span class="o">-></span><span class="n">get_reply_to</span><span class="p">());</span> + <span class="nv">$message</span><span class="o">-></span><span class="n">set_body</span><span class="p">(</span><span class="s">"Reply for "</span><span class="p">,</span> <span class="nv">$msg</span><span class="o">-></span><span class="n">get_body</span><span class="p">);</span> + <span class="nv">$self</span><span class="o">-></span><span class="nb">send</span><span class="p">(</span><span class="nv">$message</span><span class="p">);</span> + <span class="p">}</span> +<span class="p">}</span> + +<span class="k">sub </span><span class="nf">on_status</span> <span class="p">{</span> + <span class="k">my</span> <span class="p">(</span><span class="nv">$self</span><span class="p">)</span> <span class="o">=</span> <span class="nv">@_</span><span class="p">;</span> + <span class="k">my</span> <span class="nv">$messenger</span> <span class="o">=</span> <span class="nv">$self</span><span class="o">-></span><span class="p">{</span><span class="n">_messenger</span><span class="p">};</span> + <span class="k">my</span> <span class="nv">$status</span> <span class="o">=</span> <span class="nv">$_</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span> + + <span class="k">print</span> <span class="s">"Status: "</span><span class="p">,</span> <span class="nv">$status</span><span class="p">,</span> <span class="s">"\n"</span><span class="p">;</span> +<span class="p">}</span> + +<span class="k">sub </span><span class="nf">on_stop</span> <span class="p">{</span> + <span class="k">print</span> <span class="s">"Stopped.\n"</span> +<span class="p">}</span> + +<span class="nb">package</span> <span class="n">main</span><span class="p">;</span> + +<span class="k">our</span> <span class="nv">$messenger</span> <span class="o">=</span> <span class="k">new</span> <span class="nn">qpid::proton::</span><span class="n">Messenger</span><span class="p">();</span> +<span class="k">our</span> <span class="nv">$app</span> <span class="o">=</span> <span class="k">new</span> <span class="nn">async::</span><span class="n">Receiver</span><span class="p">(</span><span class="nv">$messenger</span><span class="p">);</span> + +<span class="nv">$app</span><span class="o">-></span><span class="n">run</span><span class="p">();</span> +</pre></div> + +<p><a href="recv_async.pl">Download this file</a></p> + + + <hr/> + + <ul id="-apache-navigation"> + <li><a href="http://www.apache.org/">Apache</a></li> + <li><a href="http://www.apache.org/licenses/">License</a></li> + <li><a href="http://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li> + <li><a href="http://www.apache.org/foundation/thanks.html">Thanks!</a></li> + <li><a href="/security.html">Security</a></li> + <li><a href="http://www.apache.org/"><img id="-apache-feather" width="48" height="14" src="" alt="Apache"/></a></li> + </ul> + + <p id="-legal"> + Apache Qpid, Messaging built on AMQP; Copyright © 2015 + The Apache Software Foundation; Licensed under + the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache + License, Version 2.0</a>; Apache Qpid, Qpid, Qpid Proton, + Proton, Apache, the Apache feather logo, and the Apache Qpid + project logo are trademarks of The Apache Software + Foundation; All other marks mentioned may be trademarks or + registered trademarks of their respective owners + </p> + </div> + </div> + </div> + </body> +</html> http://git-wip-us.apache.org/repos/asf/qpid-site/blob/1859e58c/content/releases/qpid-proton-0.17.0/messenger/perl/examples/send.pl ---------------------------------------------------------------------- diff --git a/content/releases/qpid-proton-0.17.0/messenger/perl/examples/send.pl b/content/releases/qpid-proton-0.17.0/messenger/perl/examples/send.pl new file mode 100755 index 0000000..27893ce --- /dev/null +++ b/content/releases/qpid-proton-0.17.0/messenger/perl/examples/send.pl @@ -0,0 +1,88 @@ +#!/usr/bin/env 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 Getopt::Std; + +use qpid_proton; + +$Getopt::Std::STANDARD_HELP_VERSION = 1; + +sub VERSION_MESSAGE() { +} + +sub HELP_MESSAGE() { + print "Usage: send.pl [OPTIONS] -a <ADDRESS>\n"; + print "Options:\n"; + print "\t-s - the message subject\n"; + print "\t-C - the message content\n"; + print "\t<ADDRESS> - amqp://<domain>[/<name>]\n"; + print "\t-h - this message\n"; + + exit; +} + +my %options = (); +getopts("a:C:s:h:", \%options) or HELP_MESSAGE(); + +my $address = $options{a} || "amqp://0.0.0.0"; +my $subject = $options{s} || localtime(time); +my $content = $options{C} || ""; + +my $msg = new qpid::proton::Message(); +my $messenger = new qpid::proton::Messenger(); + +$messenger->start(); + +my @messages = @ARGV; +@messages = ("This is a test. " . localtime(time)) unless $messages[0]; + +foreach (@messages) +{ + $msg->set_address($address); + $msg->set_subject($subject); + $msg->set_body($content); + # try a few different body types + my $body_type = int(rand(6)); + $msg->set_property("sent", "" . localtime(time)); + $msg->get_instructions->{"fold"} = "yes"; + $msg->get_instructions->{"spindle"} = "no"; + $msg->get_instructions->{"mutilate"} = "no"; + $msg->get_annotations->{"version"} = 1.0; + $msg->get_annotations->{"pill"} = "RED"; + + SWITCH: { + $body_type == 0 && do { $msg->set_body("It is now " . localtime(time));}; + $body_type == 1 && do { $msg->set_body(rand(65536)); }; + $body_type == 2 && do { $msg->set_body(int(rand(2)), qpid::proton::BOOL); }; + $body_type == 3 && do { $msg->set_body({"foo" => "bar"}); }; + $body_type == 4 && do { $msg->set_body([4, [1, 2, 3.1, 3.4E-5], 8, 15, 16, 23, 42]); }; + $body_type == 5 && do { $msg->set_body(int(rand(65535))); } + } + + $messenger->put($msg); + print "Sent: " . $msg->get_body . " [CONTENT TYPE: " . $msg->get_body_type . "]\n"; +} + +$messenger->send(); +$messenger->stop(); + +die $@ if ($@); http://git-wip-us.apache.org/repos/asf/qpid-site/blob/1859e58c/content/releases/qpid-proton-0.17.0/messenger/perl/examples/send.pl.html ---------------------------------------------------------------------- diff --git a/content/releases/qpid-proton-0.17.0/messenger/perl/examples/send.pl.html b/content/releases/qpid-proton-0.17.0/messenger/perl/examples/send.pl.html new file mode 100644 index 0000000..f6a8c42 --- /dev/null +++ b/content/releases/qpid-proton-0.17.0/messenger/perl/examples/send.pl.html @@ -0,0 +1,217 @@ +<!DOCTYPE html> +<!-- + - + - 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. + - +--> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> + <head> + <title>send.pl - Apache Qpid™</title> + <meta http-equiv="X-UA-Compatible" content="IE=edge"/> + <meta name="viewport" content="width=device-width, initial-scale=1.0"/> + <link rel="stylesheet" href="/site.css" type="text/css" async="async"/> + <link rel="stylesheet" href="/deferred.css" type="text/css" defer="defer"/> + <script type="text/javascript">var _deferredFunctions = [];</script> + <script type="text/javascript" src="/deferred.js" defer="defer"></script> + <!--[if lte IE 8]> + <link rel="stylesheet" href="/ie.css" type="text/css"/> + <script type="text/javascript" src="/html5shiv.js"></script> + <![endif]--> + + <!-- Redirects for `go get` and godoc.org --> + <meta name="go-import" + content="qpid.apache.org git https://git-wip-us.apache.org/repos/asf/qpid-proton.git"/> + <meta name="go-source" + content="qpid.apache.org +https://github.com/apache/qpid-proton/blob/go1/README.md +https://github.com/apache/qpid-proton/tree/go1{/dir} +https://github.com/apache/qpid-proton/blob/go1{/dir}/{file}#L{line}"/> + </head> + <body> + <div id="-content"> + <div id="-top" class="panel"> + <a id="-menu-link"><img width="16" height="16" src="" alt="Menu"/></a> + + <a id="-search-link"><img width="22" height="16" src="" alt="Search"/></a> + + <ul id="-global-navigation"> + <li><a id="-logotype" href="/index.html">Apache Qpid<sup>™</sup></a></li> + <li><a href="/documentation.html">Documentation</a></li> + <li><a href="/download.html">Download</a></li> + <li><a href="/discussion.html">Discussion</a></li> + </ul> + </div> + + <div id="-menu" class="panel" style="display: none;"> + <div class="flex"> + <section> + <h3>Project</h3> + + <ul> + <li><a href="/overview.html">Overview</a></li> + <li><a href="/components/index.html">Components</a></li> + <li><a href="/releases/index.html">Releases</a></li> + </ul> + </section> + + <section> + <h3>Messaging APIs</h3> + + <ul> + <li><a href="/proton/index.html">Qpid Proton</a></li> + <li><a href="/components/jms/index.html">Qpid JMS</a></li> + <li><a href="/components/messaging-api/index.html">Qpid Messaging API</a></li> + </ul> + </section> + + <section> + <h3>Servers and tools</h3> + + <ul> + <li><a href="/components/java-broker/index.html">Broker for Java</a></li> + <li><a href="/components/cpp-broker/index.html">C++ broker</a></li> + <li><a href="/components/dispatch-router/index.html">Dispatch router</a></li> + </ul> + </section> + + <section> + <h3>Resources</h3> + + <ul> + <li><a href="/dashboard.html">Dashboard</a></li> + <li><a href="https://cwiki.apache.org/confluence/display/qpid/Index">Wiki</a></li> + <li><a href="/resources.html">More resources</a></li> + </ul> + </section> + </div> + </div> + + <div id="-search" class="panel" style="display: none;"> + <form action="http://www.google.com/search" method="get"> + <input type="hidden" name="sitesearch" value="qpid.apache.org"/> + <input type="text" name="q" maxlength="255" autofocus="autofocus" tabindex="1"/> + <button type="submit">Search</button> + <a href="/search.html">More ways to search</a> + </form> + </div> + + <div id="-middle" class="panel"> + <ul id="-path-navigation"><li><a href="/index.html">Home</a></li><li><a href="/releases/index.html">Releases</a></li><li><a href="/releases/qpid-proton-0.17.0/index.html">Qpid Proton 0.17.0</a></li><li><a href="/releases/qpid-proton-0.17.0/messenger/perl/examples/index.html">Perl AMQP Messenger Examples</a></li><li>send.pl</li></ul> + + <div id="-middle-content"> + +<h1>send.pl</h1> +<div class="highlight"><pre><span class="k">use</span> <span class="n">strict</span><span class="p">;</span> +<span class="k">use</span> <span class="n">warnings</span><span class="p">;</span> +<span class="k">use</span> <span class="nn">Getopt::</span><span class="n">Std</span><span class="p">;</span> + +<span class="k">use</span> <span class="n">qpid_proton</span><span class="p">;</span> + +<span class="nv">$</span><span class="nn">Getopt::Std::</span><span class="nv">STANDARD_HELP_VERSION</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> + +<span class="k">sub </span><span class="nf">VERSION_MESSAGE</span><span class="p">()</span> <span class="p">{</span> +<span class="p">}</span> + +<span class="k">sub </span><span class="nf">HELP_MESSAGE</span><span class="p">()</span> <span class="p">{</span> + <span class="k">print</span> <span class="s">"Usage: send.pl [OPTIONS] -a <ADDRESS>\n"</span><span class="p">;</span> + <span class="k">print</span> <span class="s">"Options:\n"</span><span class="p">;</span> + <span class="k">print</span> <span class="s">"\t-s - the message subject\n"</span><span class="p">;</span> + <span class="k">print</span> <span class="s">"\t-C - the message content\n"</span><span class="p">;</span> + <span class="k">print</span> <span class="s">"\t<ADDRESS> - amqp://<domain>[/<name>]\n"</span><span class="p">;</span> + <span class="k">print</span> <span class="s">"\t-h - this message\n"</span><span class="p">;</span> + + <span class="nb">exit</span><span class="p">;</span> +<span class="p">}</span> + +<span class="k">my</span> <span class="nv">%options</span> <span class="o">=</span> <span class="p">();</span> +<span class="n">getopts</span><span class="p">(</span><span class="s">"a:C:s:h:"</span><span class="p">,</span> <span class="o">\</span><span class="nv">%options</span><span class="p">)</span> <span class="ow">or</span> <span class="n">HELP_MESSAGE</span><span class="p">();</span> + +<span class="k">my</span> <span class="nv">$address</span> <span class="o">=</span> <span class="nv">$options</span><span class="p">{</span><span class="n">a</span><span class="p">}</span> <span class="o">||</span> <span class="s">"amqp://0.0.0.0"</span><span class="p">;</span> +<span class="k">my</span> <span class="nv">$subject</span> <span class="o">=</span> <span class="nv">$options</span><span class="p">{</span><span class="n">s</span><span class="p">}</span> <span class="o">||</span> <span class="nb">localtime</span><span class="p">(</span><span class="nb">time</span><span class="p">);</span> +<span class="k">my</span> <span class="nv">$content</span> <span class="o">=</span> <span class="nv">$options</span><span class="p">{</span><span class="n">C</span><span class="p">}</span> <span class="o">||</span> <span class="s">""</span><span class="p">;</span> + +<span class="k">my</span> <span class="nv">$msg</span> <span class="o">=</span> <span class="k">new</span> <span class="nn">qpid::proton::</span><span class="n">Message</span><span class="p">();</span> +<span class="k">my</span> <span class="nv">$messenger</span> <span class="o">=</span> <span class="k">new</span> <span class="nn">qpid::proton::</span><span class="n">Messenger</span><span class="p">();</span> + +<span class="nv">$messenger</span><span class="o">-></span><span class="n">start</span><span class="p">();</span> + +<span class="k">my</span> <span class="nv">@messages</span> <span class="o">=</span> <span class="nv">@ARGV</span><span class="p">;</span> +<span class="nv">@messages</span> <span class="o">=</span> <span class="p">(</span><span class="s">"This is a test. "</span> <span class="o">.</span> <span class="nb">localtime</span><span class="p">(</span><span class="nb">time</span><span class="p">))</span> <span class="k">unless</span> <span class="nv">$messages</span><span class="p">[</span><span class="mi">0</span><span class="p">];</span> + +<span class="k">foreach</span> <span class="p">(</span><span class="nv">@messages</span><span class="p">)</span> +<span class="p">{</span> + <span class="nv">$msg</span><span class="o">-></span><span class="n">set_address</span><span class="p">(</span><span class="nv">$address</span><span class="p">);</span> + <span class="nv">$msg</span><span class="o">-></span><span class="n">set_subject</span><span class="p">(</span><span class="nv">$subject</span><span class="p">);</span> + <span class="nv">$msg</span><span class="o">-></span><span class="n">set_body</span><span class="p">(</span><span class="nv">$content</span><span class="p">);</span> + <span class="c1"># try a few different body types</span> + <span class="k">my</span> <span class="nv">$body_type</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="nb">rand</span><span class="p">(</span><span class="mi">6</span><span class="p">));</span> + <span class="nv">$msg</span><span class="o">-></span><span class="n">set_property</span><span class="p">(</span><span class="s">"sent"</span><span class="p">,</span> <span class="s">""</span> <span class="o">.</span> <span class="nb">localtime</span><span class="p">(</span><span class="nb">time</span><span class="p">));</span> + <span class="nv">$msg</span><span class="o">-></span><span class="n">get_instructions</span><span class="o">-></span><span class="p">{</span><span class="s">"fold"</span><span class="p">}</span> <span class="o">=</span> <span class="s">"yes"</span><span class="p">;</span> + <span class="nv">$msg</span><span class="o">-></span><span class="n">get_instructions</span><span class="o">-></span><span class="p">{</span><span class="s">"spindle"</span><span class="p">}</span> <span class="o">=</span> <span class="s">"no"</span><span class="p">;</span> + <span class="nv">$msg</span><span class="o">-></span><span class="n">get_instructions</span><span class="o">-></span><span class="p">{</span><span class="s">"mutilate"</span><span class="p">}</span> <span class="o">=</span> <span class="s">"no"</span><span class="p">;</span> + <span class="nv">$msg</span><span class="o">-></span><span class="n">get_annotations</span><span class="o">-></span><span class="p">{</span><span class="s">"version"</span><span class="p">}</span> <span class="o">=</span> <span class="mf">1.0</span><span class="p">;</span> + <span class="nv">$msg</span><span class="o">-></span><span class="n">get_annotations</span><span class="o">-></span><span class="p">{</span><span class="s">"pill"</span><span class="p">}</span> <span class="o">=</span> <span class="s">"RED"</span><span class="p">;</span> + + <span class="n">SWITCH:</span> <span class="p">{</span> + <span class="nv">$body_type</span> <span class="o">==</span> <span class="mi">0</span> <span class="o">&&</span> <span class="k">do</span> <span class="p">{</span> <span class="nv">$msg</span><span class="o">-></span><span class="n">set_body</span><span class="p">(</span><span class="s">"It is now "</span> <span class="o">.</span> <span class="nb">localtime</span><span class="p">(</span><span class="nb">time</span><span class="p">));};</span> + <span class="nv">$body_type</span> <span class="o">==</span> <span class="mi">1</span> <span class="o">&&</span> <span class="k">do</span> <span class="p">{</span> <span class="nv">$msg</span><span class="o">-></span><span class="n">set_body</span><span class="p">(</span><span class="nb">rand</span><span class="p">(</span><span class="mi">65536</span><span class="p">));</span> <span class="p">};</span> + <span class="nv">$body_type</span> <span class="o">==</span> <span class="mi">2</span> <span class="o">&&</span> <span class="k">do</span> <span class="p">{</span> <span class="nv">$msg</span><span class="o">-></span><span class="n">set_body</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="nb">rand</span><span class="p">(</span><span class="mi">2</span><span class="p">)),</span> <span class="nn">qpid::proton::</span><span class="n">BOOL</span><span class="p">);</span> <span class="p">};</span> + <span class="nv">$body_type</span> <span class="o">==</span> <span class="mi">3</span> <span class="o">&&</span> <span class="k">do</span> <span class="p">{</span> <span class="nv">$msg</span><span class="o">-></span><span class="n">set_body</span><span class="p">({</span><span class="s">"foo"</span> <span class="o">=></span> <span class="s">"bar"</span><span class="p">});</span> <span class="p">};</span> + <span class="nv">$body_type</span> <span class="o">==</span> <span class="mi">4</span> <span class="o">&&</span> <span class="k">do</span> <span class="p">{</span> <span class="nv">$msg</span><span class="o">-></span><span class="n">set_body</span><span class="p">([</span><span class="mi">4</span><span class="p">,</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mf">3.1</span><span class="p">,</span> <span class="mf">3.4E-5</span><span class="p">],</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">15</span><span class="p">,</span> <span class="mi">16</span><span class="p">,</span> <span class="mi">23</span><span class="p">,</span> <span class="mi">42</span><span class="p">]);</span> <span class="p">};</span> + <span class="nv">$body_type</span> <span class="o">==</span> <span class="mi">5</span> <span class="o">&&</span> <span class="k">do</span> <span class="p">{</span> <span class="nv">$msg</span><span class="o">-></span><span class="n">set_body</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="nb">rand</span><span class="p">(</span><span class="mi">65535</span><span class="p">)));</span> <span class="p">}</span> + <span class="p">}</span> + + <span class="nv">$messenger</span><span class="o">-></span><span class="n">put</span><span class="p">(</span><span class="nv">$msg</span><span class="p">);</span> + <span class="k">print</span> <span class="s">"Sent: "</span> <span class="o">.</span> <span class="nv">$msg</span><span class="o">-></span><span class="n">get_body</span> <span class="o">.</span> <span class="s">" [CONTENT TYPE: "</span> <span class="o">.</span> <span class="nv">$msg</span><span class="o">-></span><span class="n">get_body_type</span> <span class="o">.</span> <span class="s">"]\n"</span><span class="p">;</span> +<span class="p">}</span> + +<span class="nv">$messenger</span><span class="o">-></span><span class="nb">send</span><span class="p">();</span> +<span class="nv">$messenger</span><span class="o">-></span><span class="n">stop</span><span class="p">();</span> + +<span class="nb">die</span> <span class="vg">$@</span> <span class="k">if</span> <span class="p">(</span><span class="vg">$@</span><span class="p">);</span> +</pre></div> + +<p><a href="send.pl">Download this file</a></p> + + + <hr/> + + <ul id="-apache-navigation"> + <li><a href="http://www.apache.org/">Apache</a></li> + <li><a href="http://www.apache.org/licenses/">License</a></li> + <li><a href="http://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li> + <li><a href="http://www.apache.org/foundation/thanks.html">Thanks!</a></li> + <li><a href="/security.html">Security</a></li> + <li><a href="http://www.apache.org/"><img id="-apache-feather" width="48" height="14" src="" alt="Apache"/></a></li> + </ul> + + <p id="-legal"> + Apache Qpid, Messaging built on AMQP; Copyright © 2015 + The Apache Software Foundation; Licensed under + the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache + License, Version 2.0</a>; Apache Qpid, Qpid, Qpid Proton, + Proton, Apache, the Apache feather logo, and the Apache Qpid + project logo are trademarks of The Apache Software + Foundation; All other marks mentioned may be trademarks or + registered trademarks of their respective owners + </p> + </div> + </div> + </div> + </body> +</html> http://git-wip-us.apache.org/repos/asf/qpid-site/blob/1859e58c/content/releases/qpid-proton-0.17.0/messenger/perl/examples/send_async.pl ---------------------------------------------------------------------- diff --git a/content/releases/qpid-proton-0.17.0/messenger/perl/examples/send_async.pl b/content/releases/qpid-proton-0.17.0/messenger/perl/examples/send_async.pl new file mode 100755 index 0000000..2f9408a --- /dev/null +++ b/content/releases/qpid-proton-0.17.0/messenger/perl/examples/send_async.pl @@ -0,0 +1,97 @@ +# +# 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 Getopt::Std; +use qpid_proton; +use async; + +$Getopt::Std::STANDARD_HELP_VERSION = 1; + +sub VERSION_MESSAGE() {} + +sub HELP_MESSAGE() { + print "Usage: send_async.pl [OPTIONS] <msg_0> <msg_1> ...\n"; + print "Options:\n"; + print "\t-a - the message address (def. amqp://0.0.0.0)\n"; + print "\t-r - the reply-to address: //<domain>[/<name>]\n"; + print "\t msg_# - a text string to send\n"; +} + +my %optons = (); +getopts("a:r:", \%options) or usage(); + +our $address = $options{a} || "amqp://0.0.0.0"; +our $replyto = $options{r} || "~/#"; + +package async::Sender; + +@ISA = (async::CallbackAdapter); + +sub on_start { + my ($self) = @_; + my $message = $self->{_message}; + my $messenger = $self->{_messenger}; + my $args = $_[1] || ("Hello world!"); + + print "Started\n"; + + $message->clear; + $message->set_address("amqp://0.0.0.0"); + $message->set_reply_to($replyto) if (defined($replyto)); + + foreach $arg ($args) { + $message->set_body($arg); + if ($replyto) { + $message->set_reply_to($replyto); + } + $self->send($message, "on_status"); + } + + $messenger->receive() if (defined($replyto)); +} + +sub on_status { + my ($self) = @_; + my $messenger = $self->{_messenger}; + my $status = $_[1] || ""; + + print "Status: ", $status, "\n"; +} + +sub on_receive { + my ($self) = @_; + my $message = $_[1]; + my $text = $message->get_body || "[empty]"; + + print "Received: " . $text . "\n"; + + $self->stop(); +} + +sub on_stop { + print "Stopped\n"; +} + + +package main; + +our $msgr = new qpid::proton::Messenger(); +our $app = async::Sender->new($msgr); + +$app->run; http://git-wip-us.apache.org/repos/asf/qpid-site/blob/1859e58c/content/releases/qpid-proton-0.17.0/messenger/perl/examples/send_async.pl.html ---------------------------------------------------------------------- diff --git a/content/releases/qpid-proton-0.17.0/messenger/perl/examples/send_async.pl.html b/content/releases/qpid-proton-0.17.0/messenger/perl/examples/send_async.pl.html new file mode 100644 index 0000000..fe312c8 --- /dev/null +++ b/content/releases/qpid-proton-0.17.0/messenger/perl/examples/send_async.pl.html @@ -0,0 +1,227 @@ +<!DOCTYPE html> +<!-- + - + - 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. + - +--> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> + <head> + <title>send_async.pl - Apache Qpid™</title> + <meta http-equiv="X-UA-Compatible" content="IE=edge"/> + <meta name="viewport" content="width=device-width, initial-scale=1.0"/> + <link rel="stylesheet" href="/site.css" type="text/css" async="async"/> + <link rel="stylesheet" href="/deferred.css" type="text/css" defer="defer"/> + <script type="text/javascript">var _deferredFunctions = [];</script> + <script type="text/javascript" src="/deferred.js" defer="defer"></script> + <!--[if lte IE 8]> + <link rel="stylesheet" href="/ie.css" type="text/css"/> + <script type="text/javascript" src="/html5shiv.js"></script> + <![endif]--> + + <!-- Redirects for `go get` and godoc.org --> + <meta name="go-import" + content="qpid.apache.org git https://git-wip-us.apache.org/repos/asf/qpid-proton.git"/> + <meta name="go-source" + content="qpid.apache.org +https://github.com/apache/qpid-proton/blob/go1/README.md +https://github.com/apache/qpid-proton/tree/go1{/dir} +https://github.com/apache/qpid-proton/blob/go1{/dir}/{file}#L{line}"/> + </head> + <body> + <div id="-content"> + <div id="-top" class="panel"> + <a id="-menu-link"><img width="16" height="16" src="" alt="Menu"/></a> + + <a id="-search-link"><img width="22" height="16" src="" alt="Search"/></a> + + <ul id="-global-navigation"> + <li><a id="-logotype" href="/index.html">Apache Qpid<sup>™</sup></a></li> + <li><a href="/documentation.html">Documentation</a></li> + <li><a href="/download.html">Download</a></li> + <li><a href="/discussion.html">Discussion</a></li> + </ul> + </div> + + <div id="-menu" class="panel" style="display: none;"> + <div class="flex"> + <section> + <h3>Project</h3> + + <ul> + <li><a href="/overview.html">Overview</a></li> + <li><a href="/components/index.html">Components</a></li> + <li><a href="/releases/index.html">Releases</a></li> + </ul> + </section> + + <section> + <h3>Messaging APIs</h3> + + <ul> + <li><a href="/proton/index.html">Qpid Proton</a></li> + <li><a href="/components/jms/index.html">Qpid JMS</a></li> + <li><a href="/components/messaging-api/index.html">Qpid Messaging API</a></li> + </ul> + </section> + + <section> + <h3>Servers and tools</h3> + + <ul> + <li><a href="/components/java-broker/index.html">Broker for Java</a></li> + <li><a href="/components/cpp-broker/index.html">C++ broker</a></li> + <li><a href="/components/dispatch-router/index.html">Dispatch router</a></li> + </ul> + </section> + + <section> + <h3>Resources</h3> + + <ul> + <li><a href="/dashboard.html">Dashboard</a></li> + <li><a href="https://cwiki.apache.org/confluence/display/qpid/Index">Wiki</a></li> + <li><a href="/resources.html">More resources</a></li> + </ul> + </section> + </div> + </div> + + <div id="-search" class="panel" style="display: none;"> + <form action="http://www.google.com/search" method="get"> + <input type="hidden" name="sitesearch" value="qpid.apache.org"/> + <input type="text" name="q" maxlength="255" autofocus="autofocus" tabindex="1"/> + <button type="submit">Search</button> + <a href="/search.html">More ways to search</a> + </form> + </div> + + <div id="-middle" class="panel"> + <ul id="-path-navigation"><li><a href="/index.html">Home</a></li><li><a href="/releases/index.html">Releases</a></li><li><a href="/releases/qpid-proton-0.17.0/index.html">Qpid Proton 0.17.0</a></li><li><a href="/releases/qpid-proton-0.17.0/messenger/perl/examples/index.html">Perl AMQP Messenger Examples</a></li><li>send_async.pl</li></ul> + + <div id="-middle-content"> + +<h1>send_async.pl</h1> +<div class="highlight"><pre><span class="k">use</span> <span class="nn">Getopt::</span><span class="n">Std</span><span class="p">;</span> +<span class="k">use</span> <span class="n">qpid_proton</span><span class="p">;</span> +<span class="k">use</span> <span class="n">async</span><span class="p">;</span> + +<span class="nv">$</span><span class="nn">Getopt::Std::</span><span class="nv">STANDARD_HELP_VERSION</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> + +<span class="k">sub </span><span class="nf">VERSION_MESSAGE</span><span class="p">()</span> <span class="p">{}</span> + +<span class="k">sub </span><span class="nf">HELP_MESSAGE</span><span class="p">()</span> <span class="p">{</span> + <span class="k">print</span> <span class="s">"Usage: send_async.pl [OPTIONS] <msg_0> <msg_1> ...\n"</span><span class="p">;</span> + <span class="k">print</span> <span class="s">"Options:\n"</span><span class="p">;</span> + <span class="k">print</span> <span class="s">"\t-a - the message address (def. amqp://0.0.0.0)\n"</span><span class="p">;</span> + <span class="k">print</span> <span class="s">"\t-r - the reply-to address: //<domain>[/<name>]\n"</span><span class="p">;</span> + <span class="k">print</span> <span class="s">"\t msg_# - a text string to send\n"</span><span class="p">;</span> +<span class="p">}</span> + +<span class="k">my</span> <span class="nv">%optons</span> <span class="o">=</span> <span class="p">();</span> +<span class="n">getopts</span><span class="p">(</span><span class="s">"a:r:"</span><span class="p">,</span> <span class="o">\</span><span class="nv">%options</span><span class="p">)</span> <span class="ow">or</span> <span class="n">usage</span><span class="p">();</span> + +<span class="k">our</span> <span class="nv">$address</span> <span class="o">=</span> <span class="nv">$options</span><span class="p">{</span><span class="n">a</span><span class="p">}</span> <span class="o">||</span> <span class="s">"amqp://0.0.0.0"</span><span class="p">;</span> +<span class="k">our</span> <span class="nv">$replyto</span> <span class="o">=</span> <span class="nv">$options</span><span class="p">{</span><span class="n">r</span><span class="p">}</span> <span class="o">||</span> <span class="s">"~/#"</span><span class="p">;</span> + +<span class="nb">package</span> <span class="nn">async::</span><span class="n">Sender</span><span class="p">;</span> + +<span class="nv">@ISA</span> <span class="o">=</span> <span class="p">(</span><span class="nn">async::</span><span class="n">CallbackAdapter</span><span class="p">);</span> + +<span class="k">sub </span><span class="nf">on_start</span> <span class="p">{</span> + <span class="k">my</span> <span class="p">(</span><span class="nv">$self</span><span class="p">)</span> <span class="o">=</span> <span class="nv">@_</span><span class="p">;</span> + <span class="k">my</span> <span class="nv">$message</span> <span class="o">=</span> <span class="nv">$self</span><span class="o">-></span><span class="p">{</span><span class="n">_message</span><span class="p">};</span> + <span class="k">my</span> <span class="nv">$messenger</span> <span class="o">=</span> <span class="nv">$self</span><span class="o">-></span><span class="p">{</span><span class="n">_messenger</span><span class="p">};</span> + <span class="k">my</span> <span class="nv">$args</span> <span class="o">=</span> <span class="nv">$_</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">||</span> <span class="p">(</span><span class="s">"Hello world!"</span><span class="p">);</span> + + <span class="k">print</span> <span class="s">"Started\n"</span><span class="p">;</span> + + <span class="nv">$message</span><span class="o">-></span><span class="n">clear</span><span class="p">;</span> + <span class="nv">$message</span><span class="o">-></span><span class="n">set_address</span><span class="p">(</span><span class="s">"amqp://0.0.0.0"</span><span class="p">);</span> + <span class="nv">$message</span><span class="o">-></span><span class="n">set_reply_to</span><span class="p">(</span><span class="nv">$replyto</span><span class="p">)</span> <span class="k">if</span> <span class="p">(</span><span class="nb">defined</span><span class="p">(</span><span class="nv">$replyto</span><span class="p">));</span> + + <span class="k">foreach</span> <span class="nv">$arg</span> <span class="p">(</span><span class="nv">$args</span><span class="p">)</span> <span class="p">{</span> + <span class="nv">$message</span><span class="o">-></span><span class="n">set_body</span><span class="p">(</span><span class="nv">$arg</span><span class="p">);</span> + <span class="k">if</span> <span class="p">(</span><span class="nv">$replyto</span><span class="p">)</span> <span class="p">{</span> + <span class="nv">$message</span><span class="o">-></span><span class="n">set_reply_to</span><span class="p">(</span><span class="nv">$replyto</span><span class="p">);</span> + <span class="p">}</span> + <span class="nv">$self</span><span class="o">-></span><span class="nb">send</span><span class="p">(</span><span class="nv">$message</span><span class="p">,</span> <span class="s">"on_status"</span><span class="p">);</span> + <span class="p">}</span> + + <span class="nv">$messenger</span><span class="o">-></span><span class="n">receive</span><span class="p">()</span> <span class="k">if</span> <span class="p">(</span><span class="nb">defined</span><span class="p">(</span><span class="nv">$replyto</span><span class="p">));</span> +<span class="p">}</span> + +<span class="k">sub </span><span class="nf">on_status</span> <span class="p">{</span> + <span class="k">my</span> <span class="p">(</span><span class="nv">$self</span><span class="p">)</span> <span class="o">=</span> <span class="nv">@_</span><span class="p">;</span> + <span class="k">my</span> <span class="nv">$messenger</span> <span class="o">=</span> <span class="nv">$self</span><span class="o">-></span><span class="p">{</span><span class="n">_messenger</span><span class="p">};</span> + <span class="k">my</span> <span class="nv">$status</span> <span class="o">=</span> <span class="nv">$_</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">||</span> <span class="s">""</span><span class="p">;</span> + + <span class="k">print</span> <span class="s">"Status: "</span><span class="p">,</span> <span class="nv">$status</span><span class="p">,</span> <span class="s">"\n"</span><span class="p">;</span> +<span class="p">}</span> + +<span class="k">sub </span><span class="nf">on_receive</span> <span class="p">{</span> + <span class="k">my</span> <span class="p">(</span><span class="nv">$self</span><span class="p">)</span> <span class="o">=</span> <span class="nv">@_</span><span class="p">;</span> + <span class="k">my</span> <span class="nv">$message</span> <span class="o">=</span> <span class="nv">$_</span><span class="p">[</span><span class="mi">1</span><span class="p">];</span> + <span class="k">my</span> <span class="nv">$text</span> <span class="o">=</span> <span class="nv">$message</span><span class="o">-></span><span class="n">get_body</span> <span class="o">||</span> <span class="s">"[empty]"</span><span class="p">;</span> + + <span class="k">print</span> <span class="s">"Received: "</span> <span class="o">.</span> <span class="nv">$text</span> <span class="o">.</span> <span class="s">"\n"</span><span class="p">;</span> + + <span class="nv">$self</span><span class="o">-></span><span class="n">stop</span><span class="p">();</span> +<span class="p">}</span> + +<span class="k">sub </span><span class="nf">on_stop</span> <span class="p">{</span> + <span class="k">print</span> <span class="s">"Stopped\n"</span><span class="p">;</span> +<span class="p">}</span> + + +<span class="nb">package</span> <span class="n">main</span><span class="p">;</span> + +<span class="k">our</span> <span class="nv">$msgr</span> <span class="o">=</span> <span class="k">new</span> <span class="nn">qpid::proton::</span><span class="n">Messenger</span><span class="p">();</span> +<span class="k">our</span> <span class="nv">$app</span> <span class="o">=</span> <span class="nn">async::</span><span class="n">Sender</span><span class="o">-></span><span class="k">new</span><span class="p">(</span><span class="nv">$msgr</span><span class="p">);</span> + +<span class="nv">$app</span><span class="o">-></span><span class="n">run</span><span class="p">;</span> +</pre></div> + +<p><a href="send_async.pl">Download this file</a></p> + + + <hr/> + + <ul id="-apache-navigation"> + <li><a href="http://www.apache.org/">Apache</a></li> + <li><a href="http://www.apache.org/licenses/">License</a></li> + <li><a href="http://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li> + <li><a href="http://www.apache.org/foundation/thanks.html">Thanks!</a></li> + <li><a href="/security.html">Security</a></li> + <li><a href="http://www.apache.org/"><img id="-apache-feather" width="48" height="14" src="" alt="Apache"/></a></li> + </ul> + + <p id="-legal"> + Apache Qpid, Messaging built on AMQP; Copyright © 2015 + The Apache Software Foundation; Licensed under + the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache + License, Version 2.0</a>; Apache Qpid, Qpid, Qpid Proton, + Proton, Apache, the Apache feather logo, and the Apache Qpid + project logo are trademarks of The Apache Software + Foundation; All other marks mentioned may be trademarks or + registered trademarks of their respective owners + </p> + </div> + </div> + </div> + </body> +</html> http://git-wip-us.apache.org/repos/asf/qpid-site/blob/1859e58c/content/releases/qpid-proton-0.17.0/messenger/perl/examples/server.pl ---------------------------------------------------------------------- diff --git a/content/releases/qpid-proton-0.17.0/messenger/perl/examples/server.pl b/content/releases/qpid-proton-0.17.0/messenger/perl/examples/server.pl new file mode 100755 index 0000000..c13d4d5 --- /dev/null +++ b/content/releases/qpid-proton-0.17.0/messenger/perl/examples/server.pl @@ -0,0 +1,123 @@ +#!/usr/bin/env 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 Getopt::Long; +use Pod::Usage; + +use qpid_proton; + +my $help = 0; +my $man = 0; + +GetOptions( + man => \$man, + "help|?" => \$help + ) or pod2usage(2); + +pod2usage(1) if $help; +pod2usage(-exitval => 0, -verbose => 2) if $man; + +pod2usage(2) unless scalar(@ARGV); + +# create a messenger for receiving and holding +# incoming messages +our $messenger = new qpid::proton::Messenger; +$messenger->start; + +# subscribe the messenger to all addresses specified sources +foreach (@ARGV) { + $messenger->subscribe($_); +} + +sub dispatch { + my $request = $_[0]; + my $reply = $_[1]; + + if ($request->get_subject) { + $reply->set_subject("Re: " . $request->get_subject); + } + + $reply->set_properties($request->get_properties); + print "Dispatched " . $request->get_subject . "\n"; + my $properties = $request->get_properties; + foreach (keys %{$properties}) { + my $value = $properties->{%_}; + print "\t$_: $value\n"; + } +} + +our $message = new qpid::proton::Message; +our $reply = new qpid::proton::Message; + +while(1) { + $messenger->receive(1) if $messenger->incoming < 10; + + if ($messenger->incoming > 0) { + $messenger->get($message); + + if ($message->get_reply_to) { + print $message->get_reply_to . "\n"; + $reply->set_address($message->get_reply_to); + $reply->set_correlation_id($message->get_correlation_id); + $reply->set_body($message->get_body); + } + dispatch($message, $reply); + $messenger->put($reply); + $messenger->send; + } +} + +$message->stop; + +__END__ + +=head1 NAME + +server - Proton example server application for Perl. + +=head1 SYNOPSIS + +server.pl [OPTIONS] <addr1> ... <addrn> + + Options: + --help - This help message. + --man - Show the full documentation. + +=over 8 + +=item B<--help> + +Prints a brief help message and exits. + +=item B<--man> + +Prints the man page and exits. + +=back + +=head2 ADDRESS + +The form an address takes is: + +[amqp://]<domain>[/name] + +=cut --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
