Sha256: 7501a479a90bbbd556cf923087e13eabf6a58257e0f97545e9a9812e497721c4

Contents?: true

Size: 950 Bytes

Versions: 6

Compression:

Stored size: 950 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
      
      @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
        
    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

6 entries across 6 versions & 1 rubygems

Version Path
rabbithutch-0.1.5 lib/consumers/mongo_consumer.rb
rabbithutch-0.1.2 lib/consumers/mongo_consumer.rb
rabbithutch-0.1.1 lib/consumers/mongo_consumer.rb
rabbithutch-0.1.0 lib/consumers/mongo_consumer.rb
rabbithutch-0.0.9 lib/consumers/mongo_consumer.rb
rabbithutch-0.0.8 lib/consumers/mongo_consumer.rb