http://git-wip-us.apache.org/repos/asf/qpid-site/blob/7833dc2a/content/releases/qpid-proton-0.16.0/messenger/python/examples/recv.py.html ---------------------------------------------------------------------- diff --git a/content/releases/qpid-proton-0.16.0/messenger/python/examples/recv.py.html b/content/releases/qpid-proton-0.16.0/messenger/python/examples/recv.py.html new file mode 100644 index 0000000..19544c3 --- /dev/null +++ b/content/releases/qpid-proton-0.16.0/messenger/python/examples/recv.py.html @@ -0,0 +1,185 @@ +<!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.py - 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.16.0/index.html">Qpid Proton 0.16.0</a></li><li><a href="/releases/qpid-proton-0.16.0/messenger/python/examples/index.html">Python AMQP Messenger Examples</a></li><li>recv.py</li></ul> + + <div id="-middle-content"> + +<h1>recv.py</h1> +<div class="highlight"><pre><span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">print_function</span> +<span class="kn">import</span> <span class="nn">sys</span><span class="o">,</span> <span class="nn">optparse</span> +<span class="kn">from</span> <span class="nn">proton</span> <span class="kn">import</span> <span class="o">*</span> + +<span class="n">parser</span> <span class="o">=</span> <span class="n">optparse</span><span class="o">.</span><span class="n">OptionParser</span><span class="p">(</span><span class="n">usage</span><span class="o">=</span><span class="s">"usage: %prog [options] <addr_1> ... <addr_n>"</span><span class="p">,</span> + <span class="n">description</span><span class="o">=</span><span class="s">"simple message receiver"</span><span class="p">)</span> +<span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">"-c"</span><span class="p">,</span> <span class="s">"--certificate"</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s">"path to certificate file"</span><span class="p">)</span> +<span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">"-k"</span><span class="p">,</span> <span class="s">"--private-key"</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s">"path to private key file"</span><span class="p">)</span> +<span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">"-p"</span><span class="p">,</span> <span class="s">"--password"</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s">"password for private key file"</span><span class="p">)</span> + +<span class="n">opts</span><span class="p">,</span> <span class="n">args</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">()</span> + +<span class="k">if</span> <span class="ow">not</span> <span class="n">args</span><span class="p">:</span> + <span class="n">args</span> <span class="o">=</span> <span class="p">[</span><span class="s">"amqp://~0.0.0.0"</span><span class="p">]</span> + +<span class="n">mng</span> <span class="o">=</span> <span class="n">Messenger</span><span class="p">()</span> +<span class="n">mng</span><span class="o">.</span><span class="n">certificate</span><span class="o">=</span><span class="n">opts</span><span class="o">.</span><span class="n">certificate</span> +<span class="n">mng</span><span class="o">.</span><span class="n">private_key</span><span class="o">=</span><span class="n">opts</span><span class="o">.</span><span class="n">private_key</span> +<span class="n">mng</span><span class="o">.</span><span class="n">password</span><span class="o">=</span><span class="n">opts</span><span class="o">.</span><span class="n">password</span> +<span class="n">mng</span><span class="o">.</span><span class="n">start</span><span class="p">()</span> + +<span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="n">args</span><span class="p">:</span> + <span class="n">mng</span><span class="o">.</span><span class="n">subscribe</span><span class="p">(</span><span class="n">a</span><span class="p">)</span> + +<span class="n">msg</span> <span class="o">=</span> <span class="n">Message</span><span class="p">()</span> +<span class="k">while</span> <span class="bp">True</span><span class="p">:</span> + <span class="n">mng</span><span class="o">.</span><span class="n">recv</span><span class="p">()</span> + <span class="k">while</span> <span class="n">mng</span><span class="o">.</span><span class="n">incoming</span><span class="p">:</span> + <span class="k">try</span><span class="p">:</span> + <span class="n">mng</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span> + <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span> + <span class="k">print</span><span class="p">(</span><span class="n">e</span><span class="p">)</span> + <span class="k">else</span><span class="p">:</span> + <span class="k">print</span><span class="p">(</span><span class="n">msg</span><span class="o">.</span><span class="n">address</span><span class="p">,</span> <span class="n">msg</span><span class="o">.</span><span class="n">subject</span> <span class="ow">or</span> <span class="s">"(no subject)"</span><span class="p">,</span> <span class="n">msg</span><span class="o">.</span><span class="n">properties</span><span class="p">,</span> <span class="n">msg</span><span class="o">.</span><span class="n">body</span><span class="p">)</span> + +<span class="n">mng</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span> +</pre></div> + +<p><a href="recv.py">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/7833dc2a/content/releases/qpid-proton-0.16.0/messenger/python/examples/recv_async.py ---------------------------------------------------------------------- diff --git a/content/releases/qpid-proton-0.16.0/messenger/python/examples/recv_async.py b/content/releases/qpid-proton-0.16.0/messenger/python/examples/recv_async.py new file mode 100755 index 0000000..b38c31a --- /dev/null +++ b/content/releases/qpid-proton-0.16.0/messenger/python/examples/recv_async.py @@ -0,0 +1,56 @@ +#!/usr/bin/python +# +# 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. +# +from __future__ import print_function +import sys, optparse +from async import * + +parser = optparse.OptionParser(usage="usage: %prog [options] <addr_1> ... <addr_n>", + description="simple message receiver") + +opts, args = parser.parse_args() + +if not args: + args = ["amqp://~0.0.0.0"] + +class App(CallbackAdapter): + + def on_start(self): + print("Started") + for a in args: + print("Subscribing to:", a) + self.messenger.subscribe(a) + self.messenger.recv() + + def on_recv(self, msg): + print("Received:", msg) + if msg.body == "die": + self.stop() + if msg.reply_to: + self.message.clear() + self.message.address = msg.reply_to + self.message.body = "Reply for: %s" % msg.body + print("Replied:", self.message) + self.send(self.message) + + def on_stop(self): + print("Stopped") + +a = App(Messenger()) +a.run() http://git-wip-us.apache.org/repos/asf/qpid-site/blob/7833dc2a/content/releases/qpid-proton-0.16.0/messenger/python/examples/recv_async.py.html ---------------------------------------------------------------------- diff --git a/content/releases/qpid-proton-0.16.0/messenger/python/examples/recv_async.py.html b/content/releases/qpid-proton-0.16.0/messenger/python/examples/recv_async.py.html new file mode 100644 index 0000000..7735022 --- /dev/null +++ b/content/releases/qpid-proton-0.16.0/messenger/python/examples/recv_async.py.html @@ -0,0 +1,186 @@ +<!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.py - 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.16.0/index.html">Qpid Proton 0.16.0</a></li><li><a href="/releases/qpid-proton-0.16.0/messenger/python/examples/index.html">Python AMQP Messenger Examples</a></li><li>recv_async.py</li></ul> + + <div id="-middle-content"> + +<h1>recv_async.py</h1> +<div class="highlight"><pre><span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">print_function</span> +<span class="kn">import</span> <span class="nn">sys</span><span class="o">,</span> <span class="nn">optparse</span> +<span class="kn">from</span> <span class="nn">async</span> <span class="kn">import</span> <span class="o">*</span> + +<span class="n">parser</span> <span class="o">=</span> <span class="n">optparse</span><span class="o">.</span><span class="n">OptionParser</span><span class="p">(</span><span class="n">usage</span><span class="o">=</span><span class="s">"usage: %prog [options] <addr_1> ... <addr_n>"</span><span class="p">,</span> + <span class="n">description</span><span class="o">=</span><span class="s">"simple message receiver"</span><span class="p">)</span> + +<span class="n">opts</span><span class="p">,</span> <span class="n">args</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">()</span> + +<span class="k">if</span> <span class="ow">not</span> <span class="n">args</span><span class="p">:</span> + <span class="n">args</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">class</span> <span class="nc">App</span><span class="p">(</span><span class="n">CallbackAdapter</span><span class="p">):</span> + + <span class="k">def</span> <span class="nf">on_start</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> + <span class="k">print</span><span class="p">(</span><span class="s">"Started"</span><span class="p">)</span> + <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="n">args</span><span class="p">:</span> + <span class="k">print</span><span class="p">(</span><span class="s">"Subscribing to:"</span><span class="p">,</span> <span class="n">a</span><span class="p">)</span> + <span class="bp">self</span><span class="o">.</span><span class="n">messenger</span><span class="o">.</span><span class="n">subscribe</span><span class="p">(</span><span class="n">a</span><span class="p">)</span> + <span class="bp">self</span><span class="o">.</span><span class="n">messenger</span><span class="o">.</span><span class="n">recv</span><span class="p">()</span> + + <span class="k">def</span> <span class="nf">on_recv</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">msg</span><span class="p">):</span> + <span class="k">print</span><span class="p">(</span><span class="s">"Received:"</span><span class="p">,</span> <span class="n">msg</span><span class="p">)</span> + <span class="k">if</span> <span class="n">msg</span><span class="o">.</span><span class="n">body</span> <span class="o">==</span> <span class="s">"die"</span><span class="p">:</span> + <span class="bp">self</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span> + <span class="k">if</span> <span class="n">msg</span><span class="o">.</span><span class="n">reply_to</span><span class="p">:</span> + <span class="bp">self</span><span class="o">.</span><span class="n">message</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span> + <span class="bp">self</span><span class="o">.</span><span class="n">message</span><span class="o">.</span><span class="n">address</span> <span class="o">=</span> <span class="n">msg</span><span class="o">.</span><span class="n">reply_to</span> + <span class="bp">self</span><span class="o">.</span><span class="n">message</span><span class="o">.</span><span class="n">body</span> <span class="o">=</span> <span class="s">"Reply for: </span><span class="si">%s</span><span class="s">"</span> <span class="o">%</span> <span class="n">msg</span><span class="o">.</span><span class="n">body</span> + <span class="k">print</span><span class="p">(</span><span class="s">"Replied:"</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">message</span><span class="p">)</span> + <span class="bp">self</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">message</span><span class="p">)</span> + + <span class="k">def</span> <span class="nf">on_stop</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> + <span class="k">print</span><span class="p">(</span><span class="s">"Stopped"</span><span class="p">)</span> + +<span class="n">a</span> <span class="o">=</span> <span class="n">App</span><span class="p">(</span><span class="n">Messenger</span><span class="p">())</span> +<span class="n">a</span><span class="o">.</span><span class="n">run</span><span class="p">()</span> +</pre></div> + +<p><a href="recv_async.py">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/7833dc2a/content/releases/qpid-proton-0.16.0/messenger/python/examples/send.py ---------------------------------------------------------------------- diff --git a/content/releases/qpid-proton-0.16.0/messenger/python/examples/send.py b/content/releases/qpid-proton-0.16.0/messenger/python/examples/send.py new file mode 100755 index 0000000..c274656 --- /dev/null +++ b/content/releases/qpid-proton-0.16.0/messenger/python/examples/send.py @@ -0,0 +1,45 @@ +#!/usr/bin/python +# +# 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. +# +from __future__ import print_function +import sys, optparse +from proton import * + +parser = optparse.OptionParser(usage="usage: %prog [options] <msg_1> ... <msg_n>", + description="simple message sender") +parser.add_option("-a", "--address", default="amqp://0.0.0.0", + help="address: //<domain>[/<name>] (default %default)") + +opts, args = parser.parse_args() +if not args: + args = ["Hello World!"] + +mng = Messenger() +mng.start() + +msg = Message() +for m in args: + msg.address = opts.address + msg.body = str(m) + mng.put(msg) + +mng.send() +print("sent:", ", ".join(args)) + +mng.stop() http://git-wip-us.apache.org/repos/asf/qpid-site/blob/7833dc2a/content/releases/qpid-proton-0.16.0/messenger/python/examples/send.py.html ---------------------------------------------------------------------- diff --git a/content/releases/qpid-proton-0.16.0/messenger/python/examples/send.py.html b/content/releases/qpid-proton-0.16.0/messenger/python/examples/send.py.html new file mode 100644 index 0000000..62b8298 --- /dev/null +++ b/content/releases/qpid-proton-0.16.0/messenger/python/examples/send.py.html @@ -0,0 +1,175 @@ +<!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.py - 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.16.0/index.html">Qpid Proton 0.16.0</a></li><li><a href="/releases/qpid-proton-0.16.0/messenger/python/examples/index.html">Python AMQP Messenger Examples</a></li><li>send.py</li></ul> + + <div id="-middle-content"> + +<h1>send.py</h1> +<div class="highlight"><pre><span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">print_function</span> +<span class="kn">import</span> <span class="nn">sys</span><span class="o">,</span> <span class="nn">optparse</span> +<span class="kn">from</span> <span class="nn">proton</span> <span class="kn">import</span> <span class="o">*</span> + +<span class="n">parser</span> <span class="o">=</span> <span class="n">optparse</span><span class="o">.</span><span class="n">OptionParser</span><span class="p">(</span><span class="n">usage</span><span class="o">=</span><span class="s">"usage: %prog [options] <msg_1> ... <msg_n>"</span><span class="p">,</span> + <span class="n">description</span><span class="o">=</span><span class="s">"simple message sender"</span><span class="p">)</span> +<span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">"-a"</span><span class="p">,</span> <span class="s">"--address"</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s">"amqp://0.0.0.0"</span><span class="p">,</span> + <span class="n">help</span><span class="o">=</span><span class="s">"address: //<domain>[/<name>] (default </span><span class="si">%d</span><span class="s">efault)"</span><span class="p">)</span> + +<span class="n">opts</span><span class="p">,</span> <span class="n">args</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">()</span> +<span class="k">if</span> <span class="ow">not</span> <span class="n">args</span><span class="p">:</span> + <span class="n">args</span> <span class="o">=</span> <span class="p">[</span><span class="s">"Hello World!"</span><span class="p">]</span> + +<span class="n">mng</span> <span class="o">=</span> <span class="n">Messenger</span><span class="p">()</span> +<span class="n">mng</span><span class="o">.</span><span class="n">start</span><span class="p">()</span> + +<span class="n">msg</span> <span class="o">=</span> <span class="n">Message</span><span class="p">()</span> +<span class="k">for</span> <span class="n">m</span> <span class="ow">in</span> <span class="n">args</span><span class="p">:</span> + <span class="n">msg</span><span class="o">.</span><span class="n">address</span> <span class="o">=</span> <span class="n">opts</span><span class="o">.</span><span class="n">address</span> + <span class="n">msg</span><span class="o">.</span><span class="n">body</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">m</span><span class="p">)</span> + <span class="n">mng</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span> + +<span class="n">mng</span><span class="o">.</span><span class="n">send</span><span class="p">()</span> +<span class="k">print</span><span class="p">(</span><span class="s">"sent:"</span><span class="p">,</span> <span class="s">", "</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">args</span><span class="p">))</span> + +<span class="n">mng</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span> +</pre></div> + +<p><a href="send.py">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/7833dc2a/content/releases/qpid-proton-0.16.0/messenger/python/examples/send_async.py ---------------------------------------------------------------------- diff --git a/content/releases/qpid-proton-0.16.0/messenger/python/examples/send_async.py b/content/releases/qpid-proton-0.16.0/messenger/python/examples/send_async.py new file mode 100755 index 0000000..50f7a68 --- /dev/null +++ b/content/releases/qpid-proton-0.16.0/messenger/python/examples/send_async.py @@ -0,0 +1,64 @@ +#!/usr/bin/python +# +# 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. +# +from __future__ import print_function +import sys, optparse +from async import * + +parser = optparse.OptionParser(usage="usage: %prog [options] <msg_1> ... <msg_n>", + description="simple message sender") +parser.add_option("-a", "--address", default="amqp://0.0.0.0", + help="address: //<domain>[/<name>] (default %default)") +parser.add_option("-r", "--reply_to", help="reply_to: //<domain>[/<name>]") + +opts, args = parser.parse_args() +if not args: + args = ["Hello World!"] + +class App(CallbackAdapter): + + def on_start(self): + print("Started") + self.message.clear() + self.message.address = opts.address + self.message.reply_to = opts.reply_to + for a in args: + self.message.body = a + self.send(self.message, self.on_status) + + if opts.reply_to: + self.messenger.recv() + + def on_status(self, status): + print("Status:", status) + if not opts.reply_to or opts.reply_to[0] != "~": + args.pop(0) + if not args: self.stop() + + def on_recv(self, msg): + print("Received:", msg) + if opts.reply_to and opts.reply_to[0] == "~": + args.pop(0) + if not args: self.stop() + + def on_stop(self): + print("Stopped") + +a = App(Messenger()) +a.run() http://git-wip-us.apache.org/repos/asf/qpid-site/blob/7833dc2a/content/releases/qpid-proton-0.16.0/messenger/python/examples/send_async.py.html ---------------------------------------------------------------------- diff --git a/content/releases/qpid-proton-0.16.0/messenger/python/examples/send_async.py.html b/content/releases/qpid-proton-0.16.0/messenger/python/examples/send_async.py.html new file mode 100644 index 0000000..21fdaad --- /dev/null +++ b/content/releases/qpid-proton-0.16.0/messenger/python/examples/send_async.py.html @@ -0,0 +1,194 @@ +<!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.py - 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.16.0/index.html">Qpid Proton 0.16.0</a></li><li><a href="/releases/qpid-proton-0.16.0/messenger/python/examples/index.html">Python AMQP Messenger Examples</a></li><li>send_async.py</li></ul> + + <div id="-middle-content"> + +<h1>send_async.py</h1> +<div class="highlight"><pre><span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">print_function</span> +<span class="kn">import</span> <span class="nn">sys</span><span class="o">,</span> <span class="nn">optparse</span> +<span class="kn">from</span> <span class="nn">async</span> <span class="kn">import</span> <span class="o">*</span> + +<span class="n">parser</span> <span class="o">=</span> <span class="n">optparse</span><span class="o">.</span><span class="n">OptionParser</span><span class="p">(</span><span class="n">usage</span><span class="o">=</span><span class="s">"usage: %prog [options] <msg_1> ... <msg_n>"</span><span class="p">,</span> + <span class="n">description</span><span class="o">=</span><span class="s">"simple message sender"</span><span class="p">)</span> +<span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">"-a"</span><span class="p">,</span> <span class="s">"--address"</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="s">"amqp://0.0.0.0"</span><span class="p">,</span> + <span class="n">help</span><span class="o">=</span><span class="s">"address: //<domain>[/<name>] (default </span><span class="si">%d</span><span class="s">efault)"</span><span class="p">)</span> +<span class="n">parser</span><span class="o">.</span><span class="n">add_option</span><span class="p">(</span><span class="s">"-r"</span><span class="p">,</span> <span class="s">"--reply_to"</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s">"reply_to: //<domain>[/<name>]"</span><span class="p">)</span> + +<span class="n">opts</span><span class="p">,</span> <span class="n">args</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">()</span> +<span class="k">if</span> <span class="ow">not</span> <span class="n">args</span><span class="p">:</span> + <span class="n">args</span> <span class="o">=</span> <span class="p">[</span><span class="s">"Hello World!"</span><span class="p">]</span> + +<span class="k">class</span> <span class="nc">App</span><span class="p">(</span><span class="n">CallbackAdapter</span><span class="p">):</span> + + <span class="k">def</span> <span class="nf">on_start</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> + <span class="k">print</span><span class="p">(</span><span class="s">"Started"</span><span class="p">)</span> + <span class="bp">self</span><span class="o">.</span><span class="n">message</span><span class="o">.</span><span class="n">clear</span><span class="p">()</span> + <span class="bp">self</span><span class="o">.</span><span class="n">message</span><span class="o">.</span><span class="n">address</span> <span class="o">=</span> <span class="n">opts</span><span class="o">.</span><span class="n">address</span> + <span class="bp">self</span><span class="o">.</span><span class="n">message</span><span class="o">.</span><span class="n">reply_to</span> <span class="o">=</span> <span class="n">opts</span><span class="o">.</span><span class="n">reply_to</span> + <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="n">args</span><span class="p">:</span> + <span class="bp">self</span><span class="o">.</span><span class="n">message</span><span class="o">.</span><span class="n">body</span> <span class="o">=</span> <span class="n">a</span> + <span class="bp">self</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">message</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">on_status</span><span class="p">)</span> + + <span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">reply_to</span><span class="p">:</span> + <span class="bp">self</span><span class="o">.</span><span class="n">messenger</span><span class="o">.</span><span class="n">recv</span><span class="p">()</span> + + <span class="k">def</span> <span class="nf">on_status</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">status</span><span class="p">):</span> + <span class="k">print</span><span class="p">(</span><span class="s">"Status:"</span><span class="p">,</span> <span class="n">status</span><span class="p">)</span> + <span class="k">if</span> <span class="ow">not</span> <span class="n">opts</span><span class="o">.</span><span class="n">reply_to</span> <span class="ow">or</span> <span class="n">opts</span><span class="o">.</span><span class="n">reply_to</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">!=</span> <span class="s">"~"</span><span class="p">:</span> + <span class="n">args</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> + <span class="k">if</span> <span class="ow">not</span> <span class="n">args</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span> + + <span class="k">def</span> <span class="nf">on_recv</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">msg</span><span class="p">):</span> + <span class="k">print</span><span class="p">(</span><span class="s">"Received:"</span><span class="p">,</span> <span class="n">msg</span><span class="p">)</span> + <span class="k">if</span> <span class="n">opts</span><span class="o">.</span><span class="n">reply_to</span> <span class="ow">and</span> <span class="n">opts</span><span class="o">.</span><span class="n">reply_to</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s">"~"</span><span class="p">:</span> + <span class="n">args</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> + <span class="k">if</span> <span class="ow">not</span> <span class="n">args</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span> + + <span class="k">def</span> <span class="nf">on_stop</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> + <span class="k">print</span><span class="p">(</span><span class="s">"Stopped"</span><span class="p">)</span> + +<span class="n">a</span> <span class="o">=</span> <span class="n">App</span><span class="p">(</span><span class="n">Messenger</span><span class="p">())</span> +<span class="n">a</span><span class="o">.</span><span class="n">run</span><span class="p">()</span> +</pre></div> + +<p><a href="send_async.py">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/7833dc2a/content/releases/qpid-proton-0.16.0/messenger/python/examples/server.py ---------------------------------------------------------------------- diff --git a/content/releases/qpid-proton-0.16.0/messenger/python/examples/server.py b/content/releases/qpid-proton-0.16.0/messenger/python/examples/server.py new file mode 100755 index 0000000..8c25879 --- /dev/null +++ b/content/releases/qpid-proton-0.16.0/messenger/python/examples/server.py @@ -0,0 +1,62 @@ +#!/usr/bin/python +# +# 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. +# +from __future__ import print_function +import sys, optparse +from proton import * + +parser = optparse.OptionParser(usage="usage: %prog <addr_1> ... <addr_n>", + description="simple message server") + +opts, args = parser.parse_args() + +if not args: + args = ["amqp://~0.0.0.0"] + +mng = Messenger() +mng.start() + +for a in args: + mng.subscribe(a) + +def dispatch(request, response): + if request.subject: + response.subject = "Re: %s" % request.subject + response.properties = request.properties + print("Dispatched %s %s" % (request.subject, request.properties)) + +msg = Message() +reply = Message() + +while True: + if mng.incoming < 10: + mng.recv(10) + + if mng.incoming > 0: + mng.get(msg) + if msg.reply_to: + print(msg.reply_to) + reply.address = msg.reply_to + reply.correlation_id = msg.correlation_id + reply.body = msg.body + dispatch(msg, reply) + mng.put(reply) + mng.send() + +mng.stop() http://git-wip-us.apache.org/repos/asf/qpid-site/blob/7833dc2a/content/releases/qpid-proton-0.16.0/messenger/python/examples/server.py.html ---------------------------------------------------------------------- diff --git a/content/releases/qpid-proton-0.16.0/messenger/python/examples/server.py.html b/content/releases/qpid-proton-0.16.0/messenger/python/examples/server.py.html new file mode 100644 index 0000000..bbb14f5 --- /dev/null +++ b/content/releases/qpid-proton-0.16.0/messenger/python/examples/server.py.html @@ -0,0 +1,192 @@ +<!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>server.py - 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.16.0/index.html">Qpid Proton 0.16.0</a></li><li><a href="/releases/qpid-proton-0.16.0/messenger/python/examples/index.html">Python AMQP Messenger Examples</a></li><li>server.py</li></ul> + + <div id="-middle-content"> + +<h1>server.py</h1> +<div class="highlight"><pre><span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">print_function</span> +<span class="kn">import</span> <span class="nn">sys</span><span class="o">,</span> <span class="nn">optparse</span> +<span class="kn">from</span> <span class="nn">proton</span> <span class="kn">import</span> <span class="o">*</span> + +<span class="n">parser</span> <span class="o">=</span> <span class="n">optparse</span><span class="o">.</span><span class="n">OptionParser</span><span class="p">(</span><span class="n">usage</span><span class="o">=</span><span class="s">"usage: %prog <addr_1> ... <addr_n>"</span><span class="p">,</span> + <span class="n">description</span><span class="o">=</span><span class="s">"simple message server"</span><span class="p">)</span> + +<span class="n">opts</span><span class="p">,</span> <span class="n">args</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">()</span> + +<span class="k">if</span> <span class="ow">not</span> <span class="n">args</span><span class="p">:</span> + <span class="n">args</span> <span class="o">=</span> <span class="p">[</span><span class="s">"amqp://~0.0.0.0"</span><span class="p">]</span> + +<span class="n">mng</span> <span class="o">=</span> <span class="n">Messenger</span><span class="p">()</span> +<span class="n">mng</span><span class="o">.</span><span class="n">start</span><span class="p">()</span> + +<span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="n">args</span><span class="p">:</span> + <span class="n">mng</span><span class="o">.</span><span class="n">subscribe</span><span class="p">(</span><span class="n">a</span><span class="p">)</span> + +<span class="k">def</span> <span class="nf">dispatch</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">response</span><span class="p">):</span> + <span class="k">if</span> <span class="n">request</span><span class="o">.</span><span class="n">subject</span><span class="p">:</span> + <span class="n">response</span><span class="o">.</span><span class="n">subject</span> <span class="o">=</span> <span class="s">"Re: </span><span class="si">%s</span><span class="s">"</span> <span class="o">%</span> <span class="n">request</span><span class="o">.</span><span class="n">subject</span> + <span class="n">response</span><span class="o">.</span><span class="n">properties</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">properties</span> + <span class="k">print</span><span class="p">(</span><span class="s">"Dispatched </span><span class="si">%s</span><span class="s"> </span><span class="si">%s</span><span class="s">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">request</span><span class="o">.</span><span class="n">subject</span><span class="p">,</span> <span class="n">request</span><span class="o">.</span><span class="n">properties</span><span class="p">))</span> + +<span class="n">msg</span> <span class="o">=</span> <span class="n">Message</span><span class="p">()</span> +<span class="n">reply</span> <span class="o">=</span> <span class="n">Message</span><span class="p">()</span> + +<span class="k">while</span> <span class="bp">True</span><span class="p">:</span> + <span class="k">if</span> <span class="n">mng</span><span class="o">.</span><span class="n">incoming</span> <span class="o"><</span> <span class="mi">10</span><span class="p">:</span> + <span class="n">mng</span><span class="o">.</span><span class="n">recv</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span> + + <span class="k">if</span> <span class="n">mng</span><span class="o">.</span><span class="n">incoming</span> <span class="o">></span> <span class="mi">0</span><span class="p">:</span> + <span class="n">mng</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span> + <span class="k">if</span> <span class="n">msg</span><span class="o">.</span><span class="n">reply_to</span><span class="p">:</span> + <span class="k">print</span><span class="p">(</span><span class="n">msg</span><span class="o">.</span><span class="n">reply_to</span><span class="p">)</span> + <span class="n">reply</span><span class="o">.</span><span class="n">address</span> <span class="o">=</span> <span class="n">msg</span><span class="o">.</span><span class="n">reply_to</span> + <span class="n">reply</span><span class="o">.</span><span class="n">correlation_id</span> <span class="o">=</span> <span class="n">msg</span><span class="o">.</span><span class="n">correlation_id</span> + <span class="n">reply</span><span class="o">.</span><span class="n">body</span> <span class="o">=</span> <span class="n">msg</span><span class="o">.</span><span class="n">body</span> + <span class="n">dispatch</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="n">reply</span><span class="p">)</span> + <span class="n">mng</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="n">reply</span><span class="p">)</span> + <span class="n">mng</span><span class="o">.</span><span class="n">send</span><span class="p">()</span> + +<span class="n">mng</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span> +</pre></div> + +<p><a href="server.py">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/7833dc2a/content/releases/qpid-proton-0.16.0/messenger/ruby/examples/client.rb ---------------------------------------------------------------------- diff --git a/content/releases/qpid-proton-0.16.0/messenger/ruby/examples/client.rb b/content/releases/qpid-proton-0.16.0/messenger/ruby/examples/client.rb new file mode 100755 index 0000000..a2c2564 --- /dev/null +++ b/content/releases/qpid-proton-0.16.0/messenger/ruby/examples/client.rb @@ -0,0 +1,92 @@ +#!/usr/bin/env ruby +# +# 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. +# + +require 'qpid_proton' +require 'optparse' + + +$options = { + :verbose => false, + :hostname => "0.0.0.0", + :subject => "", + :replyto => "~/replies" +} + + +OptionParser.new do |opts| + opts.banner = "Usage: client [options] <addr> <subject>" + + opts.on("-r", "--reply-to", String, :REQUIRED, + "Reply address") do |replyto| + $options[:replyto] = replyto + end + + opts.on("-v", "--verbose", :NONE, + "Enable verbose output") do + $options[:verbose] = true + end + + opts.on("-h", "--help", :NONE, + "Show this help message") do + puts opts + exit + end + + begin + ARGV << "-h" if ARGV.empty? + opts.parse!(ARGV) + rescue OptionParser::ParseError => error + STDERR.puts error.message, "\n", opts + exit 1 + end + + ($options[:address], $options[:subject]) = ARGV + + abort "No address specified" if $options[:hostname].nil? + abort "No subject specified" if $options[:subject].nil? + +end + +def log(text) + printf "#{Time.new}: #{text}\n" if $options[:verbose] +end + +msgr = Qpid::Proton::Messenger::Messenger.new +msgr.start + +msg = Qpid::Proton::Message.new +msg.address = $options[:address] +msg.subject = $options[:subject] +msg.reply_to = $options[:replyto] + +msgr.put(msg) +msgr.send + +if $options[:replyto].start_with? "~/" + msgr.receive(1) + begin + msgr.get(msg) + puts "#{msg.address}, #{msg.subject}" + rescue error + puts error + end +end + +msgr.stop http://git-wip-us.apache.org/repos/asf/qpid-site/blob/7833dc2a/content/releases/qpid-proton-0.16.0/messenger/ruby/examples/client.rb.html ---------------------------------------------------------------------- diff --git a/content/releases/qpid-proton-0.16.0/messenger/ruby/examples/client.rb.html b/content/releases/qpid-proton-0.16.0/messenger/ruby/examples/client.rb.html new file mode 100644 index 0000000..e8b7132 --- /dev/null +++ b/content/releases/qpid-proton-0.16.0/messenger/ruby/examples/client.rb.html @@ -0,0 +1,221 @@ +<!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>client.rb - 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.16.0/index.html">Qpid Proton 0.16.0</a></li><li><a href="/releases/qpid-proton-0.16.0/messenger/ruby/examples/index.html">Ruby AMQP Messenger Examples</a></li><li>client.rb</li></ul> + + <div id="-middle-content"> + +<h1>client.rb</h1> +<div class="highlight"><pre><span class="nb">require</span> <span class="s1">'qpid_proton'</span> +<span class="nb">require</span> <span class="s1">'optparse'</span> + + +<span class="vg">$options</span> <span class="o">=</span> <span class="p">{</span> + <span class="ss">:verbose</span> <span class="o">=></span> <span class="kp">false</span><span class="p">,</span> + <span class="ss">:hostname</span> <span class="o">=></span> <span class="s2">"0.0.0.0"</span><span class="p">,</span> + <span class="ss">:subject</span> <span class="o">=></span> <span class="s2">""</span><span class="p">,</span> + <span class="ss">:replyto</span> <span class="o">=></span> <span class="s2">"~/replies"</span> +<span class="p">}</span> + + +<span class="no">OptionParser</span><span class="o">.</span><span class="n">new</span> <span class="k">do</span> <span class="o">|</span><span class="n">opts</span><span class="o">|</span> + <span class="n">opts</span><span class="o">.</span><span class="n">banner</span> <span class="o">=</span> <span class="s2">"Usage: client [options] <addr> <subject>"</span> + + <span class="n">opts</span><span class="o">.</span><span class="n">on</span><span class="p">(</span><span class="s2">"-r"</span><span class="p">,</span> <span class="s2">"--reply-to"</span><span class="p">,</span> <span class="nb">String</span><span class="p">,</span> <span class="ss">:REQUIRED</span><span class="p">,</span> + <span class="s2">"Reply address"</span><span class="p">)</span> <span class="k">do</span> <span class="o">|</span><span class="n">replyto</span><span class="o">|</span> + <span class="vg">$options</span><span class="o">[</span><span class="ss">:replyto</span><span class="o">]</span> <span class="o">=</span> <span class="n">replyto</span> + <span class="k">end</span> + + <span class="n">opts</span><span class="o">.</span><span class="n">on</span><span class="p">(</span><span class="s2">"-v"</span><span class="p">,</span> <span class="s2">"--verbose"</span><span class="p">,</span> <span class="ss">:NONE</span><span class="p">,</span> + <span class="s2">"Enable verbose output"</span><span class="p">)</span> <span class="k">do</span> + <span class="vg">$options</span><span class="o">[</span><span class="ss">:verbose</span><span class="o">]</span> <span class="o">=</span> <span class="kp">true</span> + <span class="k">end</span> + + <span class="n">opts</span><span class="o">.</span><span class="n">on</span><span class="p">(</span><span class="s2">"-h"</span><span class="p">,</span> <span class="s2">"--help"</span><span class="p">,</span> <span class="ss">:NONE</span><span class="p">,</span> + <span class="s2">"Show this help message"</span><span class="p">)</span> <span class="k">do</span> + <span class="nb">puts</span> <span class="n">opts</span> + <span class="nb">exit</span> + <span class="k">end</span> + + <span class="k">begin</span> + <span class="no">ARGV</span> <span class="o"><<</span> <span class="s2">"-h"</span> <span class="k">if</span> <span class="no">ARGV</span><span class="o">.</span><span class="n">empty?</span> + <span class="n">opts</span><span class="o">.</span><span class="n">parse!</span><span class="p">(</span><span class="no">ARGV</span><span class="p">)</span> + <span class="k">rescue</span> <span class="ss">OptionParser</span><span class="p">:</span><span class="ss">:ParseError</span> <span class="o">=></span> <span class="n">error</span> + <span class="no">STDERR</span><span class="o">.</span><span class="n">puts</span> <span class="n">error</span><span class="o">.</span><span class="n">message</span><span class="p">,</span> <span class="s2">"</span><span class="se">\n</span><span class="s2">"</span><span class="p">,</span> <span class="n">opts</span> + <span class="nb">exit</span> <span class="mi">1</span> + <span class="k">end</span> + + <span class="p">(</span><span class="vg">$options</span><span class="o">[</span><span class="ss">:address</span><span class="o">]</span><span class="p">,</span> <span class="vg">$options</span><span class="o">[</span><span class="ss">:subject</span><span class="o">]</span><span class="p">)</span> <span class="o">=</span> <span class="no">ARGV</span> + + <span class="nb">abort</span> <span class="s2">"No address specified"</span> <span class="k">if</span> <span class="vg">$options</span><span class="o">[</span><span class="ss">:hostname</span><span class="o">].</span><span class="n">nil?</span> + <span class="nb">abort</span> <span class="s2">"No subject specified"</span> <span class="k">if</span> <span class="vg">$options</span><span class="o">[</span><span class="ss">:subject</span><span class="o">].</span><span class="n">nil?</span> + +<span class="k">end</span> + +<span class="k">def</span> <span class="nf">log</span><span class="p">(</span><span class="n">text</span><span class="p">)</span> + <span class="nb">printf</span> <span class="s2">"</span><span class="si">#{</span><span class="no">Time</span><span class="o">.</span><span class="n">new</span><span class="si">}</span><span class="s2">: </span><span class="si">#{</span><span class="n">text</span><span class="si">}</span><span class="se">\n</span><span class="s2">"</span> <span class="k">if</span> <span class="vg">$options</span><span class="o">[</span><span class="ss">:verbose</span><span class="o">]</span> +<span class="k">end</span> + +<span class="n">msgr</span> <span class="o">=</span> <span class="ss">Qpid</span><span class="p">:</span><span class="ss">:Proton</span><span class="o">::</span><span class="ss">Messenger</span><span class="p">:</span><span class="ss">:Messenger</span><span class="o">.</span><span class="n">new</span> +<span class="n">msgr</span><span class="o">.</span><span class="n">start</span> + +<span class="n">msg</span> <span class="o">=</span> <span class="ss">Qpid</span><span class="p">:</span><span class="ss">:Proton</span><span class="o">::</span><span class="no">Message</span><span class="o">.</span><span class="n">new</span> +<span class="n">msg</span><span class="o">.</span><span class="n">address</span> <span class="o">=</span> <span class="vg">$options</span><span class="o">[</span><span class="ss">:address</span><span class="o">]</span> +<span class="n">msg</span><span class="o">.</span><span class="n">subject</span> <span class="o">=</span> <span class="vg">$options</span><span class="o">[</span><span class="ss">:subject</span><span class="o">]</span> +<span class="n">msg</span><span class="o">.</span><span class="n">reply_to</span> <span class="o">=</span> <span class="vg">$options</span><span class="o">[</span><span class="ss">:replyto</span><span class="o">]</span> + +<span class="n">msgr</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span> +<span class="n">msgr</span><span class="o">.</span><span class="n">send</span> + +<span class="k">if</span> <span class="vg">$options</span><span class="o">[</span><span class="ss">:replyto</span><span class="o">].</span><span class="n">start_with?</span> <span class="s2">"~/"</span> + <span class="n">msgr</span><span class="o">.</span><span class="n">receive</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> + <span class="k">begin</span> + <span class="n">msgr</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span> + <span class="nb">puts</span> <span class="s2">"</span><span class="si">#{</span><span class="n">msg</span><span class="o">.</span><span class="n">address</span><span class="si">}</span><span class="s2">, </span><span class="si">#{</span><span class="n">msg</span><span class="o">.</span><span class="n">subject</span><span class="si">}</span><span class="s2">"</span> + <span class="k">rescue</span> <span class="n">error</span> + <span class="nb">puts</span> <span class="n">error</span> + <span class="k">end</span> +<span class="k">end</span> + +<span class="n">msgr</span><span class="o">.</span><span class="n">stop</span> +</pre></div> + +<p><a href="client.rb">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> --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org For additional commands, e-mail: commits-h...@qpid.apache.org