Sha256: 95abab893074ce145caa365a3551e114228a4abd238ffd2a0916b805d4621af1

Contents?: true

Size: 971 Bytes

Versions: 8

Compression:

Stored size: 971 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  
        puts "mongo"
        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

8 entries across 8 versions & 1 rubygems

Version Path
dafiti-rabbit-hutch-0.1.12 lib/consumers/mongo_consumer.rb
dafiti-rabbit-hutch-0.1.11 lib/consumers/mongo_consumer.rb
dafiti-rabbit-hutch-0.1.10 lib/consumers/mongo_consumer.rb
dafiti-rabbit-hutch-0.1.9 lib/consumers/mongo_consumer.rb
dafiti-rabbit-hutch-0.1.5 lib/consumers/mongo_consumer.rb
dafiti-rabbit-hutch-0.1.4 lib/consumers/mongo_consumer.rb
dafiti-rabbit-hutch-0.1.1 lib/consumers/mongo_consumer.rb
dafiti-rabbit-hutch-0.1.0 lib/consumers/mongo_consumer.rb