Kafka on MAC
Harnessing the Power of Apache Kafka on Your Mac
Apache Kafka has become invaluable for building scalable, fault-tolerant, real-time data streaming applications and platforms. If you’re a developer or data engineer using a Mac, you’re lucky; setting up and running Kafka on your machine is relatively straightforward.
Prerequisites
- Java: Kafka is a Java-based system, so you must install the Java Development Kit (JDK). Version 8 or later is recommended. You can check if Java is installed by running your terminal’s Javathe Java version. If not, download the JDK from Oracle’s website.
- Homebrew (Optional): While not strictly required, Homebrew is the most convenient way to manage software packages on macOS. If you don’t have Homebrew, follow the instructions on their website to install it.
Installation
There are two main ways to install Kafka on your Mac:
1. Manual Download
- Visit the Apache Kafka downloads page:
- Download the latest binary release (choose a Scala version that aligns with your project).
- Extract the downloaded tar file:
- Bash
- tar -xzf kafka_2.13-3.0.0.tgz
- Use code
- content_copy
- Move the extracted folder to a convenient location like /usr/local/Kafka.
2. Using Homebrew
- Open your terminal and run:
- Bash
- brew install Kafka
- Use code
- content_copy
Starting the Servers
The Kafka system relies on two core components:
- ZooKeeper: A coordination service that manages the Kafka cluster.
- Kafka Broker: The core Kafka server that handles message streams.
- Start ZooKeeper:
- Manual: Navigate to the Kafka directory and run:
- Bash
- bin/zookeeper-server-start.sh config/zookeeper.properties
- Use code
- content_copy
- Homebrew:
- Bash
- zkServer start
- Use code
- content_copy
- Start Kafka Broker:
- Manual: Open a new terminal, navigate to the Kafka directory, and run:
- Bash
- bin/kafka-server-start.sh config/server.properties
- Use code
- content_copy
- Homebrew:
- Bash
- Kafka-server-start
- Use code
- content_copy
Creating a Topic
A topic is a category or feed to which you publish and subscribe messages in Kafka.
- In a new terminal, navigate to your Kafka directory.
- Run the following command:
- Bash
- bin/Kafka-topics.sh –create –topic quickstart-topic –bootstrap-server localhost:9092
- Use code
- content_copy
- (Replace ‘quickstart-topic’ with your desired topic name)
Testing
- Producer:
- Bash
- bin/kafka-console-producer.sh –topic quickstart-topic –broker-list localhost:9092
- Use code
- content_copy
- Start typing messages and hit enter to send them.
- Consumer:
- Bash
- bin/Kafka-console-consumer.sh –topic quickstart-topic –from-beginning –bootstrap-server localhost:9092
- Use code
- content_copy
- You should see the messages you typed in the producer.
Beyond the Basics
This blog has given you a quick start. Kafka offers rich features:
- Kafka Connect: Integrate with databases and external systems.
- Kafka Streams: Real-time stream processing capabilities.
- Configuration: Explore to optimize performance.
Stopping Kafka
Run these (using the correct method depending on how you installed Kafka):
Bash
bin/kafka-server-stop.sh
bin/zookeeper-server-stop.sh
Conclusion:
Unogeeks is the No.1 IT Training Institute for Apache kafka Training. Anyone Disagree? Please drop in a comment
You can check out our other latest blogs on Apache Kafka here – Apache kafka Blogs
You can check out our Best In Class Apache Kafka Details here – Apache kafka Training
Follow & Connect with us:
———————————-
For Training inquiries:
Call/Whatsapp: +91 73960 33555
Mail us at: info@unogeeks.com
Our Website ➜ https://unogeeks.com
Follow us:
Instagram: https://www.instagram.com/unogeeks
Facebook: https://www.facebook.com/UnogeeksSoftwareTrainingInstitute
Twitter: https://twitter.com/unogeek