Refactor ConsumerInitWorker to use IHostedService

Refactored the `ConsumerInitWorker` class to implement the
`IHostedService` interface, replacing `BackgroundService`.
Replaced `ExecuteAsync` with `StartAsync` and `StopAsync`
methods. Added a log statement for successful initialization
of `SendingEmailConsumerPool`.

Updated `DigitalData.MessagingService.API.csproj` to increment
version numbers:
- `Version`: 2.2.0-beta -> 2.2.1-beta
- `FileVersion`: 2.2.0.0 -> 2.2.1.0
- `AssemblyVersion`: 2.2.0.0 -> 2.2.1.0

These changes introduce minor improvements and bug fixes
without breaking changes.
This commit is contained in:
2026-11-16 16:51:46 +01:00
parent a1165121d1
commit ef39263f82
2 changed files with 10 additions and 9 deletions

View File

@@ -15,17 +15,18 @@ public class ConsumerInitWorker(
SendingEmailConsumerPool ConsumerPool, SendingEmailConsumerPool ConsumerPool,
ILogger<ConsumerInitWorker> Logger, ILogger<ConsumerInitWorker> Logger,
IOptions<RabbitMqConnectionConfiguration> RabbitMqOptions, IOptions<RabbitMqConnectionConfiguration> RabbitMqOptions,
ConsumerInitHealthCheck HealthCheck) : BackgroundService ConsumerInitHealthCheck HealthCheck) : IHostedService
{ {
protected override async Task ExecuteAsync(CancellationToken stoppingToken) public async Task StartAsync(CancellationToken cancellationToken)
{ {
try try
{ {
await ConsumerPool.InitAsync(); await ConsumerPool.InitAsync();
Logger.LogInformation("SendingEmailConsumerPool initialized successfully.");
} }
catch (Exception ex) catch (Exception ex)
{ {
// Log and mark the health check as unhealthy — callers will receive HTTP 503. // Log and mark the health check as unhealthy <EFBFBD> callers will receive HTTP 503.
// The API remains operational; only outgoing email delivery via the consumer pool is affected. // The API remains operational; only outgoing email delivery via the consumer pool is affected.
Logger.LogError(ex, "Failed to initialize SendingEmailConsumerPool. Outgoing email consumers are not running."); Logger.LogError(ex, "Failed to initialize SendingEmailConsumerPool. Outgoing email consumers are not running.");
@@ -34,7 +35,7 @@ public class ConsumerInitWorker(
if (!RabbitMqOptions.Value.ContinueOnInitFailure) if (!RabbitMqOptions.Value.ContinueOnInitFailure)
throw; throw;
} }
await Task.Delay(Timeout.Infinite, stoppingToken).ConfigureAwait(ConfigureAwaitOptions.SuppressThrowing);
} }
}
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}

View File

@@ -10,9 +10,9 @@
<Authors>Digital Data GmbH</Authors> <Authors>Digital Data GmbH</Authors>
<Company>Digital Data GmbH</Company> <Company>Digital Data GmbH</Company>
<Product>DigitalData.MessagingService.API</Product> <Product>DigitalData.MessagingService.API</Product>
<Version>2.2.0-beta</Version> <Version>2.2.1-beta</Version>
<FileVersion>2.2.0.0</FileVersion> <FileVersion>2.2.1.0</FileVersion>
<AssemblyVersion>2.2.0.0</AssemblyVersion> <AssemblyVersion>2.2.1.0</AssemblyVersion>
<Copyright>Copyright © 2026 Digital Data GmbH. All rights reserved.</Copyright> <Copyright>Copyright © 2026 Digital Data GmbH. All rights reserved.</Copyright>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile> <DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup> </PropertyGroup>