Axon-kafka ProducerFencedException

We have two services set up to communicate utilizing Kafka as our event bus (using axon-kafka and axon-kafka-spring-boot-starter). They are both pointed to the same topic for inter-service communication. Randomly we will see our publishers fail with an error message similar to the following:

org.apache.kafka.common.errors.ProducerFencedException: Producer with transactionalId 'null0' and ProducerIdAndEpoch(producerId=69453, epoch=695) has been fenced by another producer with the same transactionalId
org.apache.kafka.common.errors.ProducerFencedException: There is a newer producer with the same transactionalId which fences the current one.

There doesn’t seem to be much of a pattern as to when this occurs. Can’t quite figure out what’s going on here and wondering if anyone has any insight into this problem

Would it be an option not to use the transactional confirmation mode? I can imagine with a high load, creating a lot of producers, they might have a conflict sometimes. And I don’t understand the advantages of having Kafka transactions for this use case.

Thanks for the response Gerard! For completeness in case someone else runs into this it was caused by a missing property to ensure transactionIds are unique: axon.kafka.producer.transaction-id-prefix. Set this to ${spring.application.name} in both services and we were good to go.

1 Like