Hi,

Thanks for your work and sorry to bother you.

My code gets the same IllegalStateException from KafkaProducer as Kafka Stream 
gets in KAFKA-16221:

java.lang.IllegalStateException: Cannot attempt operation `abortTransaction` 
because the previous call to `commitTransaction` timed out and must be retried
    at 
org.apache.kafka.clients.producer.internals.TransactionManager.handleCachedTransactionRequestResult(TransactionManager.java:1109)
    at 
org.apache.kafka.clients.producer.internals.TransactionManager.beginAbort(TransactionManager.java:266)
    at 
org.apache.kafka.clients.producer.KafkaProducer.abortTransaction(KafkaProducer.java:835)

I have followed the recipe from 
https://kafka.apache.org/37/javadoc/org/apache/kafka/clients/producer/KafkaProducer.html
for error handling for a transactional producer, i.e.

 try {
     producer.beginTransaction();
     for (int i = 0; i < 100; i++)
         producer.send(new ProducerRecord<>("my-topic", Integer.toString(i), 
Integer.toString(i)));
     producer.commitTransaction();
 } catch (ProducerFencedException | OutOfOrderSequenceException | 
AuthorizationException e) {
     // We can't recover from these exceptions, so our only option is to close 
the producer and exit.
     producer.close();
 } catch (KafkaException e) {
     // For all other exceptions, just abort the transaction and try again.
     producer.abortTransaction();
 }
 producer.close();

Kafka Streams has solved KAFKA-16221 by introducing a hack 
(https://github.com/apache/kafka/pull/15315), but plans a clean solution.

Does that mean that above recipe is outdated?
Is there really no simple, clean solution how to do the error handling?
Should I use the solution from https://github.com/apache/kafka/pull/15315 and 
wait for what Kafka Streams comes up next for the clean solution?

Kind regards, Matthias Kraaz

Reply via email to