Installing and running Apache Kafka on MacOS with Apple Silicon

Taapas Agrawal
2 min readJan 20, 2022

--

This article assumes that you have already setup homebrew on your MacOS Apple Silicon system. If not refer to this stackoverflow link to set it up or refer the official documentation.

The first steps are pretty straightforward:

$ brew install java
$ brew install kafka

Once these commands run successfully your kafka package is installed. Now to run kafka open two seperate terminals to run Zookeeper and Kafka services seperately as:

Start Zookeeper:

$ zookeeper-server-start /opt/homebrew/etc/kafka/zookeeper.properties

Start Kafka:

$ kafka-server-start /opt/homebrew/etc/kafka/server.properties

After the services are successfully running, the next step is to create a kafka topic. A topic is a category or feed name to which records are stored and published. Before running any producer or consumer API it is mandatory to create a topic. Here is an example to create a sample topic named foobar :

$ kafka-topics --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic foobar

NOTE: Notice here we aren’t using --zookeeper flag as in standard documentations because Kafka versions for new MacOS do not support/ require that flag anymore.

Once the topic is created we can test out Kafka producer and consumer APIs:

  • Open two terminals.
  • In the first one initialize a producer console for topic thefoobar . And try to send some test messages as follows:
$ kafka-console-producer --broker-list localhost:9092 --topic foobar
>
foo
> bar
  • In the second one initalize a consumer console for the topic foobar . This will listen to the bootstrap server at port 9092 at topic foobar:
$ kafka-console-consumer --bootstrap-server localhost:9092 --topic foobar --from-beginningfoo
bar

If you can see the outputs kafka is set up and running neatly on your Apple Silicon system.

Cheers !

--

--

Taapas Agrawal

SDE-II @ Cisco | GSoC’19 @Mercurial SCM | Open-souce enthusiast | IIT Kharagpur