sneaker 在 heroku 上没有收到消息 - RabbitMQ Bigwig
sneaker is not receiving messages on heroku - RabbitMQ Bigwig
我正在尝试 运行 heroku 上的消息队列。为此,我正在使用 RabbitMQ Bigwig 插件。
我正在使用兔子 gem 发布消息并尝试使用运动鞋 gem 接收消息。整个设置在本地机器上运行顺利。
我按照以下步骤设置队列
我运行服务器上的这个耙子设置队列:
namespace :rabbitmq do
desc 'Setup routing'
task :setup_test_commands_queue do
require 'bunny'
conn = Bunny.new(ENV['SYNC_AMQP'], read_timeout: 10, heartbeat: 10)
conn.start
ch = conn.create_channel
# get or create exchange
x = ch.direct('testsync.pcc', :durable => true)
# get or create queue (note the durable setting)
queue = ch.queue('test.commands', :durable => true, :ack => true, :routing_key => 'test_cmd')
# bind queue to exchange
queue.bind(x, :routing_key => 'test_cmd')
conn.close
end
end
我能够在 rabbitmq management 插件中看到这个队列,其中提到了绑定。
class TestPublisher
def self.publish(test)
x = channel.direct("testsync.pcc", :durable => true)
puts "publishing this = #{Test}"
x.publish(Test, :persistent => true, :routing_key => 'pcc_cmd')
end
def self.channel
@channel ||= connection.create_channel
end
def self.connection
@conn = Bunny.new(ENV['RABBITMQ_BIGWIG_TX_URL'], read_timeout: 10, heartbeat: 10) # getting configuration from rabbitmq.yml
@conn.start
end
end
我正在调用 TestPublisher.publish() 发布消息。
我有这样的鞋匠:
require 'test_sync'
class TestsWorker
include Sneakers::Worker
from_queue "test.commands", env: nil
def work(raw_event)
puts "^"*100
puts raw_event
# o = CaseNote.create!(content: raw_event, creator_id: 1)
# puts "#########{o}"
test = Oj.load raw_event
test.execute
# event_params = JSON.parse(raw_event)
# SomeWiseService.build.call(event_params)
ack!
end
end
我的程序文件
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
worker: bundle exec rake jobs:work
sneaker: WORKERS=TestsWorker bundle exec rake sneakers:run
我的 Rakefile
require File.expand_path('../config/application', __FILE__)
require 'rake/dsl_definition'
require 'rake'
require 'sneakers/tasks'
Test::Application.load_tasks
我的运动鞋配置
require 'sneakers'
Sneakers.configure amqp: ENV['RABBITMQ_BIGWIG_RX_URL'],
log: "log/sneakers.log",
threads: 1,
workers: 1
puts "configuring sneaker"
我确定消息已发布。我能够在 rabbitmq management 插件上收到消息。但是运动鞋不起作用。 sneakers.log 中没有任何帮助。
sneakers.log 在 heroku 上:
# Logfile created on 2016-04-05 14:40:59 +0530 by logger.rb/41212
很抱歉这么晚才回复。我能够在 heroku 上运行它。经过数小时的调试后,当我遇到此错误时,我无法修复它。所以我重写了上面所有的代码,我没有检查我以前的代码有什么问题。
此代码和正确代码的唯一问题是队列绑定。
我在同一个交换器上有两个队列。 pcc.commands
路由密钥 pcc_cmd
和 test.commands
路由密钥 test_cmd
.
我正在使用 test_cmd
但按照 TestPublisher
中的以下行
x.publish(Test, :persistent => true, :routing_key => 'pcc_cmd')
我正在发布到不同的队列 (pcc.commands)。因此我无法在 test.commands
队列中收到消息。
在TestWorker
from_queue "test.commands", env: nil
这表示仅从 test.commands
队列中获取消息。
关于 sneakers.log
文件:
以上设置无法在 sneakers.log
文件中给我日志。是的,此设置适用于您的本地开发机器,但不适用于 heroku。现在为了调试此类问题,我从配置中省略了 log
属性。像这样:
require 'sneakers'
Sneakers.configure amqp: ENV['RABBITMQ_BIGWIG_RX_URL'],
# log: "log/sneakers.log",
threads: 1,
workers: 1
这样你会在heroku日志中得到sneaker日志(甚至心跳日志),可以通过运行命令heroku logs -a app_name --tail
.
查看
我正在尝试 运行 heroku 上的消息队列。为此,我正在使用 RabbitMQ Bigwig 插件。
我正在使用兔子 gem 发布消息并尝试使用运动鞋 gem 接收消息。整个设置在本地机器上运行顺利。
我按照以下步骤设置队列
我运行服务器上的这个耙子设置队列:
namespace :rabbitmq do
desc 'Setup routing'
task :setup_test_commands_queue do
require 'bunny'
conn = Bunny.new(ENV['SYNC_AMQP'], read_timeout: 10, heartbeat: 10)
conn.start
ch = conn.create_channel
# get or create exchange
x = ch.direct('testsync.pcc', :durable => true)
# get or create queue (note the durable setting)
queue = ch.queue('test.commands', :durable => true, :ack => true, :routing_key => 'test_cmd')
# bind queue to exchange
queue.bind(x, :routing_key => 'test_cmd')
conn.close
end
end
我能够在 rabbitmq management 插件中看到这个队列,其中提到了绑定。
class TestPublisher
def self.publish(test)
x = channel.direct("testsync.pcc", :durable => true)
puts "publishing this = #{Test}"
x.publish(Test, :persistent => true, :routing_key => 'pcc_cmd')
end
def self.channel
@channel ||= connection.create_channel
end
def self.connection
@conn = Bunny.new(ENV['RABBITMQ_BIGWIG_TX_URL'], read_timeout: 10, heartbeat: 10) # getting configuration from rabbitmq.yml
@conn.start
end
end
我正在调用 TestPublisher.publish() 发布消息。
我有这样的鞋匠:
require 'test_sync'
class TestsWorker
include Sneakers::Worker
from_queue "test.commands", env: nil
def work(raw_event)
puts "^"*100
puts raw_event
# o = CaseNote.create!(content: raw_event, creator_id: 1)
# puts "#########{o}"
test = Oj.load raw_event
test.execute
# event_params = JSON.parse(raw_event)
# SomeWiseService.build.call(event_params)
ack!
end
end
我的程序文件
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
worker: bundle exec rake jobs:work
sneaker: WORKERS=TestsWorker bundle exec rake sneakers:run
我的 Rakefile
require File.expand_path('../config/application', __FILE__)
require 'rake/dsl_definition'
require 'rake'
require 'sneakers/tasks'
Test::Application.load_tasks
我的运动鞋配置
require 'sneakers'
Sneakers.configure amqp: ENV['RABBITMQ_BIGWIG_RX_URL'],
log: "log/sneakers.log",
threads: 1,
workers: 1
puts "configuring sneaker"
我确定消息已发布。我能够在 rabbitmq management 插件上收到消息。但是运动鞋不起作用。 sneakers.log 中没有任何帮助。
sneakers.log 在 heroku 上:
# Logfile created on 2016-04-05 14:40:59 +0530 by logger.rb/41212
很抱歉这么晚才回复。我能够在 heroku 上运行它。经过数小时的调试后,当我遇到此错误时,我无法修复它。所以我重写了上面所有的代码,我没有检查我以前的代码有什么问题。
此代码和正确代码的唯一问题是队列绑定。
我在同一个交换器上有两个队列。 pcc.commands
路由密钥 pcc_cmd
和 test.commands
路由密钥 test_cmd
.
我正在使用 test_cmd
但按照 TestPublisher
x.publish(Test, :persistent => true, :routing_key => 'pcc_cmd')
我正在发布到不同的队列 (pcc.commands)。因此我无法在 test.commands
队列中收到消息。
在TestWorker
from_queue "test.commands", env: nil
这表示仅从 test.commands
队列中获取消息。
关于 sneakers.log
文件:
以上设置无法在 sneakers.log
文件中给我日志。是的,此设置适用于您的本地开发机器,但不适用于 heroku。现在为了调试此类问题,我从配置中省略了 log
属性。像这样:
require 'sneakers'
Sneakers.configure amqp: ENV['RABBITMQ_BIGWIG_RX_URL'],
# log: "log/sneakers.log",
threads: 1,
workers: 1
这样你会在heroku日志中得到sneaker日志(甚至心跳日志),可以通过运行命令heroku logs -a app_name --tail
.