Welcome to my Kafka learning series! Here, I'll share my journey with Apache Kafka, from setting up the environment to mastering the CLI and beyond. For a deeper dive into all things Kafka, check out the extensive collection of articles on Baeldung's Kafka tag.
Kafka is a powerful stream processing platform developed by the Apache Software Foundation, and I'll guide you through the essentials of getting started and effectively using it.
To quickly get Kafka up and running, Docker is an excellent choice. Here's a step-by-step guide:
I have created docker compose file for local setup.
docker-compose -f single-zookeeper-single-kafka.yml up -d-druns the Docker app in the background.-fspecifies the file, allowing you to skip the defaultdocker-compose.yml.
docker-compose -f single-zookeeper-single-kafka.yml psdocker exec -it kafka1 /bin/bashkafka-topics --versiondocker-compose -f single-zookeeper-single-kafka.yml stopdocker-compose -f single-zookeeper-single-kafka.yml downdocker exec -u root -t -i container_id /bin/bashFor a detailed setup guide, visit Conduktor's tutorial.
Create Topic
kafka-topics --bootstrap-server localhost:9092 --topic demo_topic --create --partitions 3 --replication-factor 1List Topics
kafka-topics --bootstrap-server localhost:9092 --listUse --exclude-internal to hide internal topics.
Describe Topic
kafka-topics --bootstrap-server localhost:9092 --describe --topic demo_topicAlter Topic (Increase Partitions)
kafka-topics --bootstrap-server localhost:9092 --alter --topic demo_topic --partitions 4Delete Topic
kafka-topics --bootstrap-server localhost:9092 --delete --topic demo_topicFor more on topic configurations, see the Kafka documentation.
Push Messages
kafka-console-producer --bootstrap-server localhost:9092 --topic demo_topicPush with Key
kafka-console-producer --bootstrap-server localhost:9092 --topic demo_topic --property parse.key=true --property key.separator=:Explore more with Conduktor's producer CLI tutorial.
Consume Messages
kafka-console-consumer --bootstrap-server localhost:9092 --topic demo_topicConsume from Beginning
kafka-console-consumer --bootstrap-server localhost:9092 --topic demo_topic --from-beginning --formatter kafka.tools.DefaultMessageFormatter --property print.timestamp=true --property print.value=trueLearn more about consumer CLI options on Conduktor.
Create Consumer Group
kafka-console-consumer --bootstrap-server localhost:9092 --topic topic_for_group_consumer --group my_first_applicationCheck Group Details
kafka-consumer-groups --bootstrap-server localhost:9092 --describe --group my_first_applicationReset Offsets
kafka-consumer-groups --bootstrap-server localhost:9092 --group my_first_application --reset-offsets --to-earliest --execute --topic topic_for_group_consumerContinue exploring consumer group management here.
Kafka Connectors simplify the integration between Kafka and other systems. For a vast selection, visit the Connectors hub. Start learning about Kafka Connect here.
Kafka isn't just about message passing; it's about building robust applications. Here are some great resources to get started:
- Kafka Programming Tutorials
- Java Kafka Programming
- Advanced Kafka Consumer with Java
- Spring Kafka on Baeldung
Stay tuned for more insights and tutorials on Kafka. Happy learning!