I am trying to start message queues on heroku. For this, I use the RabbitMQ Bigwig plugin .
I am posting using the bunny gem, and trying to get messages using sneakers. All this setting works smoothly on the local machine.
I do the following steps to set up the queue
I run this rake on the server to install the queue:
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
x = ch.direct('testsync.pcc', :durable => true)
queue = ch.queue('test.commands', :durable => true, :ack => true, :routing_key => 'test_cmd')
queue.bind(x, :routing_key => 'test_cmd')
conn.close
end
end
I can see this queue in the rabbitmq control plugin with the specified binding.
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)
@conn.start
end
end
I call TestPublisher.publish () to post a post.
I have such a crossover:
require 'test_sync'
class TestsWorker
include Sneakers::Worker
from_queue "test.commands", env: nil
def work(raw_event)
puts "^"*100
puts raw_event
test = Oj.load raw_event
test.execute
ack!
end
end
My profile
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
worker: bundle exec rake jobs:work
sneaker: WORKERS=TestsWorker bundle exec rake sneakers:run
My rakefile
require File.expand_path('../config/application', __FILE__)
require 'rake/dsl_definition'
require 'rake'
require 'sneakers/tasks'
Test::Application.load_tasks
My sneaker configuration
require 'sneakers'
Sneakers.configure amqp: ENV['RABBITMQ_BIGWIG_RX_URL'],
log: "log/sneakers.log",
threads: 1,
workers: 1
puts "configuring sneaker"
, . rabbitmq. . , .
sneakers.log on heroku: