You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@kafka.apache.org by Paweł Szymczyk <pa...@gmail.com> on 2025/02/19 17:17:40 UTC
Kafka Producer send offsets to transaction method confusion
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.
--
Pozdrawiam
Paweł Szymczyk
Re: Kafka Producer send offsets to transaction method confusion
Posted by "Matthias J. Sax" <mj...@apache.org>.
It would be best if you would comment about it on the Jira ticket and we
can take it from there.
I cannot (and to be honest, also don't want to) make a call on this, but
hope that you and the other person can figure it out, who works on it...
Happy to moderate the discussion of course, if necessary.
-Matthias
On 2/20/25 2:24 AM, Paweł Szymczyk wrote:
> https://github.com/apache/kafka/pull/18977
>
> czw., 20 lut 2025 o 07:48 Paweł Szymczyk <pa...@gmail.com>
> napisał(a):
>
>> Sure, I would love to continue working on this task and provide an
>> interface, I see that someone else has been assigned to Jira recently,
>> please let him know that I like to handle it on my own 🙂
>>
>>
>> Dnia 20 lutego 2025 03:51:02 CET, "Matthias J. Sax" <mj...@apache.org>
>> napisał/a:
>>
>>> 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.
>>>>
>>>>
>>> Paweł Szymczyk
>>
>
>
Re: Kafka Producer send offsets to transaction method confusion
Posted by Paweł Szymczyk <pa...@gmail.com>.
https://github.com/apache/kafka/pull/18977
czw., 20 lut 2025 o 07:48 Paweł Szymczyk <pa...@gmail.com>
napisał(a):
> Sure, I would love to continue working on this task and provide an
> interface, I see that someone else has been assigned to Jira recently,
> please let him know that I like to handle it on my own 🙂
>
>
> Dnia 20 lutego 2025 03:51:02 CET, "Matthias J. Sax" <mj...@apache.org>
> napisał/a:
>
>> 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.
>>>
>>>
>> Paweł Szymczyk
>
--
Pozdrawiam
Paweł Szymczyk
Re: Kafka Producer send offsets to transaction method confusion
Posted by Paweł Szymczyk <pa...@gmail.com>.
Sure, I would love to continue working on this task and provide an interface, I see that someone else has been assigned to Jira recently, please let him know that I like to handle it on my own 🙂
Dnia 20 lutego 2025 03:51:02 CET, "Matthias J. Sax" <mj...@apache.org> napisał/a:
>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.
>>
>
Paweł Szymczyk
Re: Kafka Producer send offsets to transaction method confusion
Posted by "Matthias J. Sax" <mj...@apache.org>.
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.
>