What have you found for these years?

2010-03-17

AMQP and EventMachine

(from my email with some editing)
2010-03-15 21:45

I think AMQP gem is well written,
it's based on EventMachine, which is used in
Thin server. This should be a lot more efficient
than delayed_job in my opinion, but surely harder
to integrate into Rails than delayed_job because
it's not designed for Rails only.

The most important thing is that it is EventMachine
based, so it would need EventMachine's event loop
to work properly. In other words, you can't use it directly
in Mongrel, Passenger, etc. But you can use it in Thin
(thus Heroku I guess?[0]) because Thin is EventMachine
based so it has the event loop already. It won't work
on my current favorite Ruby server Unicorn as well, it
needs Rainbows! with Rainbows::EventMachine backend.

A simple example, in Rails:

mq = MQ.new
mq.queue('a job').publish('message')

in worker:
mq = MQ.new
mq.queue('a job').subscribe{ |msg|
# doing things with msg, this is a callback block
}

A little more complex example with Topic, in Rails:
mq = MQ.new
mq.topic('topic').publish('message', :key => 'user.something')

in worker:
mq = MQ.new
mq.queue('a job').bind(mq.topic('topic'), :key =>
'user.*').subscribe{ |info, msg|
# info.routing_key is the key passed in, here it would be 'user.something'
}


cheers,

[0] Heroku AMQP add-on

0 retries:

Post a Comment

All texts are licensed under CC Attribution 3.0