RabbitMQ和运动鞋的配置问题

时间:2018-09-10 12:12:54

标签: ruby-on-rails ruby-on-rails-3 sidekiq bunny sneakers

我有两个应用程序sap1和sap2,并且我一直在使用RabbitMQ(小兔子gem)进行消息传递,因此就像从sap1一样工作,我将创建消息并发布

sap1(发布商应用)

宝石文件

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("order-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(消费类应用)

宝石文件

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 "order-test"

  def work(params)
     # Calling the function
  end
end

并在控制台中进行监听

 bundle exec rake sneakers:run

这在起作用,有时我也遇到连接问题,在消费者应用程序中,我不想使用运动鞋gem,因此我想从兔子队列中读取消息并将其放入sidekiq,以及如何收听自动在sidekiq中吗?

0 个答案:

没有答案