1

I have an example Spring Boot application saving a document to MongoDB using Spring's MongoRepository. After that, I write a message to a Kafka topic.

What I want is to rollback the MongoDB transaction when the Kafka write fails.

Do I have other options than XA transactions?

underscore_d
  • 6,309
  • 3
  • 38
  • 64
JointEffort
  • 583
  • 7
  • 21

1 Answers1

1

Kafka does not support XA transactions.

You can use a ChainedKafkaTransactionManager with the mongo tm and a KafkaTransactionManager (in that order); if the Kafka transaction commit fails, the mongo transaction will roll back.

See Transactions and the Chained Transaction Manager.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179