2

First of all this is working fine in my local machine.

I have one publisher app (Rails 3), which is publishing message to cloudamq(addon) in heroku, we are getting messages in cloudamq

enter image description here

and one consumer application (Rails 5) which is also running on heroku as a separate app, i put this consumer in a rake task but here the issue is this takes messages from the queue only when we restart the server, that means this rake task will run when we restart, but in rabbitMQ it shows always running

enter image description here

So how can we make the consumer to listen continuously once we push to heroku?

Also once we get the message from queue i have to call a sidekiq worker, that is not happening? using 'redis to go' addon

CONSUMER APP

Gem which i have used in this cosumer application

gem 'redis', '~> 3.0'

gem 'sidekiq'

gem 'bunny'

This is the consumer part to get the message from queue as a rake task.

 task :do_consumer => :environment do

   connection = Bunny.new(ENV['CLOUDAMQP_URL'])

   connection.start # start a communication session with the amqp server

   channel = connection.channel()

   queue = channel.queue('order-queue', durable: true)

   puts ' [*] Waiting for messages. To exit press CTRL+C'

   queue.subscribe(manual_ack: true, block: true) do |delivery_info, 
   properties, payload|
      puts " [x] Received #{payload}"
      puts " [x] Done"

      channel.ack(delivery_info.delivery_tag, false)
      # Call sidekiq worker to do task
      callSidekiqWorker.perform_async(payload)
   end
end

Procfile

web: bundle exec puma -C config/puma.rb
worker: bundle exec sidekiq -e production
worker: bundle exec rake do_consumer
Developer
  • 561
  • 7
  • 29
  • 1
    just a thought, it seems that rake will start the process for the task and this process will be killed after task is completed. Basically the line: `queue.subscribe` will not be there once the rake process will stop. You would need a running process for subscription. You may want to create a file in `config/initializers/subscribers.rb` and put this logic there. – teckden Sep 25 '18 at 08:02
  • thanks @teckden, now its listening but that sidekiq worker call is not happening, bcz in my local when i run 'bundle exec sidekiq' that new subscribers.rb initializer is calling – Developer Sep 25 '18 at 09:06
  • I do not have much experience with rabbitmq, if no one will help you I can try to check it later. For now maybe you can take a look at https://github.com/jondot/sneakers so in your` Procfile` you would have something `worker: bundle exec sneakers work Processor` – teckden Sep 25 '18 at 09:53
  • Yes this one i tried, that was working, but i dn't want to use more gem, thats'y i am working with this way, thanks – Developer Sep 25 '18 at 10:08

0 Answers0