skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search