Skip to content

Instantly share code, notes, and snippets.

@rubygem
Created September 26, 2013 11:51
Show Gist options
  • Save rubygem/6713081 to your computer and use it in GitHub Desktop.
Save rubygem/6713081 to your computer and use it in GitHub Desktop.
My message queue code
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
@rubygem
Copy link
Author

rubygem commented Sep 26, 2013

require 'bundler/setup'
require 'test/unit'
require_relative "../src/MessageQueue"

class TestEndToEnd < Test::Unit::TestCase

def test_sending_message
message = {"_id"=>"x67Aa7je", "type"=>"point-to-point"}
(0..100).each do |i|
message_queue = MessageQueue.new
message_queue.push(message)
end

end
end

@rubygem
Copy link
Author

rubygem commented Sep 26, 2013

[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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment