Class: RabbitHutch::Consumer

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

Overview

Controls the consumers that are to be kicked off based on the config file

Instance Method Summary collapse

Constructor Details

#initialize(consumers) ⇒ Consumer

Returns a new instance of Consumer.



8
9
10
# File 'lib/consumer.rb', line 8

def initialize(consumers)
  @consumers = consumers
end

Instance Method Details

#handle_message(metadata, payload) ⇒ Object

Raised on receipt of a message from RabbitMq and uses the appropriate appender



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/consumer.rb', line 13

def handle_message(, payload)
   # loop through appenders and fire each as required
   @consumers.each do |consumer|
     action = .routing_key.split('.', 2).first
     if(action == "publish")
       exchange = .attributes[:headers]["exchange_name"]
       queue = .routing_key.split('.', 2).last
       item = {:date => Time.now, 
            :exchange => exchange,
            :queue => queue,
            :routing_keys => .attributes[:headers]["routing_keys"].inspect,
            :attributes => .attributes.inspect,
            :payload => payload.inspect
       }
       consumer.log_event(item)
     end 
   end
end