简体   繁体   中英

MSMQ: Is it possible to consume the message in the same order as they were being sent?

Let say I have a queue Q ,Q is the destination of message. I know that MSMQ guarantees that multi messages encompassed in the transaction are received in the same order in which they were sent.But my application send one message per transaction to Q( messages have same destination ).Can messages order still being preserved when it reach Q?

Yes, you should be OK although it may depend on how flaky the network is. MSMQ uses internal ack messages to ensure messages are successfully delivered. The retry mechanism will handle any lost messages. It may be possible, depending on retry window size, etc., for a lost message to be delayed behind the following message.

I can also imagine it may be possible for one message to get ahead of another - for example, a 1kb message following a 4MB message - due to the time it takes for a message to be persisted from the network stack to the disk.

Both scenarios are edge cases, though.

Bottom line is that order is not guaranteed outside a transaction so, if your app depends on it, make sure the messages contain a sequence number of some kind.

Make sure your servicebehaviour is decoraated with EnsureOrderedDispatch:=true

Here is the link that Microsoft is confirmed with

https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/ordered-processing-of-messages-in-single-concurrency-mode

Have a look at this stackoverflow question . It does refer to multiple clients, but the content of the post might be useful to you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM