Exercise: Developing Kafka Consumer
- Read the javadoc of KafkaConsumer to know how to use the Consumer API (to consume messages from Kafka)
- Create a new Scala/sbt project in IntelliJ IDEA
- Define dependency for Kafka Clients API library
- Use mvnrepository to know the proper entry for
kafka-clients
dependency
- Write a Kafka consumer
- Name of the object: KafkaConsumerApp
- Start with an empty
Properties
object and fill out the missing properties per exceptions at runtime
- Use ConsumerConfig constants (not string values for properties)
- Don’t forget to
close
the consumer (so the messages are actually acknowledged to the broker)
- Run the Kafka consumer
- Use
kafka-console-producer
to produce messages
- Fix the slf4j logging errors
- Define dependencies for
slf4j-api
and slf4j-log4j12
in build.sbt
- Create
src/main/resources/log4j.properties
as the configuration file
- Use Apache Kafka’s
config/log4j.properties
as the sample (4 first non-comment lines)
Duration: 30 mins