Endpoint Does Not Receive Messages Under Windows Service

I am using NSB 7.7.3 and .NET 6.

I have two endpoints: the first one sends messages to the second which only receives messages. When the application is run with no Windows Service, it runs perfectly. However, when running under a Windows Service, the first endpoint sends data to the second, which does not receive it. This is my understanding because when I run the application a second time while not under a service, the queued messages are received by the second endpoint (and logging confirms they were not sent from the first).

There are no error messages. I tested this under a local service and one governed by a gMSA. With both the second endpoint simply stops receiving messages while under the service. All help is greatly appreciated. Thank you.

What transport are you using? If that’s MSMQ it sounds like a permissions issue.

I am using the SQL Server transport. I’ve looked at the Windows service permissions and do not see anything that would only affect a single NSB receiving endpoint.

I’m not that familiar with group-managed service accounts. I’m unsure how that affects the endpoint process interaction with the database server. I assume the gMSA has access to SQL Server.

Can you share the failing NServiceBus endpoint logs and its configuration code? If you prefer not to share them publicly, you can send them to support@particular.net.

The gMSA does have access to SQL Server. The database that Particular’s software (and the SQL transport) resides in also has tables for my application logging and that logging works under the gMSA.

Earlier I had a SQL issue where gMSA ran afoul of NSB pre-startup checks:

Pre-Startup Checks Fail Prior to gMSA Context Being Established by Windows Service

As a result of that issue, I ended up using this configuration for the receiving endpoint (the one that does not receive messages under the Windows service/gMSA):

//Endpoint and database names have been changed
//Program.cs has no NSB configuration

//public static class NServiceBus_BaseConfiguration //configures all endpoints

public static (EndpointConfiguration endpointConfiguration, TransportExtensions<SqlServerTransport> sqlTransport) GetEndpointConfiguration(string endpointName, IConfiguration configuration)
{
    var endpointConfiguration = new EndpointConfiguration(endpointName);

    endpointConfiguration.AuditProcessedMessagesTo("NServiceBus.Audit");
    endpointConfiguration.SendFailedMessagesTo("NServiceBus.Errors");
    endpointConfiguration.UseSerialization<NewtonsoftJsonSerializer>(); // For Custom Events Error emails/logging
    endpointConfiguration.AddDeserializer<XmlSerializer>(); // For transmitting contacts
    //endpointConfiguration.PurgeOnStartup(true); //Very useful for testing

    // Wires up NServiceBus to SQL
    string connectionString = configuration.GetValue<string>("ConnectionStrings:AppDatabase");
    var transport = endpointConfiguration.UseTransport<SqlServerTransport>();
    transport.ConnectionString(connectionString);

    var subscriptions = transport.SubscriptionSettings();
    subscriptions.SubscriptionTableName(tableName: "NServiceBus.SubscriptionRouting");

    // Read settings and connect to NServiceBus ServiceControl, ServicePulse, and ServiceInsight
    #pragma warning disable CS8602 // Dereference of a possibly null reference.
    var NServiceBusConfigPath = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Configurations\\NServiceBus_MonitorConfiguration.json");
    #pragma warning restore CS8602 // Dereference of a possibly null reference.

    var NServiceBusConfiguration = File.ReadAllText(NServiceBusConfigPath);
    var platformConnection = ServicePlatformConnectionConfiguration.Parse(NServiceBusConfiguration);
    endpointConfiguration.ConnectToServicePlatform(platformConnection);

    // Wires up email notifications processed by NServiceBusCustomEventsHandler
    var conventions = endpointConfiguration.Conventions();
    conventions.DefiningEventsAs(
        type =>
        {
            return typeof(IEvent).IsAssignableFrom(type) ||
                   // include ServiceControl events
                   type.Namespace != null &&
                   type.Namespace.StartsWith("ServiceControl.Contracts");
        });

    endpointConfiguration.EnableInstallers();

    return (endpointConfiguration, transport);
}

//Endpoint2 Worker.cs
//public override async Task<Task> StartAsync(CancellationToken cancellationToken)

var bundledConfigurations = NServiceBus_BaseConfiguration.GetEndpointConfiguration("NServiceBus.Endpoint2", _configuration);
var endpointConfiguration = bundledConfigurations.endpointConfiguration;

endpointConfiguration.DefineCriticalErrorAction(OnCriticalError);

var startableEndpoint = await Endpoint.Create(endpointConfiguration)
    .ConfigureAwait(false);
var endpointInstance = await startableEndpoint.Start()
    .ConfigureAwait(false);
_activeDirectoryEndpointInstance = endpointInstance;

//protected override async Task ExecuteAsync(CancellationToken cancellationToken)

//logging code
await _activeDirectoryEndpointInstance.Stop()
   .ConfigureAwait(false);

I was uncertain as to what logs you want to look at. If these samples are not what you need, please let me know.

Particular.Monitoring (no exceptions, entire contents below)
ServiceControl Monitoring Version: 4.22.0
Selected Transport: ServiceControl.Transports.SqlServer.SqlServerTransportCustomization, ServiceControl.Transports.SqlServer

2023-01-30 04:00:55.3090|5|Warn|NServiceBus.Transport.SqlServer.SqlConnectionFactory|Maximum connection pooling value (Max Pool Size=N) is not configured on the provided connection string. The default value (100) will be used.

Particular.ServiceControl.Audit (only exception below, rest is info level, and warn on 19% disk space remaining)
System.ComponentModel.Win32Exception (0x80004005): The interface is unknown
at System.Diagnostics.EventLogInternal.InternalWriteEvent(UInt32 eventID, UInt16 category, EventLogEntryType type, String[] strings, Byte[] rawData, String currentMachineName)
at System.Diagnostics.EventLogInternal.WriteEvent(EventInstance instance, Byte[] data, Object[] values)
at System.Diagnostics.EventLog.WriteEvent(EventInstance instance, Object[] values)
at Microsoft.Extensions.Logging.EventLog.WindowsEventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category)
at Microsoft.Extensions.Logging.EventLog.EventLogLogger.WriteMessage(String message, EventLogEntryType eventLogEntryType, Int32 eventId)
at Microsoft.Extensions.Logging.EventLog.EventLogLogger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func3 formatter) at Microsoft.Extensions.Logging.Logger.<Log>g__LoggerLog|12_0[TState](LogLevel logLevel, EventId eventId, ILogger logger, Exception exception, Func3 formatter, List`1& exceptions, TState& state)

Particular.ServiceControl
Only Info level messages “no batch found to stage” and “No batch found to forward”

Please let me know if you need anything else. Thank you!

After looking through every possible log, including those found at

I discovered that the issue was caused by an incorrectly placed

await EndpointInstance.Stop()
          .ConfigureAwait(false);

which caused the endpoint to cease working at an incorrect point in the application.

1 Like