DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

SBOMs are essential to circumventing software supply chain attacks, and they provide visibility into various software components.

Related

  • Next-Gen Data Pipes With Spark, Kafka and k8s
  • Harnessing Real-Time Insights With Streaming SQL on Kafka
  • Real-Time Analytics: All Data, Any Data, Any Scale, at Any Time
  • Building Real-Time Applications to Process Wikimedia Streams Using Kafka and Hazelcast

Trending

  • The Evolution of Software Integration: How MCP Is Reshaping AI Development Beyond Traditional APIs
  • Seata the Deal: No More Distributed Transaction Nightmares Across (Spring Boot) Microservices
  • Build Real-Time Analytics Applications With AWS Kinesis and Amazon Redshift
  • The Rise of the Intelligent AI Agent: Revolutionizing Database Management With Agentic DBA
  1. DZone
  2. Data Engineering
  3. Big Data
  4. Real-Time Stream Processing With Apache Kafka Part 3: Setup a Single Node Kafka Cluster

Real-Time Stream Processing With Apache Kafka Part 3: Setup a Single Node Kafka Cluster

Create a single node Kafka Cluster with ZooKeeper.

By 
Satish Sharma user avatar
Satish Sharma
·
Jul. 29, 19 · Tutorial
Likes (6)
Comment
Save
Tweet
Share
16.5K Views

Join the DZone community and get the full member experience.

Join For Free

In the first article, we introduced Apache Kafka, and in the previous article, we discussed the Kafka Streams API. In this article, we will learn how to set up a single node Kafka Cluster on our local machine.

Environment

Below is the environment I used for the setup.

  1. Apache Kafka (kafka_2.12-2.1.0).

  2. Apache ZooKeeper (ZooKeeper-3.4.12).

  3. Windows Operating System (with commands given for Linux).

The steps mentioned should be valid with other versions as well without much change. Please refer to the official documentation if you have any issues.

Set Up ZooKeeper

Kafka needs ZooKeeper to run. So, first, we need to set up and start ZooKeeper. There are two options for setting up ZooKeeper.

  • For quick and easy setup, Kafka is distributed bundled with Zookeeper. You can get a quick-and-dirty single-node Zookeeper instance. The convenience script is there in the bin folder of the Kafka distribution.

Linux -> bin/zookeeper-server-start.sh config/zookeeper.properties
Windows -> bin\windows\zookeeper-server-start.bat <Path to config file>


  • You can also download the full-fledged ZooKeeper distributions from the download page of the official release, Un-tar the distribution, and start a ZooKeerp server.

Linux -> bin/zkServer.sh <Path to config file>
Windows -> bin\zkServer.cmd <Path to config file>

start zookeeper

Start ZooKeeper


Set Up Kafka   

Download Kafka from the official release downloads page and un-tar the distribution (on windows use utilities like 7zip).

tar -xzf kafka_2.11-2.1.0.tgz


Edit the file "server.properties" present in "config" directory. You can create a copy of the file as well. You need to update the property "log.dirs" to a location where the logs shall be persisted on the file system.

"log.dirs" = <Folder location to be used for persisting logs> 

For example:

    Linux ->  log.dirs=/tmp/kafka-logs
    Windows -> log.dirs= C:\tmp



Log command for Linux

Log command for Linux


Start the server by following command in the bin directory

Linux -> bin/kafka-server-start.sh config\server.properties
Windows -> kafka-server-start.bat ..\..\config\server.properties


If your configuration files are valid, then Kafka will start at pre-configured port. Port 9092 is the default port.

Kafka server

Kafka server


Test Your Created Cluster

Create a topic in Kafka

Use the following command to create a topic.

kafka-topics.sh  --create --zookeeper <zookeeper_host>:<zookeeper_port> --replication-factor <factor> --partitions <partition> --topic <topic-name>


Linux ->  bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic tutorial-topic
Windows -> bin\windows\kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1  --topic tutorial-topic


Type the message that you want to publish to the Kafka topickafka create topic

Kafka created topic

This will create a topic named "tutorial-topic" with the replication of one. 

Send Records to a Newly Created Topic

We will use the Kafka console producer to send some messages to the topic we created in the earlier step. 

Linux -> bin/kafka-console-producer.sh --broker-list localhost:9092 --topic tutorial-topic
Windows -> bin\windows\kafka-console-producer.bat --broker-list localhost:9092 --topic tutorial-topic
<type your message>


Kafka console producer

Kafka console producer

Consume Records Using Console Consumer

For quick testing, let's start a handy console consumer, which reads messages from a specified topic and displays them back on the console. We will use the same to consumer to read all of our messages from this point forward. Use the following command: 

Linux -> bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic tutorial-topic --from-beginning
Windows -> bin\windows\kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic tutorial-topic --from-beginning


If your settings are valid, then you should be able to see the messages that you publish to the topic.

Test message

Test message


In this article, we have set up a single node Kafka Cluster on our local machine. In the next article, we will discuss a use case for real-time analytics using Kafka streams.

Please share any comments/feedback you may have!

kafka cluster Stream processing

Opinions expressed by DZone contributors are their own.

Related

  • Next-Gen Data Pipes With Spark, Kafka and k8s
  • Harnessing Real-Time Insights With Streaming SQL on Kafka
  • Real-Time Analytics: All Data, Any Data, Any Scale, at Any Time
  • Building Real-Time Applications to Process Wikimedia Streams Using Kafka and Hazelcast

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: