Skip to content

Instantly share code, notes, and snippets.

@dasch
Last active January 18, 2016 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dasch/b2ebe1e29dd3aab3396f to your computer and use it in GitHub Desktop.
Save dasch/b2ebe1e29dd3aab3396f to your computer and use it in GitHub Desktop.
Example Ruby Kafka client API
require 'kafka'
kafka_brokers = ENV.fetch("KAFKA_BROKERS").split(",")
kafka_topic = "application.events"
kafka = Kafka.new(brokers: kafka_brokers, logger: logger)
consumer = kafka.consumer(group_id: "my-consumer", autocommit: true)
consumer.subscribe(kafka_topic) do |messages|
messages.each do |message|
puts message.topic, message.partition, message.offset, message.key, message.value
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment