Ruby library to access and manipulate Kafka metadata in Zookeeper
First, make kazoo available by adding it to your Gemfile
gem 'kazoo-ruby', require: 'kazoo'
Now, you can interact with the cluster metadata as follows:
# Connect to the Zookeeper cluster that backs your Kafka cluster
cluster = Kazoo::Cluster.new('zookeeper1:2181,zookeeper2:2181/chroot')
# List the brokers that form the Kafka cluster
cluster.brokers.each do |id, broker|
puts "Broker #{broker.id}: #{broker.addr}"
end
# Inspect topic/partition metadata
cluster.topics.each do |name, topic|
puts "#{name}: #{topic.partitions.length} partitions"
end
# List consumers
cluster.consumergroups.each do |name, group|
puts "Consumer #{name}: #{group.instances.length} running instances"
end
This gem also comes with a simple kazoo
binary to inspect your kafka cluster:
# Describe the brokers that compose the cluster
$ kazoo cluster --zookeeper zk1:2181,zk2:2181,zk3:2181/chroot
# List all topics or partitions in the cluster
$ kazoo topics --zookeeper zk1:2181,zk2:2181,zk3:2181/chroot
$ kazoo partitions --topic=access_log --zookeeper zk1:2181,zk2:2181,zk3:2181/chroot
- Fork it ( https://github.com/wvanbergen/kazoo/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
- kafka-consumer: a high-level Kafka consumer library that coordinates running instances using Zookeeper.