I have spent lot of time trying to understand how NServiceBus works under the hood, but I am having quite some difficulties.
We have NServiceBus 7.8.2 with SQL Transport 6.3.4 running services in on-premises environment. If the SQL Server is turned off even for 5 minutes, connectivity does not return and circuit breaker doesn’t trigger.
In order to run our operations with some fault resilience I would need to have preferably both features. I have tried running with dozens of configurations but circuit breaker is not triggering.
This is how I initialize the endpoint, is there anything wrong with that? What am I missing?
Thank you!
host.UseWindowsService();
host.ConfigureLogging(loggingBuilder => {
loggingBuilder.AddConsole();
});
host.UseNLog();
host.UseMicrosoftLogFactoryLogging();
host.UseNServiceBus(hostBuilderContext => {
var config = hostBuilderContext.Configuration.GetSection("NServiceBusConfiguration").Get<NServiceBusConfiguration>();
var endpointConfiguration = new EndpointConfiguration(Endpoints.Example.ToString());
endpointConfiguration.License(config.License);
var transport = endpointConfiguration.UseTransport<SqlServerTransport>();
transport.ConnectionString(config.SqlConnectionString);
transport.Transactions(TransportTransactionMode.ReceiveOnly);
endpointConfiguration.UniquelyIdentifyRunningInstance().UsingNames(Endpoints.Example.ToString(), Environment.MachineName);
endpointConfiguration.UseSerialization<NewtonsoftJsonSerializer>();
var persistence = endpointConfiguration.UsePersistence<SqlPersistence>();
persistence.SqlDialect<SqlDialect.MsSqlServer>();
persistence.ConnectionBuilder(() => new SqlConnection(config.SqlConnectionString));
persistence.SubscriptionSettings().CacheFor(TimeSpan.FromMinutes(5));
endpointConfiguration.SendFailedMessagesTo(config.ErrorQueue);
endpointConfiguration.EnableInstallers();
endpointConfiguration.Recoverability().AddUnrecoverableException<MyServiceBusException>();
endpointConfiguration.Recoverability().Delayed(x => x.NumberOfRetries(0));
endpointConfiguration.Recoverability().Immediate(x => x.NumberOfRetries(0));
endpointConfiguration.TimeToWaitBeforeTriggeringCriticalErrorOnTimeoutOutages(TimeSpan.FromSeconds(30));
endpointConfiguration.DefineCriticalErrorAction(OnCriticalError);
});