An example of a consumer Java application that consumes events from an Apache Kafka broker
- Have installed Apache Kafka (see How to run it sing Docker)
- Create a topic in the broker. i.e.:
topic1
- Optionally, start a producer (i.e.: https://github.com/lealceldeiro/kafkaproducer)
Run ./mvnw compile exec:java -Dexec.mainClass="com.kafkaexamples.kafkaconsumer.KafkaConsumerMain" -Dexec.args="localhost:9094 1 topic1"
- Check the console as messages (consumed from the broker) start to appear
- Type
/exit
and press enter to stop the program (it may take a while to completely shut down gracefully -- wait patiently)
Note: replace the provided arguments with the correct values for your Kafka cluster. In the previous example:
localhost:9094
is the broker url1
is the number of consumers to be startedtopic1
is the topic name to subscribe to