Sha256: 53960407463dbf0dc92f5f881e6e2cdd51c905c6fc37a3ac787e4943c16e980f

Contents?: true

Size: 942 Bytes

Versions: 4

Compression:

Stored size: 942 Bytes

Contents

# encoding: utf-8
require 'rubygems'
require "mongo"

module RabbitHutch
  class MongoConsumer
      
    def initialize(rabbitmq_host, config)
      puts "\tInitializing MongoDb Consumer"
      @config = config
      @rabbitmq_host = rabbitmq_host
      @host = rabbitmq_host["hostname"]
      @config.consumers.each do |consumer|
        if consumer["name"] == 'mongo_consumer'
          @database_prefix = consumer['database_prefix']
         end
      end
      @database = "#{@database_prefix}#{rabbitmq_host["displayname"]}"
      @port = rabbitmq_host["port"]
      @connection = Mongo::Connection.new(@host, @port)
    end
        
    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 
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rabbithutch-0.0.7 lib/consumers/mongo_consumer.rb
rabbithutch-0.0.5 lib/consumers/mongo_consumer.rb
rabbithutch-0.0.3 lib/consumers/mongo_consumer.rb
rabbithutch-0.0.2 lib/consumers/mongo_consumer.rb