Created
September 26, 2013 11:51
-
-
Save rubygem/6713081 to your computer and use it in GitHub Desktop.
My message queue code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bundler/setup' | |
require 'bunny' | |
class MessageQueue | |
def initialize | |
@conn = Bunny.new(ENV['QUEUE']) | |
@queue_name = ENV['QUEUE_NAME'] | |
end | |
def push(service) | |
puts " [x] Sending #{service} on #{@queue_name}" | |
@conn.start | |
ch = @conn.create_channel | |
q = ch.queue(@queue_name) | |
ch.default_exchange.publish(service.to_json, :routing_key => q.name) | |
puts " [x] Sent #{service} on #{@queue_name}" | |
@conn.close | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[1/1] TestEndToEnd#test_sending_message [x] Sending {"_id"=>"x67Aa7je", "type"=>"point-to-point"} on test.queue
[x] Sent {"_id"=>"x67Aa7je", "type"=>"point-to-point"} on test.queue
[x] Sending {"_id"=>"x67Aa7je", "type"=>"point-to-point"} on test.queue
[x] Sent {"_id"=>"x67Aa7je", "type"=>"point-to-point"} on test.queue
[x] Sending {"_id"=>"x67Aa7je", "type"=>"point-to-point"} on test.queue
[x] Sent {"_id"=>"x67Aa7je", "type"=>"point-to-point"} on test.queue
[x] Sending {"_id"=>"x67Aa7je", "type"=>"point-to-point"} on test.queue
[x] Sent {"_id"=>"x67Aa7je", "type"=>"point-to-point"} on test.queue
[x] Sending {"_id"=>"x67Aa7je", "type"=>"point-to-point"} on test.queue
[x] Sent {"_id"=>"x67Aa7je", "type"=>"point-to-point"} on test.queue
[x] Sending {"_id"=>"x67Aa7je", "type"=>"point-to-point"} on test.queue
[x] Sent {"_id"=>"x67Aa7je", "type"=>"point-to-point"} on test.queue
[x] Sending {"_id"=>"x67Aa7je", "type"=>"point-to-point"} on test.queue
[x] Sent {"_id"=>"x67Aa7je", "type"=>"point-to-point"} on test.queue
[x] Sending {"_id"=>"x67Aa7je", "type"=>"point-to-point"} on test.queue
[x] Sent {"_id"=>"x67Aa7je", "type"=>"point-to-point"} on test.queue
[x] Sending {"_id"=>"x67Aa7je", "type"=>"point-to-point"} on test.queue
[x] Sent {"_id"=>"x67Aa7je", "type"=>"point-to-point"} on test.queue
[x] Sending {"_id"=>"x67Aa7je", "type"=>"point-to-point"} on test.queue
[x] Sent {"_id"=>"x67Aa7je", "type"=>"point-to-point"} on test.queue
[x] Sending {"_id"=>"x67Aa7je", "type"=>"point-to-point"} on test.queue
[x] Sent {"_id"=>"x67Aa7je", "type"=>"point-to-point"} on test.queue
[x] Sending {"_id"=>"x67Aa7je", "type"=>"point-to-point"} on test.queue
[x] Sent {"_id"=>"x67Aa7je", "type"=>"point-to-point"} on test.queue
[x] Sending {"_id"=>"x67Aa7je", "type"=>"point-to-point"} on test.queue
[x] Sent {"_id"=>"x67Aa7je", "type"=>"point-to-point"} on test.queue
/home/developer/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/test/unit.rb:796:in `write': execution expired (Bunny::ConnectionTimeout)