Skip to content

Instantly share code, notes, and snippets.

@simonmorley
Created March 21, 2014 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonmorley/9684010 to your computer and use it in GitHub Desktop.
Save simonmorley/9684010 to your computer and use it in GitHub Desktop.
require "amqp"
error_handler = Proc.new do |settings|
puts "Failed to connect."
EM.stop
end
Thread.new { AMQP.start(
:port => 5672,
:vhost => '/',
:user => 'guest',
:password => 'guest',
:timeout => 10,
:on_tcp_connection_failure => error_handler)}
class MessageQueue
def initialize()
EventMachine.next_tick do
AMQP.channel ||= AMQP::Channel.new(AMQP.connection)
$exchange = AMQP.channel.topic("polkaspots", durable: true, auto_delete: false)
end
end
def push(message, routing_key = '#', expiration = nil)
EventMachine.next_tick do
$exchange.publish(
message,
message_id: SecureRandom.uuid,
content_type: "application/json",
expiration: expiration,
routing_key: routing_key
)
end
end
alias_method :<<, :push
end
MESSAGE_QUEUE = MessageQueue.new
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment