Reputation: 82341
I am working with a medical system that (among other things) will handle updates to patient data.
We are going to try to scale our system out to more than one machine to improve performance.
However, I have a worry that distributing messages could cause updates in the wrong order.
Here is an Example:
The top two messages on my MSMQ are update requests for a patient. The first one changes the middle name to "Bob", the second one changes the middle name to "Bill". (So in the end the middle name should be "Bill".)
I have a distrubtor setup to send messages to MachineA and MachineB. Both are able to handle messages, but MachineA is a much slower machine (or has other processes that load it down or is slower for some other reason).
If the distributor sends the first message to MachineA and the second to MachineB then the MachineB message will finish first and update the name to "Bill". Then MachineA finishes and the middle name is updated to "Bob".
So I end up with "Bob" as the middle name instead of "Bill".
I need a way to tell the distributor that these two messages should go to the same machine and same thread. Logic wise it is not hard to do, but I need a way to plug into the distributor to do it.
The Logic I would want to do would be like this: The Distributor would keep a list of Patient Ids that the queues are working on and then check new messages for that ID as well. If any of the queues are working on that Id then it either waits until it is done or just make sure the same queue gets the message.)
Or, does NServiceBus some how make sure that these transactions will only commit in order? (I am using Distributed Transactions.)
Upvotes: 0
Views: 180
Reputation: 6050
When you .Send() messages with NSB you can send and array of IMessage. This will send over a batch of messages that will be handled in the context of a single transaction. The messages should be handled in order.
Upvotes: 1