Hi,<div><br></div><div>Spinning up a new thread was the answer to my problem:</div><div><br></div><div><div>� � � � � � � Thread.new do</div><div>� � � � � � � � 5.times do</div><div>� � � � � � � � � lead = get_lead(n, (n == 5))</div>
<div><br></div><div>� � � � � � � � � puts &quot;message #{n} is_last = #{lead.is_last} at #{Time.now}&quot;;</div><div>� � � � � � � ��</div><div>� � � � � � � � � AMQP::Exchange.default.publish(</div><div>� � � � � � � � � � � � � � � � � � � � � � � � � MultiJson.encode(lead),�</div>
<div>� � � � � � � � � � � � � � � � � � � � � � � � � :routing_key =&gt; header.reply_to,</div><div>� � � � � � � � � � � � � � � � � � � � � � � � � :correlation_id =&gt; header.correlation_id</div><div>� � � � � � � � � � � � � � � � � � � � � � � � )</div>
<div>� � � � � � � ��</div><div>� � � � � � � � � n += 1</div><div>� � � � � � � � � sleep(2)</div><div>� � � � � � � � end</div><div>� � � � � � � end</div></div><div><br></div><div>Creating a new thread stops the EventMachine reactor being blocked and the messages are sent async.</div>
<div><br clear="all">Cheers<br><br>Paul Cowan<br><br>Cutting-Edge Solutions (Scotland)<br><br><a href="http://thesoftwaresimpleton.com/" target="_blank">http://thesoftwaresimpleton.com/</a><br><br>
<br><br><div class="gmail_quote">On 6 January 2012 17:38, Paul Cowan <span dir="ltr">&lt;<a href="mailto:dagda1@scotalt.net">dagda1@scotalt.net</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<div><br></div><div>I have refactored my code to use EM::defer. �I still have the same problem as before.</div><div><br></div><div>I am a bit new to rabbitmq and EventMachine, I wonder if anyone could review the EM::defer code in the following gist:</div>

<div><br></div><div><a href="https://gist.github.com/1571453" target="_blank">https://gist.github.com/1571453</a></div><div><br></div><div>Also, do you think the header.ack on line 44 of the gist is in the right place?</div>
<div><div class="im"><br clear="all">
Cheers<br><br>Paul Cowan<br><br>Cutting-Edge Solutions (Scotland)<br><br><a href="http://thesoftwaresimpleton.com/" target="_blank">http://thesoftwaresimpleton.com/</a><br><br>
<br><br></div><div><div class="h5"><div class="gmail_quote">On 6 January 2012 08:39, Paul Cowan <span dir="ltr">&lt;<a href="mailto:dagda1@scotalt.net" target="_blank">dagda1@scotalt.net</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Hi,<div><br></div><div>Thanks for the answer, I will rollback to EM::defer and checkout what is going on over wireshark.<br><br>Is there any documentation for the append_callback method and if so, where can I find it.</div>


<div><br clear="all">Cheers<br><br>Paul Cowan<br><br>Cutting-Edge Solutions (Scotland)<br><br><a href="http://thesoftwaresimpleton.com/" target="_blank">http://thesoftwaresimpleton.com/</a><div><div><br><br>
<br><br><div class="gmail_quote">On 6 January 2012 07:44, Michael Klishin <span dir="ltr">&lt;<a href="mailto:michael.s.klishin@gmail.com" target="_blank">michael.s.klishin@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


Paul Cowan:<br>
<br>
&gt; The above code works as I want with one annoying exception. Something is blocking the EM::Iterator code from being executed asynchronously. It is only after the EM::Iterator code has completed that the messages are sent. I want the messages to be sent asynchronously and handled by the anonymous queue after each iteration. At the moment, it is only after the EM::Iterator code has completed its last iteration that all the messages are sent.<br>



&gt;<br>
<br>
This is a question for EventMachine mailing list. EventMachine::Iterator is only available in beta releases of EventMachine 1.0, so use it with caution.<br>
<br>
&gt; Can anyone see what I am doing wrong or suggest a different approach? I tried EM::defer and had the same behaviour.<br>
&gt;<br>
<br>
EventMachine.defer uses a thread pool with 20 threads by default. If operations you defer to it are blocked, it may suggest that the issue is not with something blocking the event loop.<br>
<br>
For example, you are using prefetch = 1 and manual acknowledgements for your consumer that uses EventMachine::Iterator. However, I don&#39;t see messages being acknowledged.<br>
<br>
You can use Wireshark GUI to record a session of what&#39;s going up and down the wire (filter for &quot;amqp&quot;).<br>
<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><br>
<br>
</blockquote></div><br></div></div></div>
</blockquote></div><br></div></div></div>
</blockquote></div><br></div>