Last active
August 29, 2015 14:24
-
-
Save blurredbits/aa2cd858ea05599f0360 to your computer and use it in GitHub Desktop.
Kafka Mongo Consumer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'poseidon' | |
require 'mongo' | |
Mongo::Logger.logger.level = Logger::WARN | |
db = Mongo::Client.new(['127.0.0.1:27017'], database: 'metrics') | |
consumer = Poseidon::PartitionConsumer.new("mongo_consumer", "localhost", 9092, "metrics", 0, :earliest_offset) | |
loop do | |
messages = consumer.fetch | |
messages.each do |m| | |
result = db[:metrics].insert_one({ metric: m.value }) | |
if result.n == 1 | |
puts "MONGO --> Inserted metric: #{m.value}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment