Rails 应用程序内的 AMQP 订阅者
是否可以使用我的 Rails 应用程序启动 AMQP 订阅者?可能通过初始化程序或其他东西。
我想让它同时运行,也可以与 Rails 模型交互。下面是我的意思的伪代码示例。
queue.subscribe do |msg,body|
Foo.create(....)
end
Is it possible to start an AMQP subscriber with my Rails app? Possibly through an initializer or something.
I'd like to have it running at the same time that can also interact with Rails models. Below is a pseudo-code example of what I mean.
queue.subscribe do |msg,body|
Foo.create(....)
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通常通过加载 Rails 环境的单独消息传递守护进程来执行此操作。
因此,一个非常简单的示例如下所示:rails_root/script/myapp_daemon.rb :
您还需要在 Gemfile 中添加正确的 gem 要求:amqp、daemons、eventmachine
然后要么与您的应用程序一起手动运行它:
要么从以下之一启动它你的应用程序初始值设定项:
要深入了解 amqp,请查看以下内容,这将提供一个很好的高级概述:
http://www.rubyinside.com/ Why-rubyists-should-care-about-messaging-a-high-level-intro-5017.html
这给出了非常详细的解释和工作示例:
http://rubydoc.info/github/ruby-amqp/amqp/ master/file/docs/Exchanges.textile#Publishing_messages_as_immediate_
最后看看 Bunny 是否完成了客户端所需的一切,就更简单了:
https://github.com/celldee/bunny/wiki/Using-Bunny
希望有帮助
I usually do this via a separate messaging daemon which loads the rails environment.
So a very simplistic example would look like this in rails_root/script/myapp_daemon.rb :
You would also need the right gem requires in your Gemfile: amqp, daemons, eventmachine
Then either run it manually alongside your app:
Or start it from one of your app initializers:
To dig into amqp check out the following, this will give a nice high level overview:
http://www.rubyinside.com/why-rubyists-should-care-about-messaging-a-high-level-intro-5017.html
This gives a very detailed explanation with working examples:
http://rubydoc.info/github/ruby-amqp/amqp/master/file/docs/Exchanges.textile#Publishing_messages_as_immediate_
Finally see if Bunny accomplishes everything you need for the client, it is simpler:
https://github.com/celldee/bunny/wiki/Using-Bunny
Hope that helps