Heroku でメッセージ キューを実行しようとしています。このために、RabbitMQ Bigwigプラグインを使用しています。
バニージェムを使用してメッセージを発行し、スニーカージェムでメッセージを受信しようとしています。このセットアップ全体は、ローカル マシン上でスムーズに動作します。
キューをセットアップするには、次の手順を実行します
サーバーでこのレーキを実行して、キューをセットアップします。
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 管理プラグインでメッセージを取得できます。でもスニーカーはダメ。助けることができるsneaker.logに何もありません。
herokuのsneakers.log:
# Logfile created on 2016-04-05 14:40:59 +0530 by logger.rb/41212