0

As we have moved from NSB5 to NSB6 we also looked into removing NServiceBus.Host and instead use Topshelf. When we did, our service no longer shows that it has stopped when we receive a critical failure.

As an example, when we have trouble to reach the database for any reason I want the service to end and in Services Manager it should indicate not running. Though, it still says running but service is actually stopped. Therefore no recovery is run either.

This was working as we were using NServiceBus.Host.

Per
  • 1,393
  • 16
  • 28

1 Answers1

2

I was looking in the wrong direction, towards Topshelf. The answer lies in how to configure NServiceBus to take care of critical errors.

   EndpointConfiguration.DefineCriticalErrorAction(OnCriticalError);

and

    private async Task OnCriticalError(ICriticalErrorContext context)
    {
        await context.Stop().ConfigureAwait(false);
    }

This worked for me.

Per
  • 1,393
  • 16
  • 28
  • 1
    You ALWAYS need to have a code that would do something in case a critical error happens. NServiceBus can't do that for you, since there are vastly different platforms and hosting options and each one is different. You can also use Environment.FailFast in the critical action instead of context.Stop() since that might not work (depending on what the case is). Remember to log a FATAL message as well since it will become confusing as to why the process is getting killed. – Hadi Eskandari Nov 23 '18 at 07:20