Install

Kafka needs Zookeer in order to run.

➜ brew install zookeeper
➜ brew services start zookeper

We can instal and run Kafka the same way.

➜ brew install kafka
➜ brew services start kafka

When both are started, we can validate what all services are running on our system.

➜ brew services list
Name           Status  User   Plist
zookeeper      started ondrej /Users/ondrej/Library/LaunchAgents/homebrew.mxcl.zookeeper.plist
kafka          started ondrej /Users/ondrej/Library/LaunchAgents/homebrew.mxcl.kafka.plist

Now we need to find where is Kafka installed so we can access its tools.

➜ brew --prefix kafka
/usr/local/opt/kafka

Add it to your profile, for example, if you use zsh, add this line into your vi ~/.zshrc.

# Kafka
export PATH=/usr/local/opt/kafka/bin:$PATH

Don't forget to reload the config: source ~/.zshrc

Now we can try out whether we can access Kafka commands. Lets try to list all topics that are present in Kafka.

Setup multi-broker cluster

We have managed to run single broker. Lets see how to configure and start up multiple Kafka brokers.

Because we are going to run brokers on the same machine, we need to change these in broker1.properties

And these in broker2.properties

Now we can start up the two brokers we made the configuration for.

We can create topic that will be using 3 brokers we have started up so far.

We can see what is happening in the cluster using describe topics command.

  • leader is node that is responsible for all reads and writes for given partition, if we would set partitions to 2, we would see two lines here

  • replicas - list of all nodes that replicate the log for this partition

  • isr - in-sync replicas, or "alive" replicas

If we want to kill the nodes we created, we first get the process id and then kill it.

Now we can check what --describe command returns when we run it again, after we have killed one broker.

Last updated

Was this helpful?