DavidBoike / feedback

Ask me anything!
0 stars 0 forks source link

Problem when consuming messages in order in msmq #4

Closed Javier13 closed 6 years ago

Javier13 commented 6 years ago

Hi David. I am learning to use nservicebus and your book is very helpful. Thank you.

I would appreciate it if you would please advise me on the following problem I have in MSMQ queue treatment:

In my system, to process the messages in the MSMQ queue in order is very important, very critical. For example, if I have four messages in the queue:

message4 | message3 | message2 | message1, where:

If an error occurs when processing message1, and after retries continue to fail, message1 is inserted into the error queue. Next, message2 and message 3 are processed without error. Finally, message4 can not be processed because message1 failed and they belong to the same group (internally they have the same code)

A possible solution is to store the erroneous messages in a database and look there before processing a message if there is already a message that is part of the message. same group.

My question is whether this can be done without using other storage than another database or having it in memory

Thank you very much

Javier.

DavidBoike commented 6 years ago

Hi @Javier13,

In-order processing of messages in any distributed system is pretty much a myth. Well, unless you want to have a single-threaded message processor and then stop the entire endpoint any time a message goes to the error queue.

The solution you're looking for is a saga. Store data from related messages in the saga data, and then when the conditions are correct, take further action.

When you're using persistent saga storage like SQL Persistence you are essentially storing stuff in the database in between messages, you just have a nice API and guaranteed transactional model for doing so.

Javier13 commented 6 years ago

Thanks David for the response, I will study the option of using saga. Thank you