Skip to content

thoqbk/kafka-plain-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kafka plain java

With 5 demos, this article helps readers to understand fundamental concepts in Kafka

Kafka terminology

There are some key terms using in Kafka:

  • Topic: Kafka messages are organized into topics. To consume messages, consumers need to specify the topic they want to read from. Same for producers when writing messages
  • Partition: each topic has 1 or more paritions. Based on the key of the message, Kafka decides which partition the message is located. Also, with proper configuration, Kafka can replicate partitions to multiple machines to improve read performance and data recovery ability

Prerequisites

We need to have the following items ready to be able to run through the demos:

  • JDK 11+
  • Follow step 1 and 2 to install and test Kafka on your local
  • Install Docker on your local. Lately we will use this to setup a Kafka cluster on Docker which is convenient for testing
  • Clone the repository kafka-plain-java to prepare for experiments

There are some important files in this repository:

  • demo.jar: runnable jar file. Some commands we will use in demos:
Command Description
java -jar demo.jar --mode c --id "Consumer 2" to start a consumer with id Consumer 2. Using --mode p to start a producer
java -jar demo.jar --mode c --topic topic-demo3 --bootstrap-server localhost:29092 to start a consumer, connect to localhost:29092 and consume messages in topic topic-demo3
  • RunnableConsumer.java: to consume messages when running with --mode c
  • RunnableProducer.java: to produce messages when running with --mode p

Demos:

References

About

To explore how Kafka works

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages