Ruby SMPP 与 RabbitMQ 和 Eventmachine,AMQP.stop 后出现问题
我对rabbitmq 有一个小问题,我不明白。 我正在使用:
- Ruby 版本 1.8.7
- AMQP GEM 版本 0.7.0
- RabbitMQ v2.3.1
- ruby-smpp v0.4.0
我的代码如下所示:
loop do
AMQP.start do
EventMachine::run do
@@tx = EventMachine::connect(
config[:host],
config[:port],
Smpp::Transceiver,
config,
self # delegate that will receive callbacks on MOs and DRs and other events
)
EM.add_timer(10) do
puts "AMQP New"
amq = MQ.new
amq.queue("#{provider}").subscribe(:ack => true) do |header, msg|
puts "Provider #{provider} consumer #{Process.pid} processed #{msg}"
header.ack
end
end
EM.add_timer(30) {EventMachine::stop_event_loop}
end
end
AMQP.stop
puts "#{config[:host]} Disconnected. Reconnecting in 35 seconds.."
sleep 35
end
我添加了这一行进行测试。 EM.add_timer(30) {EventMachine::stop_event_loop}
所以 30 秒后。我停止事件循环,它会休眠 35 秒,然后重新启动一切。 问题是 amq = MQ.new 似乎做了一些事情并且没有给我错误,但订阅似乎不起作用。也没有错误。 只有在停止进程并再次启动后,它才会再次订阅并处理消息。 我不明白为什么
I have a little problem with rabbitmq which I don't understand.
I am using:
- Ruby Version 1.8.7
- AMQP GEM Version 0.7.0
- RabbitMQ v2.3.1
- ruby-smpp v0.4.0
My code looks like this:
loop do
AMQP.start do
EventMachine::run do
@@tx = EventMachine::connect(
config[:host],
config[:port],
Smpp::Transceiver,
config,
self # delegate that will receive callbacks on MOs and DRs and other events
)
EM.add_timer(10) do
puts "AMQP New"
amq = MQ.new
amq.queue("#{provider}").subscribe(:ack => true) do |header, msg|
puts "Provider #{provider} consumer #{Process.pid} processed #{msg}"
header.ack
end
end
EM.add_timer(30) {EventMachine::stop_event_loop}
end
end
AMQP.stop
puts "#{config[:host]} Disconnected. Reconnecting in 35 seconds.."
sleep 35
end
I added this line for testing.
EM.add_timer(30) {EventMachine::stop_event_loop}
so after 30 sec. I stop the event loop, it sleeps 35 seconds and the restarts everything.
The problem is that amq = MQ.new seems to do something and it doesn't give me an error, but the subscribe doesn't seem to work. Also no error.
Only after stopping the process and starting it again it subscribes again and processes messages.
I don't understand why
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
AMQP.start 有它自己的 EM 魔力——这可能就是困扰你的地方。
以下是示例,说明如何操作EM 运行中的 AMQP(或者看起来是这样)
AMQP.start does it's own EM magic - this might be what is biting you.
Here's an example on how to do AMQP inside an EM run (or so it seems)
您可以尝试这个简单的库:https://github.com/sck-v/communications
除了两个应用程序之间的简单通信
You can try this simple library: https://github.com/sck-v/communications
Nothing except simple communications between two applications