Developer
Developer

Reputation: 661

RabbitMQ with sidekiq

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?

Upvotes: 1

Views: 2421

Answers (1)

sad parrot
sad parrot

Reputation: 71

To read the messages you publish from App1 to App2, in App2 you gonna need sneakers (https://github.com/jondot/sneakers)

your reader would do something like:

class Reader
  include Sneakers::Worker
  from_queue 'test1'

  def work(message)
    # your code
    ack!
  end
end

and you need to configure your environment, you can take a look at https://github.com/jondot/sneakers/wiki/Configuration

Upvotes: 1

Related Questions