我在heroku中有两个rails应用程序,App1和App2(添加了cloudAMQP gem),App1在点击按钮时会生成一些消息
APP1
class Publisher
def publish
# Start a communication session with RabbitMQ
connection = Bunny.new(:host => "chimpanzee.rmq.cloudamqp.com", :vhost => "test", :user => "test", :password => "password")
connection.start
# open a channel
channel = connection.create_channel
# declare a queue
queue = channel.queue("test1")
# publish a message to the default exchange which then gets routed to this queue
queue.publish("Hello, everybody!")
end
end
所以在App2中我必须使用所有消息而不需要任何按钮点击并将其放在sidekiq中来处理数据,但我仍然坚持如何自动从该队列中读取,我知道代码如何从队列中读取值,人们说运动鞋宝石,但我对sidekiq和运动鞋有点困惑,我们怎么能在heroku中做到这一点?
要阅读从App1发布到App2的消息,在App2中你需要运动鞋(https://github.com/jondot/sneakers)
你的读者会做类似的事情:
class Reader
include Sneakers::Worker
from_queue 'test1'
def work(message)
# your code
ack!
end
end
你需要配置你的环境,你可以看看https://github.com/jondot/sneakers/wiki/Configuration