Thanks for reaching out. This is actually very good feedback.
In general, it seems that `ConsumerGroupMetadata` should be an
interface, not a class, making it impossible for users to create an
instance.
Of course, we cannot do anything for older releases, and it seems the
JavaDocs do explain it correctly...
But I did file https://issues.apache.org/jira/browse/KAFKA-18836 -- feel
free to pick it up if you have interest to contribute a fix for Apache
Kafka 4.1 release.
-Matthias
On 2/19/25 9:17 AM, Paweł Szymczyk wrote:
Hello!
Recently, I had an opportunity to work with legacy code that was using an
old version of the Kafka native producer transactional API. Our goal was to
upgrade the code to the newest version and benefit from the upgraded
transactional API protocol. Initially, we found code that was highlighted
as deprecated (
https://kafka.apache.org/25/javadoc/org/apache/kafka/clients/producer/Producer.html#sendOffsetsToTransaction-java.util.Map-java.lang.String-
):
kafkaProducer.sendOffsetsToTransaction(Map.of(new
TopicPartition(record.topic(), record.partition()), new
OffsetAndMetadata(record.offset())), groupId);
Our first approach was to use the non-deprecated API:
kafkaProducer.sendOffsetsToTransaction(Map.of(new
TopicPartition(record.topic(), record.partition()), new
OffsetAndMetadata(record.offset())), new ConsumerGroupMetadata(groupId));
A few days later, after an extensive testing session, we finally read the
new sendOffsetsToTransaction method javadoc and discovered that we needed
to retrieve metadata from the Kafka Consumer.
From our perspective, this upgrade process was more complicated than
expected and requires broad knowledge of the transactional protocol
upgrade. Are there any contradictions in making the public
ConsumerGroupMetadata(String
groupId) constructor deprecated too? It would have given us a clear hint
that we were still doing something wrong from the start.