Reputation: 343
We have an existing application which is using spring batch. As per new requirement, we need to write a row to cassandra db by reading it from mongo db and then updating the status column in mongo db to true which signifies row is processed.
I am using driver-cassandra-core library to write data into Cassandra and spring-data-mongodb to update data in mongo db.
So now I am thinking to write data to cassandra and then update status in mongo within ItemWriter(spring-batch) which I think should work fine in happy scenario.
But I am not sure if this work well if something goes wrong with application like if db(cassandra or mongo) goes down or application goes down during processing etc. So I want to add transaction manager here which make sure application is able to rollback rows which is not in consistent state. I have seen it is possible to add transaction manager like this below:
https://docs.spring.io/spring-batch/trunk/reference/html/configureStep.html#configuringAStep
But I am not sure as I am using two different No SQL database, is it possible to make this transaction manager work to make sure ?
Can some one please let me know what is the proper way to handle such situation?
P.S: Just to update it is very important for an application to keep cassandra and mongo status in synch i.e if application writes data to cassandra then corresponding row status should be updated in mongo.
Upvotes: 0
Views: 131
Reputation: 21463
I can't speak to Cassandra, but I believe MongoDB won't participate in a transaction managed by a PlatformTransactionManager
. Because of that, you're going to need to use listeners to implement compensating logic to emulate a rollback. What I'd suggest is using a CompositeItemWriter
for the writes to both data sources, then using a ChunkListener#afterChunkError
to implement compensating logic to emulate a rollback on an error.
Upvotes: 1