Description
If you want to capture the last committed offsets of a Kafka Streams group that no longer has any members (for example, to start a new version of the application with a different application.id from the same position), this article applies to you.
In this situation kafka-streams-groups --describe --offsets prints nothing:
kafka-streams-groups --bootstrap-server <host:port> --command-config client.properties \ --group <app.id> --describe --verbose --offsets
The offsets are not lost. They are still stored on the broker, but the command only shows them while the group has active members.
Applies To
Kafka Streams clients configured with group.protocol = streams
Cause
This is a known limitation of the kafka-streams-groups tool, tracked as KAFKA-21591.
Resolution
Use --reset-offsets --to-current --dry-run. --to-current means "reset to where the group already is", and --dry-run guarantees nothing is changed. The offsets printed are the ones currently committed.
1. Print the committed offsets
kafka-streams-groups --bootstrap-server <host:port> --command-config client.properties \ --group <app.id> --reset-offsets --all-input-topics --to-current --dry-run
Output columns: GROUP / TOPIC / PARTITION / NEW-OFFSET. Check that every input partition is listed.
2. (Optional) Export them to a CSV file
Add --export to get topic,partition,offset lines:
kafka-streams-groups --bootstrap-server <host:port> --command-config client.properties \ --group <app.id> --reset-offsets --all-input-topics --to-current --export --dry-run > offsets.csv
3. (Optional) Start a new group from the same offsets
Before starting the application with the new application.id, load the CSV into the new group:
kafka-streams-groups --bootstrap-server <host:port> --command-config client.properties \ --group <new.app.id> --reset-offsets --from-file offsets.csv --execute
References
- KIP-1071: https://cwiki.apache.org/confluence/display/KAFKA/KIP-1071%3A+Streams+Rebalance+Protocol
- KAFKA-21591: https://issues.apache.org/jira/browse/KAFKA-21591
- Apache Kafka docs, Kafka Streams Groups Tool: https://kafka.apache.org/43/streams/developer-guide/kafka-streams-group-sh/