Strategy for messages that must be delivered in order in Rebus

1k views Asked by At

I'm using Rebus SQLTransport with XML serialized messages for integration with SQL Server. Messages represent changes done in SQL Server. Because of that the order of message delivery is essential.

It is because for example message1 may contain object that is referenced (by id) in message2. Another example is that message1 may contain remove request of some object that is required to accept new object from message2.

Aggregating messages into one message would be quite complicated because messages are generated by triggers.

Having message idempotence and one worker I guess that would work except the fact that won't work if error happens and message will be moved to error queue. The error is quite possible to happen because of validation or business logic exception. Because of that I believe only human can fix the problem with message and until that time other messages should not be delivered. So I wanted to ask for advice what would be best to do in that situation. As far as I saw retry number cannot be set to infinity so should I stop the service inside of handler until problem is solved by human?

Thanks in advance

1

There are 1 answers

16
mookid8000 On BEST ANSWER

If it's important that the messages are processed in order without any "holes", I suggest you assign a sequence number to each message.

This way, if the endpoint gets a message whose sequence number is greater than the expected sequence number it can throw an exception, thus preventing out-of-order messages to be processed.

I would only do this if errors are uncommon though, and only if the message volume is fairly small.

If in-order processing is required, a much better design would be to use another message processing library that supports a pull model, which I think would fit your scenario much better than Rebus' push model.