Skip to content

Instantly share code, notes, and snippets.

@rupeshtiwari
Created March 12, 2024 05:59
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 rupeshtiwari/ae258a286d537ee9213a8da848c5f6eb to your computer and use it in GitHub Desktop.
Save rupeshtiwari/ae258a286d537ee9213a8da848c5f6eb to your computer and use it in GitHub Desktop.
installing kafka on macos

Installing and running Apache Kafka on macOS involves several steps because Kafka depends on Zookeeper for cluster management. Below are the steps to install Kafka and Zookeeper using Homebrew, create a Kafka topic, and verify that Kafka is running correctly.

Step 1: Install Homebrew

First, ensure that Homebrew is installed on your macOS. If not, you can install it by running the following command in the Terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Step 2: Install Kafka and Zookeeper

Kafka requires Zookeeper to run, so you'll need to install both. You can do this easily with Homebrew:

brew install kafka

image

This command installs both Kafka and Zookeeper because Kafka has Zookeeper as a dependency.

Step 3: Start Zookeeper

Before you start Kafka, you need to start Zookeeper. Homebrew makes it simple to start services:

brew services start zookeeper

image

Step 4: Start Kafka

Once Zookeeper is up and running, you can start Kafka:

brew services start kafka

image

Step 5: Verify Kafka and Zookeeper Are Running

You can check that Zookeeper and Kafka are running by looking at the list of services managed by Homebrew:

brew services list

image

You should see kafka and zookeeper in the list, each with a status of "started".

Step 6: Create a Kafka Topic

Now that Kafka is running, you can create a topic. Let's create a topic named "test" with a single partition and only one replica:

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

image

Step 7: Verify the Topic Creation

Verify that the topic "test" has been created successfully:

kafka-topics --list --bootstrap-server localhost:9092

image

You should see "test" listed among the topics.

Step 8: Test Producing and Consuming Messages

To ensure everything is set up correctly, you can test producing and consuming messages with the "test" topic.

  • Start a Kafka Consumer: Open a new Terminal window and run:
kafka-console-consumer --topic test --from-beginning --bootstrap-server localhost:9092
  • Produce Messages to the Topic: Open another Terminal window and run:
kafka-console-producer --topic test --bootstrap-server localhost:9092

image

Now, you can type messages into the producer terminal. Press Enter after each message, and you should see the message appear in the consumer terminal.

This confirms that Kafka is running correctly on your macOS, and you're ready to use it for your event sourcing and messaging needs in your applications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment