1

I have two rails applications, App1 and App2(added cloudAMQP gem) in heroku, App1 is producing some message when click on a button

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

so in the App2 i have to consume all the messages without any button click and put that in sidekiq to process the data, but i am stuck on how can i automatically read from that queue, i know the code how to read values from queue, people are saying sneakers gem, but i am bit confused with sidekiq and sneakers, any idea of how can we do it in heroku?

4

1 回答 1

1

要阅读您从 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

于 2018-09-07T23:35:11.250 回答