Duration: 30 mins
Read the javadoc of KafkaConsumer and ConsumerConfig
Properties object with bootstrap.servers,
key.deserializer, value.deserializer, and group.id=order-consumerKafkaConsumer[String, String] and subscribes to topic orderswhile (true) loop calling
poll(Duration.ofMillis(500)),
printing each ConsumerRecord’s key, value, partition and offsetRun OrderProducerApp from Exercise 03 in one terminal and OrderConsumerApp in another. Confirm every record is printed.
Stop the consumer (Ctrl+C) and restart it. Predict first whether it
re-reads the records it already saw, then run it and check — explain
the result in terms of auto.offset.reset and committed offsets (the
default group.id here means it’s a new run of the same group, so
it resumes from the last committed offset, not from the beginning)
Change auto.offset.reset to earliest, pick a brand-new group.id,
and re-run — confirm it now replays the whole topic from the start
Discuss: what’s the difference between auto.offset.reset and
enable.auto.commit? (One decides where a new group starts; the
other decides whether/how often offsets are written back to Kafka.)
enable.auto.commit=false and add explicit commitSync() after each batch.client.id to make the consumer identifiable in kafka-consumer-groups --describe.