Class: Receiver

Inherits:
Object
  • Object
show all
Defined in:
lib/test_driven_lighting/receiver.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Receiver

Returns a new instance of Receiver.



7
8
9
10
11
# File 'lib/test_driven_lighting/receiver.rb', line 7

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

Instance Method Details

#listen(queue_name, &block) ⇒ Object



13
14
15
16
17
18
# File 'lib/test_driven_lighting/receiver.rb', line 13

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, , payload|
    yield JSON.parse(payload)
  end
end