3
votes

Is there a way to disable sending failed messages to an error queue for NServiceBus?

For one particular endpoint, I don't want to retry messages after they've failed second level retries. Instead, I'm going to hook those messages into a custom error handling solution by using the MessageSentToErrorQueue error notification mentioned here: Is there a global exception handler for NServiceBus?

If I omit the MessageForwardingInCaseOfFaultConfig setting, NSB will throw an exception.

I can send them to an unmonitored error queue (table) and just purge it regularly, but I'd rather not if possible.

Maybe I could also set the TimeToBeReceived shorter than the SecondLevel Retries, but that doesn't seem to fit either.

I'm using NSB version 5.2.14 with SQL server transport 2.2.3.

1

1 Answers

3
votes

This will discard all messages

BusConfiguration configuration = new BusConfiguration();
configuration.DiscardFailedMessagesInsteadOfSendingToErrorQueue();

Unfortunately you still need to specify an error queue or the endpoint instance won't get created. But I just tested it and the error queue wasn't even created. Unfortunately the event doesn't fire either.

Option 2: Take a look at IManageMessageFailures. There are tests in the NServiceBus repo, but this isn't a supported scenario by us.

Option 3: Implement a behavior as described here. I haven't tested this and think it's a bit flaky, but catch messages when they're sent to the error queue and abort pipeline execution.

However

Please note that we put a lot of effort into ensuring the message gets delivered, even to the error queue. So be very certain you want to build your own solution and override the error queue. I'd highly advise to read the error queue yourself, process the message and do whatever you want with them. You can just create another endpoint with NServiceBus that feeds off of the error queue. It's what we do with ServiceControl.

Note : If you're using ServiceControl and/or error queues for regular processing, you should specify a different error queue for this endpoint, so that error messages from this endpoint don't mix with your regular error msg processing.