views:

128

answers:

2

Hi , We are using NService bus for our messaging framework.Sometime the message is not coming as par the sequence of sending .Sometimes last message is coming first and than later first message.

Please help me out Thanks

+1  A: 

The nature of NServiceBus does not guarantee that messages will be received in the order they were sent. Each message is meant to be processed independently.

If an action can only be undertaken after two related messages arrive, then you need to utilize a Saga: http://www.nservicebus.com/Sagas.aspx

Edit in response to first comment:

You mention you're sending the same message in chunks. Does this mean that you have a large payload that you have to split up into multiple parts to transmit via MSMQ?

If so, you have a few options:

  1. Store the payload out of band, in a database or file system, and only put enough data in one message (an ID or file system path) to load the data from the message handler.

  2. Make the message a MessagePart that contains a BundleID, PartNumber, TotalParts, and PayloadChunk. Then, create a saga for MessagePart that stores each part and when all parts have been received, reconstitute the chunks together and do what you need. Of course, if you need to then send the resulting large object back onto the Bus, this would get annoying really quickly, so then the out-of-band option would look much more attractive.

In any case, there are a ton of reasons why any MSMQ message, not just NServiceBus messages, could arrive out of order, so you have to be able to deal with it.

David
Thnx for ur answer david,but in my application i m sending same message in chunks .the sequence is like first message thn 2nd and so on.Tht y i m wondering when we are sending same message to same queuesoo as per MSMQ behaviour it should come in sequence
A: 

Would Bus.Sending a collection of Imessages work? NServiceBus allows batching of messages

Adam Fyles
There is still the limit of 4MB per MSMQ message, regardless of how many logical messages are in there.
Udi Dahan