![]() |
The Apache Kafka is an open source stream processing platform developed by the Apache Software Foundation written in Scala and Java Programming. And It is designed to handle real time data feeds with high throughput, low latency, and durability. The Kafka is used to build real time data pipelines and streaming applications that can process data stream at scale. Running Kafka on Docker allows us to quickly set up a scalable Kafka environment, isolating it from our local machines environment and ensuring consistency across different development environments. Table of Content
TerminologiesHere we explain some Terminologies for understanding the Apache Kafka.
Step by Step Process to Set up Kafka on DockerHere we explain a step by step process to set up Kafka on Docker with examples and outputs for your reference. Step 1: Install DockerFirst ensure the Docker is installed on your machine. Otherwise you can download Docker from official website and follow the installation instructions for your operating system. ![]() Step 2: Create a Docker NetworkCreate a Docker network to allow the Kafka and Zookeeper container to communicate with each other. Below we provide the docker command for this. docker-compose.ymlversion: '3' Run below command docker compose -f docker-compose.yml up docker network create kafka-network
![]() docker Step 3: Start ZookeeperRun a Zookeeper container using Docker and The Zookeeper is a prerequisite for running Kafka. docker run -d --name zookeeper --network kafka-network -e ZOOKEEPER_CLIENT_PORT=2181 confluentinc/cp-zookeeper:latest ![]() Step 4: Start KafkaRun a Kafka container and link it to the Zookeeper container. docker run -d --name kafka --network kafka-network -e KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://localhost:9092 -e KAFKA_BROKER_ID=1 -e KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1 confluentinc/cp-kafka:latest
![]() Step 5: Verify Kafka InstallationTo ensure Kafka is running correctly and list all topics. docker exec -it kafka kafka-topics --list --zookeeper zookeeper:2181 ![]() ExampleHere we provide a example for your understanding purpose. Now creating a topic and sending a message. Create a Topicdocker exec -it kafka kafka-topics --create --topic test-topic --partitions 1 --replication-factor 1 --if-not-exists --zookeeper zookeeper:2181
Send a Messagedocker exec -it kafka kafka-console-producer --broker-list localhost:9092 --topic test-topic
Consume the Messagedocker exec -it kafka kafka-console-consumer --bootstrap-server localhost:9092 --topic test-topic --from-beginning
Output![]() Frequently Asked Questions1. Why do we need Zookeeper for Kafka?
2. Can I run Kafka without Docker?
3. What are the default ports used by Kafka and Zookeeper?
4. How can I scale Kafka using Docker?
5. What is the purpose of the kafka-network in the setup process?
ConclusionSetting up Kafka on Docker is a streamlined and efficient way to build a scalable and consistent Kafka environment by leveraging Dockers containerization capabilities and you can isolate your Kafka setup from the local machine. Ensuring consistency across different environments and simplifying the management of dependencies and configuration. Implementing Kafka on Docker not only saves time in setup but also offers the benefits of containerized applications such as easy scalability, portability and maintainability making it an excellent choice for developers. |
Reffered: https://www.geeksforgeeks.org
Apache Kafka |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |