Question

I am using NServiceBus to perform some work in a handler where information is saved to a database. As part of that process I send out a message over a web socket to tell clients to update their information.

The problem is that since the DB work is being performed in a transaction the clients receiving the web socket message may try read the data before the transaction has been committed, causing stale data to be returned.

Since the entire handler runs in a transaction scope it is not possible to only perform this work at the end of the transaction. Is there a hook to allow me to perform work after the transaction commits?

Alternatively I would like to create a "Transaction Publisher" where the publisher would enlist in the transaction, this however does not appear to be so straight forward.

What do you think is the best approach to solving this problem? Disabling transactions is not an option.

A similar problem would be experienced when trying to send a mail for instance. i.e. I only want the mail to go out once the transaction commits.

Était-ce utile?

La solution

As part of your current transaction, send a message to (yourself/another endpoint) telling it to e.g. send the mail, or contact the web socket.

The message will only actually be sent if the transaction commits - and then in the handler for that message, you can do the work that should happen after the original transaction committed.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top