https://github.com/colinbut/kafka-java-example
Kafka example using Java
https://github.com/colinbut/kafka-java-example
java java-8 kafka kafka-topic
Last synced: over 1 year ago
JSON representation
Kafka example using Java
- Host: GitHub
- URL: https://github.com/colinbut/kafka-java-example
- Owner: colinbut
- Created: 2018-08-25T22:10:12.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-12-05T15:20:17.000Z (over 7 years ago)
- Last Synced: 2025-02-01T14:46:16.387Z (over 1 year ago)
- Topics: java, java-8, kafka, kafka-topic
- Language: Java
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Kafka Java Example
This repository showcase using Kafka with vanilla Java.
### Start Kafka & Create the Topics
Follow the example commands in the `kafka-cli-commands.txt` which can be found under the `src/main/resources` folder.
### One Producer - One Consumer Group with Multiple Consumer Instances
Under this example, we should expect each individual consumer instances within the One Consumer Group to pick up messages from the
Kafka topic. The messages would be shared between the different consumer instances. This allows load balancing of Consumer messages.
1) Run the `ProducerApp.java`
....
Ensure `KafkaConfig.java` has same GROUP_ID_CONFIG for all Kafka Consumer instances - change if needed
2) Run as many `ConsumerApp.java` as needed
When running say 5 partitions, you should expect the 5 partitions to be shared amongst the Kafka consumer instances.
### One Producer - Multiple Consumer Group each with One Consumer Instance
Under this example, we should expect the same message to be delivered to each Consumer Group. Effectively this enables a
more publisher-subscriber communication model because the messages are being broadcast to each Consumer Groups. Each consumer group
is particularly an individual separate consumer of the Topic.
The consumer instances within the Consumer Groups still follow the same rules as above example such that the message will be
load balanced amongst the individual consumer instances.
1) Run the `ProducerApp.java`
....
Change `KafkaConfig.java` to have a different (unique) GROUP_ID_CONFIG for all Kafka Consumer instances
2) Run as many `ConsumerApp.java` as needed
Regardless of the number of partitions, you should expect all the messages to be broadcast to all participating
Consumer Groups.