diff options
Diffstat (limited to 'introduction.html')
-rw-r--r-- | introduction.html | 71 |
1 files changed, 46 insertions, 25 deletions
diff --git a/introduction.html b/introduction.html index 1de9bb2f..668e15a5 100644 --- a/introduction.html +++ b/introduction.html @@ -6,13 +6,13 @@ <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> - <title>kombu - AMQP Messaging Framework for Python — Kombu v1.3.2 documentation</title> + <title>kombu - AMQP Messaging Framework for Python — Kombu v1.4.0 documentation</title> <link rel="stylesheet" href="_static/celery.css" type="text/css" /> <link rel="stylesheet" href="_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '', - VERSION: '1.3.2', + VERSION: '1.4.0', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true @@ -21,7 +21,7 @@ <script type="text/javascript" src="_static/jquery.js"></script> <script type="text/javascript" src="_static/underscore.js"></script> <script type="text/javascript" src="_static/doctools.js"></script> - <link rel="top" title="Kombu v1.3.2 documentation" href="index.html" /> + <link rel="top" title="Kombu v1.4.0 documentation" href="index.html" /> <link rel="next" title="User Guide" href="userguide/index.html" /> <link rel="prev" title="Kombu Documentation" href="index.html" /> </head> @@ -41,7 +41,7 @@ <li class="right" > <a href="index.html" title="Kombu Documentation" accesskey="P">previous</a> |</li> - <li><a href="index.html">Kombu v1.3.2 documentation</a> »</li> + <li><a href="index.html">Kombu v1.4.0 documentation</a> »</li> </ul> </div> @@ -56,7 +56,7 @@ <col class="field-name" /> <col class="field-body" /> <tbody valign="top"> -<tr class="field"><th class="field-name">Version:</th><td class="field-body">1.3.1</td> +<tr class="field"><th class="field-name">Version:</th><td class="field-body">1.4.0</td> </tr> </tbody> </table> @@ -195,38 +195,59 @@ Can be disabled by setting the <tt class="docutils literal"><span class="pre">su </div> <div class="section" id="quick-overview"> <h3>Quick overview<a class="headerlink" href="#quick-overview" title="Permalink to this headline">ΒΆ</a></h3> -<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">kombu.connection</span> <span class="kn">import</span> <span class="n">BrokerConnection</span> -<span class="kn">from</span> <span class="nn">kombu.messaging</span> <span class="kn">import</span> <span class="n">Exchange</span><span class="p">,</span> <span class="n">Queue</span><span class="p">,</span> <span class="n">Consumer</span><span class="p">,</span> <span class="n">Producer</span> +<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">kombu</span> <span class="kn">import</span> <span class="n">BrokerConnection</span><span class="p">,</span> <span class="n">Exchange</span><span class="p">,</span> <span class="n">Queue</span> <span class="n">media_exchange</span> <span class="o">=</span> <span class="n">Exchange</span><span class="p">(</span><span class="s">"media"</span><span class="p">,</span> <span class="s">"direct"</span><span class="p">,</span> <span class="n">durable</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span> <span class="n">video_queue</span> <span class="o">=</span> <span class="n">Queue</span><span class="p">(</span><span class="s">"video"</span><span class="p">,</span> <span class="n">exchange</span><span class="o">=</span><span class="n">media_exchange</span><span class="p">,</span> <span class="n">routing_key</span><span class="o">=</span><span class="s">"video"</span><span class="p">)</span> -<span class="c"># connections/channels</span> -<span class="n">connection</span> <span class="o">=</span> <span class="n">BrokerConnection</span><span class="p">(</span><span class="s">"localhost"</span><span class="p">,</span> <span class="s">"guest"</span><span class="p">,</span> <span class="s">"guest"</span><span class="p">,</span> <span class="s">"/"</span><span class="p">)</span> -<span class="n">channel</span> <span class="o">=</span> <span class="n">connection</span><span class="o">.</span><span class="n">channel</span><span class="p">()</span> +<span class="c"># connections</span> +<span class="k">with</span> <span class="n">BrokerConnection</span><span class="p">(</span><span class="s">"amqp://guest:guest@localhost//"</span><span class="p">)</span> <span class="k">as</span> <span class="n">conn</span><span class="p">:</span> -<span class="c"># produce</span> -<span class="n">producer</span> <span class="o">=</span> <span class="n">Producer</span><span class="p">(</span><span class="n">channel</span><span class="p">,</span> <span class="n">exchange</span><span class="o">=</span><span class="n">media_exchange</span><span class="p">,</span> <span class="n">serializer</span><span class="o">=</span><span class="s">"json"</span><span class="p">)</span> -<span class="n">producer</span><span class="o">.</span><span class="n">publish</span><span class="p">({</span><span class="s">"name"</span><span class="p">:</span> <span class="s">"/tmp/lolcat1.avi"</span><span class="p">,</span> <span class="s">"size"</span><span class="p">:</span> <span class="mi">1301013</span><span class="p">})</span> + <span class="c"># produce</span> + <span class="k">with</span> <span class="n">conn</span><span class="o">.</span><span class="n">Producer</span><span class="p">(</span><span class="n">exchange</span><span class="o">=</span><span class="n">media_exchange</span><span class="p">,</span> + <span class="n">serializer</span><span class="o">=</span><span class="s">"json"</span><span class="p">)</span> <span class="k">as</span> <span class="n">producer</span><span class="p">:</span> + <span class="n">producer</span><span class="o">.</span><span class="n">publish</span><span class="p">({</span><span class="s">"name"</span><span class="p">:</span> <span class="s">"/tmp/lolcat1.avi"</span><span class="p">,</span> <span class="s">"size"</span><span class="p">:</span> <span class="mi">1301013</span><span class="p">})</span> -<span class="c"># consume</span> -<span class="n">consumer</span> <span class="o">=</span> <span class="n">Consumer</span><span class="p">(</span><span class="n">channel</span><span class="p">,</span> <span class="n">video_queue</span><span class="p">)</span> -<span class="n">consumer</span><span class="o">.</span><span class="n">register_callback</span><span class="p">(</span><span class="n">process_media</span><span class="p">)</span> -<span class="n">consumer</span><span class="o">.</span><span class="n">consume</span><span class="p">()</span> - -<span class="c"># Process messages on all channels</span> -<span class="k">while</span> <span class="bp">True</span><span class="p">:</span> - <span class="n">connection</span><span class="o">.</span><span class="n">drain_events</span><span class="p">()</span> + <span class="c"># consume</span> + <span class="k">with</span> <span class="n">conn</span><span class="o">.</span><span class="n">Consumer</span><span class="p">(</span><span class="n">video_queue</span><span class="p">,</span> <span class="n">callbacks</span><span class="o">=</span><span class="p">[</span><span class="n">process_media</span><span class="p">])</span> <span class="k">as</span> <span class="n">consumer</span><span class="p">:</span> + <span class="c"># Process messages and handle events on all channels</span> + <span class="k">while</span> <span class="bp">True</span><span class="p">:</span> + <span class="n">connection</span><span class="o">.</span><span class="n">drain_events</span><span class="p">()</span> <span class="c"># Consume from several queues on the same channel:</span> <span class="n">video_queue</span> <span class="o">=</span> <span class="n">Queue</span><span class="p">(</span><span class="s">"video"</span><span class="p">,</span> <span class="n">exchange</span><span class="o">=</span><span class="n">media_exchange</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="s">"video"</span><span class="p">)</span> <span class="n">image_queue</span> <span class="o">=</span> <span class="n">Queue</span><span class="p">(</span><span class="s">"image"</span><span class="p">,</span> <span class="n">exchange</span><span class="o">=</span><span class="n">media_exchange</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="s">"image"</span><span class="p">)</span> -<span class="n">consumer</span> <span class="o">=</span> <span class="n">Consumer</span><span class="p">(</span><span class="n">channel</span><span class="p">,</span> <span class="p">[</span><span class="n">video_queue</span><span class="p">,</span> <span class="n">image_queue</span><span class="p">])</span> +<span class="k">with</span> <span class="n">connection</span><span class="o">.</span><span class="n">Consumer</span><span class="p">([</span><span class="n">video_queue</span><span class="p">,</span> <span class="n">image_queue</span><span class="p">],</span> + <span class="n">callbacks</span><span class="o">=</span><span class="p">[</span><span class="n">process_media</span><span class="p">])</span> <span class="k">as</span> <span class="n">consumer</span><span class="p">:</span> + <span class="k">while</span> <span class="bp">True</span><span class="p">:</span> + <span class="n">connection</span><span class="o">.</span><span class="n">drain_events</span><span class="p">()</span> +</pre></div> +</div> +<p>Or handle channels menually:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="k">with</span> <span class="n">connection</span><span class="o">.</span><span class="n">channel</span><span class="p">()</span> <span class="k">as</span> <span class="n">channel</span><span class="p">:</span> + <span class="n">producer</span> <span class="o">=</span> <span class="n">Producer</span><span class="p">(</span><span class="n">channel</span><span class="p">,</span> <span class="o">...</span><span class="p">)</span> + <span class="n">consumer</span> <span class="o">=</span> <span class="n">Producer</span><span class="p">(</span><span class="n">channel</span><span class="p">)</span> +</pre></div> +</div> +<p>All objects can be used outside of with statements too, +just remember to close the objects after use:</p> +<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">kombu</span> <span class="kn">import</span> <span class="n">BrokerConnection</span><span class="p">,</span> <span class="n">Consumer</span><span class="p">,</span> <span class="n">Producer</span> + +<span class="n">connection</span> <span class="o">=</span> <span class="n">BrokerConnection</span><span class="p">()</span> + <span class="c"># ...</span> +<span class="n">connection</span><span class="o">.</span><span class="n">close</span><span class="p">()</span> + +<span class="n">consumer</span> <span class="o">=</span> <span class="n">Consumer</span><span class="p">(</span><span class="n">channel_or_connection</span><span class="p">,</span> <span class="o">...</span><span class="p">)</span> +<span class="n">consumer</span><span class="o">.</span><span class="n">register_callback</span><span class="p">(</span><span class="n">my_callback</span><span class="p">)</span> <span class="n">consumer</span><span class="o">.</span><span class="n">consume</span><span class="p">()</span> + <span class="c"># ....</span> +<span class="n">consumer</span><span class="o">.</span><span class="n">cancel</span><span class="p">()</span> + -<span class="k">while</span> <span class="bp">True</span><span class="p">:</span> - <span class="n">connection</span><span class="o">.</span><span class="n">drain_events</span><span class="p">()</span> +<span class="n">producer</span> <span class="o">=</span> <span class="n">Producer</span><span class="p">(</span><span class="n">channel_or_connection</span><span class="p">,</span> <span class="o">...</span><span class="p">)</span> + <span class="c"># ....</span> +<span class="n">producer</span><span class="o">.</span><span class="n">close</span><span class="p">()</span> </pre></div> </div> <p><cite>Exchange</cite> and <cite>Queue</cite> are simply declarations that can be pickled @@ -434,7 +455,7 @@ file in the top distribution directory for the full license text.</p> <li class="right" > <a href="index.html" title="Kombu Documentation" >previous</a> |</li> - <li><a href="index.html">Kombu v1.3.2 documentation</a> »</li> + <li><a href="index.html">Kombu v1.4.0 documentation</a> »</li> </ul> </div> <div class="footer"> |