<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
<!--
@font-face
        {font-family:"Cambria Math"}
@font-face
        {font-family:Calibri}
@font-face
        {font-family:Tahoma}
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif"}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline}
pre
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New"}
span.EmailStyle17
        {font-family:"Calibri","sans-serif";
        color:#1F497D}
span.HTMLPreformattedChar
        {font-family:"Courier New"}
span.c
        {}
span.k
        {}
span.nn
        {}
span.nc
        {}
span.p
        {}
span.nb
        {}
span.nf
        {}
span.bp
        {}
span.o
        {}
span.n
        {}
span.s
        {}
span.ow
        {}
span.mf
        {}
span.si
        {}
.MsoChpDefault
        {}
@page WordSection1
        {margin:1.0in 1.0in 1.0in 1.0in}
div.WordSection1
        {}
-->
</style>
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<pre><span style="font-size:11.0pt; font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;; color:#1F497D">To note, if this is an easier description, I’m trying to implement the RPC example on the RabbitMQ tutorial with a synchronous connection. Which I’ve copied below so you guys don’t need to go find it. However, the main impetus to me moving forward is lines 13/14:<br><br></span></pre>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result = self.channel.queue_declare(exclusive=True)</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.callback_queue = result.method.queue</span></p>
<pre><span style="font-size:11.0pt; font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;; color:#1F497D">&nbsp;</span></pre>
<pre><span style="font-size:11.0pt; font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;; color:#1F497D">Line 13 declares the result variable as the product of the channel getting an exclusive queue created, which I get. However the part that I get caught up in is where the callback is set to result.method.queue in line 14. What exactly is the method.queue of the result object? I am hoping to simply modify my Monitor/Publish classes to be able to have a synchronous publish/monitor without creating 2 connections. My current attempt at simply using one connection with 2 channels does not seem to be operating how I expected.<br><br></span>#!/usr/bin/env python</pre>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">import pika</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">import uuid</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">class FibonacciRpcClient(object):</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp; def __init__(self):</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.connection = pika.BlockingConnection(pika.ConnectionParameters(</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; host='localhost'))</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.channel = self.connection.channel()</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result = self.channel.queue_declare(exclusive=True)</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.callback_queue = result.method.queue</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.channel.basic_consume(self.on_response, no_ack=True,</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; queue=self.callback_queue)</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp; def on_response(self, ch, method, props, body):</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if self.corr_id == props.correlation_id:</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.response = body</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp; def call(self, n):</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.response = None</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.corr_id = str(uuid.uuid4())</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;self.channel.basic_publish(exchange='',</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; routing_key='rpc_queue',</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; properties=pika.BasicProperties(</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reply_to = self.callback_queue,</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;correlation_id = self.corr_id,</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ),</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; body=str(n))</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while self.response is None:</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.connection.process_data_events()</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return int(self.response)</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">fibonacci_rpc = FibonacciRpcClient()</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">&nbsp;</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">print &quot; [x] Requesting fib(30)&quot;</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">response = fibonacci_rpc.call(30)</span></p>
<p class="MsoNormal"><span style="font-size:10.0pt; font-family:&quot;Courier New&quot;">print &quot; [.] Got %r&quot; % (response,)</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt; font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;; color:#1F497D">&nbsp;</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt; font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;; color:#1F497D">&nbsp;</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt; font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;; color:#1F497D">&nbsp;</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt; font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;; color:#1F497D">-Christopher Lefevre</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt; font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;; color:#1F497D">&nbsp;</span></p>
<div style="border:none; border-top:solid #B5C4DF 1.0pt; padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt; font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style="font-size:10.0pt; font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> Michael Klishin [mailto:michael.s.klishin@gmail.com]
<br>
<b>Sent:</b> Tuesday, September 06, 2011 9:38 AM<br>
<b>To:</b> Christopher Lefevre<br>
<b>Cc:</b> rabbitmq-discuss@lists.rabbitmq.com<br>
<b>Subject:</b> Re: [rabbitmq-discuss] Publish on a queue, then Monitor on a reply queue, with only 1 connection to the RabbitMQ server? Non-blocking?</span></p>
</div>
<p class="MsoNormal">&nbsp;</p>
<p class="MsoNormal">2011/9/6 Christopher Lefevre &lt;<a href="mailto:CLefevre@transparent.com">CLefevre@transparent.com</a>&gt;</p>
<div>
<blockquote style="border:none; border-left:solid #CCCCCC 1.0pt; padding:0in 0in 0in 6.0pt; margin-left:4.8pt; margin-right:0in">
<p class="MsoNormal">Though I also wanted it to be non-blocking so the website isn’t stuck waiting for the reply, but rather can be updated as needed. Currently, I can get it to work if there is a pause, like when stepping through the program in a debugger,
 but when it runs without myself stepping through, it simply hangs when the queue is created and the message is never picked up.</p>
</blockquote>
</div>
<p class="MsoNormal"><br>
Please post a code example that is at least similar to your actual code.<br clear="all">
</p>
<div>
<p class="MsoNormal">&nbsp;</p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt">-- <br>
MK<br>
<br>
<a href="http://github.com/michaelklishin" target="_blank">http://github.com/michaelklishin</a><br>
<a href="http://twitter.com/michaelklishin" target="_blank">http://twitter.com/michaelklishin</a></p>
</div>
The information contained in this electronic message and any attached document(s) is intended only for the personal and confidential use of the designated recipients named above. This message may be confidential. If the reader of this message is not the intended
 recipient, you are hereby notified that you have received this document in error, and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify sender immediately
 by telephone (603) 262-6300 or by electronic mail immediately. Thank you.
</body>
</html>