I am currently in the situation where I need to commit two transaction, one going towards the database (postgres, interacted with the npgsql library), and the one going on a kafka message bus (interacted with the confluent.kafka library).
Both support sending/inserting data in transaction, but I am currently having issues with determining how I should commit both the database transaction and messagebus transaction, since I need to perform a rollback on the other in case it fails.
My initial strategy was to do a
try
{
database.commit()
}
catch
{
messagebus.abort();
throw;
}
messagebus.commit()
but this then does not cover the case where committing changes to kafka fails, triggers a rollback.
Can I somehow ensure both cases in anyway?