I cannot comment on similar topic: TransactionId prefix for producer-only and read-process-write - ProducerFencedException so I will ask a new question.
Use case:
- One topic with 2 partitions
- Spring @KafkaListener with concurrency=1 (default) in consumer-group "sample-consumer-group"
- Two instances of the same application - both with the same "transaction-id-prefix"
1) I start first app instance (lets call it "instance1" - evenrything is ok - single consumer subscribes to both partitions. Log:
o.s.k.l.KafkaMessageListenerContainer : sample-consumer-group: partitions assigned: [sampleTopic-1, sampleTopic-0]
2) I start second app instance (instance2) - everything semms ok - log from this instance:
o.s.k.l.KafkaMessageListenerContainer : sample-consumer-group: partitions assigned: [sampleTopic-1]
log from "instance1":
o.s.k.l.KafkaMessageListenerContainer : sample-consumer-group: partitions revoked: [sampleTopic-1, sampleTopic-0]
o.s.k.l.KafkaMessageListenerContainer : sample-consumer-group: partitions assigned: [sampleTopic-0]
Still seems ok... But, when I then try to send message to any other topic (not from any kafkaListener, but from some @Transactional method - so this is producer only transaction) the following errors occur:
ERROR 4395 --- [roducer-tx-prefix-0] o.a.k.clients.producer.internals.Sender : [Producer clientId=producer-tx-prefix-0, transactionalId=tx-prefix-0] Aborting producer batches due to fatal error
org.apache.kafka.common.errors.ProducerFencedException: Producer attempted an operation with an old epoch. Either there is a newer producer with the same transactionalId, or the producer's transaction has been expired by the broker.
ERROR 4395 --- [roducer-tx-prefix-0] o.s.k.support.LoggingProducerListener : Exception thrown when sending a message with key='sync-register' and payload='2020-04-21T13:52:12.148412Z' to topic anotherTopic
So Is it related to the problem that I should have separate transaction-id-prefix for each instance for producer only transactions ? If yes, what is the current status of this and how to achieve this without using separate kafkaTemplate for for consumer started and producer started transactions ?