Current Implementation
I have a spring batch job which writes to a kafka topic. I read records from the database, transform them and writes to the kafka topic.
New Changes to the existing job
I am suppose to write to one more audit topic along with the main topic.
For each record read from the database, I am writing a message of say Class Abc type to the main topic and for the same record I am suppose to write the message of another Entity Class Type to the audit topic.
Problem Statement
Currently, I am using different KakfaTemplate to write to both the topics but the issue is how to handle If job fails after writing to the main topic and it never writes to the audit topic. How to rollback the transaction (I haven't implemented transaction in the current implementation).
Do I need to change whole implementation of my application?? Shall I write to both the topics in a single transaction or there is any solution for my current implementation?
Transaction Manager
@Override
protected JobRepository createJobRepo(){
JobRepositoryFactoryBean fac = new JobRepositoryFactoryBean;
fac.setDataSource(ds);
fac.setTransactionManger(transactionManger);
fac.set();
return fac.getObject();