[rabbitmq-discuss] EventMachine EM::Iterator being blocked with rabbitmq rbc
Paul Cowan
dagda1 at scotalt.net
Sun Jan 8 15:36:36 GMT 2012
Hi,
Spinning up a new thread was the answer to my problem:
Thread.new do
5.times do
lead = get_lead(n, (n == 5))
puts "message #{n} is_last = #{lead.is_last} at
#{Time.now}";
AMQP::Exchange.default.publish(
MultiJson.encode(lead),
:routing_key =>
header.reply_to,
:correlation_id =>
header.correlation_id
)
n += 1
sleep(2)
end
end
Creating a new thread stops the EventMachine reactor being blocked and the
messages are sent async.
Cheers
Paul Cowan
Cutting-Edge Solutions (Scotland)
http://thesoftwaresimpleton.com/
On 6 January 2012 17:38, Paul Cowan <dagda1 at scotalt.net> wrote:
> Hi,
>
> I have refactored my code to use EM::defer. I still have the same problem
> as before.
>
> I am a bit new to rabbitmq and EventMachine, I wonder if anyone could
> review the EM::defer code in the following gist:
>
> https://gist.github.com/1571453
>
> Also, do you think the header.ack on line 44 of the gist is in the right
> place?
>
> Cheers
>
> Paul Cowan
>
> Cutting-Edge Solutions (Scotland)
>
> http://thesoftwaresimpleton.com/
>
>
>
> On 6 January 2012 08:39, Paul Cowan <dagda1 at scotalt.net> wrote:
>
>> Hi,
>>
>> Thanks for the answer, I will rollback to EM::defer and checkout what is
>> going on over wireshark.
>>
>> Is there any documentation for the append_callback method and if so,
>> where can I find it.
>>
>> Cheers
>>
>> Paul Cowan
>>
>> Cutting-Edge Solutions (Scotland)
>>
>> http://thesoftwaresimpleton.com/
>>
>>
>>
>>
>> On 6 January 2012 07:44, Michael Klishin <michael.s.klishin at gmail.com>wrote:
>>
>>> Paul Cowan:
>>>
>>> > 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.
>>> >
>>>
>>> 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.
>>>
>>> > Can anyone see what I am doing wrong or suggest a different approach?
>>> I tried EM::defer and had the same behaviour.
>>> >
>>>
>>> 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.
>>>
>>> For example, you are using prefetch = 1 and manual acknowledgements for
>>> your consumer that uses EventMachine::Iterator. However, I don't see
>>> messages being acknowledged.
>>>
>>> You can use Wireshark GUI to record a session of what's going up and
>>> down the wire (filter for "amqp").
>>>
>>> MK
>>>
>>> http://github.com/michaelklishin
>>> http://twitter.com/michaelklishin
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20120108/bad1c8da/attachment.htm>
More information about the rabbitmq-discuss
mailing list