1

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.

4

1 回答 1

4

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.

于 2013-07-12T07:27:13.147 回答