I am inserting some data to mongo with springboot application, after that I send this data to kafka. I want to be sure that before I send them to kafka they are commited to mongo. Is there a way I can ensure that this data is commited before sending them to kafka? Thank you
2
Answers
MongoDB 4 supports transactions https://spring.io/blog/2018/06/28/hands-on-mongodb-4-0-transactions-with-spring-data
If using this version then you can have commit and rollback.
Earlier MongoDB doesn’t support the transaction, so your spring Mongorepository insert call will return after a successful insert. Why do you need to check for commit?
If want to make sure then read that document by ID.
Simply don’t do two-phase commits.
Use external processes like Debezium or Mongo Kafka Source Connector to read the data directly from Mongo into Kafka topics