NServiceBus has the concept of error queue, that is used, as the name implies, when an error occurs; given this behavior the debate should move to:

What is an error?

Many things can be categorized as an error:

  • pure bugs such as unhandled exceptions;
  • validation failures: the incoming message does not satisfies the business validation rules;
  • security violations: the incoming message, due the current security context, cannot be handled;
  • etc.;

What we get for free in NServiceBus is that if our message handler does something like this:

class SampleHandler : IHandleMessages<SampleMessage>
    public void Handle( SampleMessage message )
        if( !this.IsValid( message ) )
             throw new ArgumentException( "Invalid message" );

        //message handling if validation succeed

and an invalid message comes in the retry logic retries for 5 times (by default) and then if the message is still invalid moves the message to the error queue.


Some legitimate questions arise from the above sample:

  1. is it possible that if message A is considered invalid at the first attempt can be considered valid at a subsequent attempt?
  2. is a validation failure the same as an unhandled exception?
  3. does it make sense to have message failed due to a validation failure in the same can as a message failed due to a bug?
    do they have the same business meaning?

Do all the above questions mean that the default NServiceBus behavior is wrong? absolutely not, period.

The above questions simply put evidence on the fact that every little thing that happens in the world we are modeling has a meaning, from the business perspective, and that meaning must be magnified to deeply understand how to treat it.

Next time we’ll see how we can leverage the message handling pipeline to change the default above behavior to satisfy our needs.