Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'json'
- require 'bunny'
- class AMQPNotifierQueue
- def initialize(options = {})
- @amqp = Bunny.new(options)
- @amqp.start
- @exchange = @amqp.exchange('rails', :type => :topic)
- @hostname = `hostname -s`
- @pid = $$
- end
- # name, start, finish, result, instrumenter_id, payload
- def publish(*args)
- routing_key = [args[0], args[4], @pid, @hostname].join(".")
- @exchange.publish(args.to_json, :key => routing_key)
- end
- def subscribe(listener, pattern=nil, &block)
- @queue = @amqp.queue
- @queue.bind(@exchange, :key => pattern.to_s)
- Thread.new do
- @queue.subscribe { |msg| block.call(msg) }
- end
- end
- end
Add Comment
Please, Sign In to add comment