Sha256: 7ef3c0f204cc6392db7f2a4ebb5e1f4881f435940704b3e82a5a8f5fa9677ab9

Contents?: true

Size: 574 Bytes

Versions: 2

Compression:

Stored size: 574 Bytes

Contents

require 'bunny'
require 'json'

STDOUT.sync = true

class Receiver
  def initialize(config)
    @connection = Bunny.new("amqp://#{config[:bunny_username]}:#{config[:bunny_password]}@#{config[:bunny_host]}").start
    @channel = @connection.create_channel
    @exchange = @channel.fanout('lighting.messages')
  end

  def listen(queue_name, &block)
    puts 'listening for light messages...'
    @channel.queue(queue_name, :auto_delete => true).bind(@exchange).subscribe(:block => true) do |delivery_info, metadata, payload|
      yield JSON.parse(payload)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
test_driven_lighting-1.2.0 lib/test_driven_lighting/receiver.rb
test_driven_lighting-1.1.0 lib/test_driven_lighting/receiver.rb