Class: RabbitHutch::MongoConsumer

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

Instance Method Summary collapse

Constructor Details

#initialize(rabbitmq_host, config) ⇒ MongoConsumer

Returns a new instance of MongoConsumer.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/consumers/mongo_consumer.rb', line 8

def initialize(rabbitmq_host, config)
  puts "\tInitializing MongoDb Consumer"
  @config = config
  @rabbitmq_host = rabbitmq_host
  
  @config.consumers.each do |consumer|
    if consumer["name"] == 'mongo_consumer'
      @host = consumer['hostname']
      @port = consumer["port"]
      @database_prefix = consumer['database_prefix']
      @database = "#{@database_prefix}#{rabbitmq_host["displayname"]}"
    end
  end
  @connection = Mongo::Connection.new(@host, @port)
end

Instance Method Details

#log_event(item) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/consumers/mongo_consumer.rb', line 24

def log_event(item)
  begin  
    db = @connection.db(@database)
    coll = db.collection(item[:exchange])
    coll.insert(item)
  rescue Exception => e
    puts "Error occurred Message Handler trying to write messages to MONGODB #{e.inspect}" 
  end
end