我正在尝试在 heroku 上运行消息队列。为此,我正在使用RabbitMQ Bigwig插件。
我正在使用 bunny gem 发布消息并尝试使用运动鞋 gem 接收消息。整个设置在本地机器上运行顺利。
我采取以下步骤来设置队列
我在服务器上运行这个 rake 来设置队列:
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 管理插件中看到这个队列,并提到了绑定。
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
我的文件
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 管理插件的消息。但是运动鞋不起作用。在sneakers.log 中没有任何帮助。
在heroku上的sneakers.log:
# Logfile created on 2016-04-05 14:40:59 +0530 by logger.rb/41212