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