Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails rabbitMQ和运动鞋的配置问题_Ruby On Rails_Ruby On Rails 3_Sidekiq_Bunny_Sneakers - Fatal编程技术网

Ruby on rails rabbitMQ和运动鞋的配置问题

Ruby on rails rabbitMQ和运动鞋的配置问题,ruby-on-rails,ruby-on-rails-3,sidekiq,bunny,sneakers,Ruby On Rails,Ruby On Rails 3,Sidekiq,Bunny,Sneakers,我有两个应用程序sap1和sap2,我一直在使用rabbitMQ(bunny gem)进行消息传递,因此它的工作方式与sap1类似,我将创建消息并发布 sap1(发布者应用程序) Gemfile ruby 1.9.3 gem 'bunny', '~> 1.7', '>= 1.7.1' ruby 2 gem 'bunny' gem 'sneakers' publish.rb def publish # Start a communication session with R

我有两个应用程序sap1和sap2,我一直在使用rabbitMQ(bunny gem)进行消息传递,因此它的工作方式与sap1类似,我将创建消息并发布

sap1(发布者应用程序)

Gemfile

ruby 1.9.3
gem 'bunny', '~> 1.7', '>= 1.7.1'
ruby 2
gem 'bunny'
gem 'sneakers'
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(消费者应用程序)

Gemfile

ruby 1.9.3
gem 'bunny', '~> 1.7', '>= 1.7.1'
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
耙子

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

这是可行的,有时我也会遇到连接问题,在消费者应用程序中,我不想使用sneakers gem,所以我想用bunny从队列中读取消息并将其放入sidekiq,还有如何在sidekiq中自动侦听?

您的问题是如何编码。您的生产环境不应该与您的开发环境不同。它是Rails Way 12 factor的核心租户之一。你在受苦,因为你没有遵循它。您需要在这两个版本中都安装相同的组件,阅读sidekiq教程以使其正常工作,然后返回错误消息(在prod/env中也是如此),我同意@Mirv。如果您在生产中使用RabbitMQ/bunny,那么也可以在登台、测试和开发中使用它。实现这一点的方法是为每个环境创建单独的队列。当您的代码运行时,每个环境都应该有不同的配置;该配置可以指定要使用的队列。这样,你在每个环境中都使用完全相同的代码。哦,该死,那是我的错误,我在代码中做的是正确的,当我在这里写的时候,它得到了改变