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
Asked
Active
Viewed 295 times
0
-
Pl go thru the existing answered questions on this. https://stackoverflow.com/questions/3507624/mongodb-nosql-keeping-document-change-history – Venkat Aug 11 '22 at 11:02
2 Answers
0
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.

Sheel Prabhakar
- 409
- 2
- 6
0
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

OneCricketeer
- 179,855
- 19
- 132
- 245