Class: Banter::DbLogger
- Inherits:
-
Object
- Object
- Banter::DbLogger
- Defined in:
- lib/banter/db_logger.rb
Instance Method Summary collapse
-
#initialize ⇒ DbLogger
constructor
A new instance of DbLogger.
- #log_publish(routing_key, message) ⇒ Object
- #start_subscribe ⇒ Object
- #teardown ⇒ Object
Constructor Details
#initialize ⇒ DbLogger
Returns a new instance of DbLogger.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/banter/db_logger.rb', line 7 def initialize @config = Configuration.configuration[:mongo] if @config.present? @client = Mongo::MongoClient.new(@config[:host], @config[:port]) else @client = Mongo::MongoClient.new end @db = @client.db("logger") end |
Instance Method Details
#log_publish(routing_key, message) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/banter/db_logger.rb', line 36 def log_publish(routing_key, ) collection_name = "publisher" collection = @db.collection(collection_name) # no need for safe writes. need to write to a file log as well. collection.insert({routing_key: routing_key, cts: [:payload], ts: [:ts], pub: [:pub]}) # make sure that we always index these two items in mongo # it's a small price of a call, so no big deal collection.ensure_index( {routing_key:1, ts:1} ) end |
#start_subscribe ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/banter/db_logger.rb', line 19 def start_subscribe subscriber = ::Banter::Server::RabbitMQSubscriber.new("") subscriber.start("logger") do |info, properties, contents| # Write to mongo the contents and the routing_key, with the routing_key being indexed routing_key = info[:routing_key] chunks = routing_key.split(".") # Logger will split the data into collections based upon the first parameter of the routing_key (initial roll out will only use 'honest') collection_name = chunks[1] || chunks[0] collection = @db.collection(collection_name) # no need for safe writes. need to write to a file log as well. collection.insert({routing_key: routing_key, cts: contents, ts: properties[:timestamp]}) # make sure that we always index these two items in mongo # it's a small price of a call, so no big deal collection.ensure_index( {routing_key:1, ts:1} ) end end |
#teardown ⇒ Object
48 49 50 |
# File 'lib/banter/db_logger.rb', line 48 def teardown @subscriber.teardown end |