I have two applications sap1 and sap2 and i have been using rabbitMQ (bunny gem) for messaging, so that is working like from sap1 i will create the message and publish
sap1 (publisher app)
Gemfile
ruby 1.9.3
gem 'bunny', '~> 1.7', '>= 1.7.1'
publish.rb
def publish
# Start a communication session with RabbitMQ
connection = Bunny.new(:host => "123123", :vhost => "1231", :user => "123", :password => "Z7tN")
connection.start
# open a channel
channel = connection.create_channel
# declare a queue
queue = channel.queue("refresh-pos-menu-test", :durable => true)
# publish a message to the default exchange which then gets routed to this queue
values = { mac_id: 14123 }
queue.publish(values.to_json)
connection.close
end
sap2 (consumer app)
Gemfile
ruby 2
gem 'bunny'
gem 'sneakers'
config/initializers/sneakers.rb
require 'sneakers'
Sneakers.configure :connection => Bunny.new(:host => "123123", :vhost => "1231", :user => "123", :password => "Z7tN"), :timeout_job_after => 360
Rakefile
require 'sneakers/tasks'
app/workers/mac_worker.rb
class MacWorker
include Sneakers::Worker
from_queue "mac-test"
def work(params)
# Calling the function
end
end
and in the console for listen doing this
bundle exec rake sneakers:run
Here this is working, sometimes i am getting connection issue also, in the consumer app i don't want to use sneakers gem so instead i want to read message from queue with bunny and put it into sidekiq, also how to listen automatically in sidekiq?
Aucun commentaire:
Enregistrer un commentaire