Imagine the situation:
var txn = new DatabaseTransaction();
var entry = txn.Database.Load<Entry>(id);
entry.Token = "123";
txn.Database.Update(entry);
PublishRabbitMqMessage(new EntryUpdatedMessage { ID = entry.ID });
// A bit more of processing
txn.Commit();
Now a consumer of EntryUpdatedMessage
can potentially get this message before the transaction txn
is committed and therefore will not be able to see the update.
Now, I know that RabbitMQ does support transactions by itself, but we cannot really use them because we create a new IModel
for each publish and having a per-thread model is really cumbersome in our scenario (ASP.NET web application).
I thought of having a list of messages due to be published when a DB transaction is committed, but that's a really smelly solution.
What is the correct way of handling this?