Is this correct example for Kafka Transactions?
See original GitHub issueDescription
How I use Kafka Transactions in my code:
using IProducer<string, string> producer = new ProducerBuilder<string, string>(_producerConfig).Build();
producer.InitTransactions(_defaultTransactionTimeout);
_consumerConfig.AutoOffsetReset = AutoOffsetReset.Earliest;
using var consumer = new ConsumerBuilder<string, string>(_consumerConfig).Build();
consumer.Subscribe(_consumeTopic);
while (!stoppingToken.IsCancellationRequested)
{
var consumeResult = consumer.Consume(stoppingToken);
producer.BeginTransaction();
producer.Produce(_produceTopic, new Message<string, string> {... });
producer.SendOffsetsToTransaction(new List<TopicPartitionOffset> { consumeResult.TopicPartitionOffset}, consumer.ConsumerGroupMetadata, _defaultTransactionTimeout);
producer.CommitTransaction(_defaultTransactionTimeout);
}
Is this correct way to use Kafka Transactions? It works most of the time but sometimes it fails with error below:
%1|1609846051.178|TXNERR|rdkafka#producer-2| [thrd:main]: Fatal transaction error: Failed to add offsets to transaction: Broker: Producer attempted an operation with an old epoch (INVALID_PRODUCER_EPOCH)
%3|1609846051.178|ERROR|rdkafka#producer-2| [thrd:main]: Fatal error: Broker: Producer attempted an operation with an old epoch: Failed to add offsets to transaction: Broker: Producer attempted an operation with an old epoch
How to reproduce
Checklist
Please provide the following information:
- A complete (i.e. we can run it), minimal program demonstrating the problem. No need to supply a project file.
- [* ] Confluent.Kafka nuget version.
- Apache Kafka version.
- Client configuration.
- Operating system.
- Provide logs (with “debug” : “…” as necessary in configuration).
- Provide broker log excerpts.
- Critical issue.
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Transactions in Apache Kafka
The transaction feature is primarily a server-side and protocol level feature which is available for use by any client library that supports it....
Read more >Kafka Transaction
In consumer-side transaction, kafka consumer consumes avro messages from the topic, processes them, save processed results to the external db ...
Read more >Kafka Transactions and Exactly-Once Processing
Kafka transactions enable atomic writes to multiple Kafka topics and partitions. Inside a transaction, a producer writes records to the Kafka topic ......
Read more >How do transactions work in Apache Kafka? - Łukasz Chrząszcz
When you first encounter Kafka, you will face either at-least-once, or at-most-once guarantees, depending on when you commit your offsets.
Read more >Kafka Transactional Producer - Progress Documentation
A transaction is a way to group messages, so that all the messages in the group remain invisible to consumers, until all have...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I got it resolved by increasing the producer TransactionTimout setting
@mhowlett and @koshdim ,
Even i too face the INVALID_PRODUCER_EPOCH error. Am running the my application in Windows 10 machine. I have a single Producer and TransactionId is Random Guid, enabled Idempotence as well. No other instance of the application or same TransactionId is used. When i try to Commit in case of successful message processing or Abort in case of failure while message processing i am getting the error.
I have disabled AutoCommit and AutoOffsetStore as well in the consumer settings
Below is the Debug log for the same
Could please provide input for the same.