Class: MqLogger::MQClient

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

Instance Method Summary collapse

Constructor Details

#initialize(queue_nqme, routing_key) ⇒ MQClient

Returns a new instance of MQClient.



8
9
10
11
12
# File 'lib/mq_logger.rb', line 8

def initialize(queue_nqme, routing_key)
  @queue = queue_nqme
  @route = routing_key
  @channel = nil
end

Instance Method Details

#write(event) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/mq_logger.rb', line 14

def write(event)
  begin
    connect unless @channel
  
    @channel.direct(@queue, :durable => true, :persistent => true).publish("#{event.to_hash.to_json}\n", :routing_key => @route)
  rescue => e
    warn "MQClient - #{e.class} - #{e.message}, AMQP.channel is null; log===#{event.to_hash.to_json.inspect}"
  end
end