Improve RabbitMQ configuration handling in DI setup

Refactor the `DependencyInjection` class to enhance the
validation and setup process for `RabbitMQ` when used as
the `ConsumerType`. Remove the outdated logic for adding
an HTTP client based on `options.ApiUrl`. Introduce a
check for `options.RabbitMQ` and throw a detailed
`InvalidOperationException` if it is missing. Use
`services.AddMessagingServiceClient` to configure the
messaging service client with the appropriate section name.
This commit is contained in:
2026-11-17 20:22:50 +01:00
parent 224d029c18
commit 3a21b3ba94

View File

@@ -31,15 +31,14 @@ public static class DependencyInjection
$"MessagingServiceApiUrl must be provided when ClientType is set to Api in the '{sectionName}' configuration section.");
break;
case ConsumerType.RabbitMQ:
if (options.ApiUrl is string rabbitModeApiUrl)
services.AddMessagingServiceHttpClient(opt =>
{
opt.BaseAddress = new Uri(rabbitModeApiUrl);
});
else
if (options.RabbitMQ is null)
throw new InvalidOperationException(
$"Missing API URL configuration." +
$"When ClientType is set to RabbitMQ in an isolated host, Notification:ApiUrl must be provided in the '{sectionName}' configuration section.");
$"Missing RabbitMQ configuration. " +
$"When ConsumerType is set to RabbitMQ, '{sectionName}:{nameof(NotificationOptions.RabbitMQ)}' must be configured.");
services.AddMessagingServiceClient(
configuration,
rabbitMqConnectionSectionName: $"{sectionName}:{nameof(NotificationOptions.RabbitMQ)}");
break;
default:
throw new InvalidOperationException(