From 6c79a26224ce17dac5eb1164271bbb5c20c9882b Mon Sep 17 00:00:00 2001 From: Anton Stuchinskii Date: Thu, 4 May 2023 14:12:16 +0200 Subject: [PATCH] Using URI param instead for RabbitMQ connection --- src/Services/Basket/Basket.API/Program.cs | 13 +++---------- src/Services/Catalog/Catalog.API/Program.cs | 17 +++++------------ src/Services/Ordering/Ordering.API/Program.cs | 15 ++------------- .../Extensions/CustomExtensionMethods.cs | 14 ++------------ .../Ordering/Ordering.SignalrHub/Program.cs | 15 ++------------- src/Services/Payment/Payment.API/Program.cs | 15 +++------------ src/Services/Webhooks/Webhooks.API/Startup.cs | 12 +----------- src/docker-compose.override.yml | 14 +++++++------- 8 files changed, 25 insertions(+), 90 deletions(-) diff --git a/src/Services/Basket/Basket.API/Program.cs b/src/Services/Basket/Basket.API/Program.cs index 71c7587db..40e20ca2c 100644 --- a/src/Services/Basket/Basket.API/Program.cs +++ b/src/Services/Basket/Basket.API/Program.cs @@ -90,19 +90,12 @@ else { builder.Services.AddSingleton(sp => { var logger = sp.GetRequiredService>(); - var factory = new ConnectionFactory() { - HostName = builder.Configuration["EventBusConnection"], + var factory = new ConnectionFactory() + { + Uri = new System.Uri(builder.Configuration["EventBusConnection"]), DispatchConsumersAsync = true }; - if (!string.IsNullOrEmpty(builder.Configuration["EventBusUserName"])) { - factory.UserName = builder.Configuration["EventBusUserName"]; - } - - if (!string.IsNullOrEmpty(builder.Configuration["EventBusPassword"])) { - factory.Password = builder.Configuration["EventBusPassword"]; - } - var retryCount = 5; if (!string.IsNullOrEmpty(builder.Configuration["EventBusRetryCount"])) { retryCount = int.Parse(builder.Configuration["EventBusRetryCount"]); diff --git a/src/Services/Catalog/Catalog.API/Program.cs b/src/Services/Catalog/Catalog.API/Program.cs index aa594b1fc..975e392a1 100644 --- a/src/Services/Catalog/Catalog.API/Program.cs +++ b/src/Services/Catalog/Catalog.API/Program.cs @@ -187,7 +187,7 @@ public static class CustomExtensionMethods { else { hcBuilder .AddRabbitMQ( - $"amqp://{configuration["EventBusConnection"]}", + configuration["EventBusConnection"], name: "catalog-rabbitmqbus-check", tags: new string[] { "rabbitmqbus" }); } @@ -269,19 +269,12 @@ public static class CustomExtensionMethods { var settings = sp.GetRequiredService>().Value; var logger = sp.GetRequiredService>(); - var factory = new ConnectionFactory() { - HostName = configuration["EventBusConnection"], + var factory = new ConnectionFactory() + { + Uri = new System.Uri(configuration["EventBusConnection"]), DispatchConsumersAsync = true }; - if (!string.IsNullOrEmpty(configuration["EventBusUserName"])) { - factory.UserName = configuration["EventBusUserName"]; - } - - if (!string.IsNullOrEmpty(configuration["EventBusPassword"])) { - factory.Password = configuration["EventBusPassword"]; - } - var retryCount = 5; if (!string.IsNullOrEmpty(configuration["EventBusRetryCount"])) { retryCount = int.Parse(configuration["EventBusRetryCount"]); @@ -329,4 +322,4 @@ public static class CustomExtensionMethods { return services; } -} \ No newline at end of file +} diff --git a/src/Services/Ordering/Ordering.API/Program.cs b/src/Services/Ordering/Ordering.API/Program.cs index ba62a4dcc..96f47c94a 100644 --- a/src/Services/Ordering/Ordering.API/Program.cs +++ b/src/Services/Ordering/Ordering.API/Program.cs @@ -237,7 +237,7 @@ static class CustomExtensionsMethods { hcBuilder .AddRabbitMQ( - $"amqp://{configuration["EventBusConnection"]}", + configuration["EventBusConnection"], name: "ordering-rabbitmqbus-check", tags: new string[] { "rabbitmqbus" }); } @@ -330,23 +330,12 @@ static class CustomExtensionsMethods { var logger = sp.GetRequiredService>(); - var factory = new ConnectionFactory() { - HostName = configuration["EventBusConnection"], + Uri = new System.Uri(configuration["EventBusConnection"]), DispatchConsumersAsync = true }; - if (!string.IsNullOrEmpty(configuration["EventBusUserName"])) - { - factory.UserName = configuration["EventBusUserName"]; - } - - if (!string.IsNullOrEmpty(configuration["EventBusPassword"])) - { - factory.Password = configuration["EventBusPassword"]; - } - var retryCount = 5; if (!string.IsNullOrEmpty(configuration["EventBusRetryCount"])) { diff --git a/src/Services/Ordering/Ordering.BackgroundTasks/Extensions/CustomExtensionMethods.cs b/src/Services/Ordering/Ordering.BackgroundTasks/Extensions/CustomExtensionMethods.cs index 83fd4dc0d..839a388eb 100644 --- a/src/Services/Ordering/Ordering.BackgroundTasks/Extensions/CustomExtensionMethods.cs +++ b/src/Services/Ordering/Ordering.BackgroundTasks/Extensions/CustomExtensionMethods.cs @@ -36,7 +36,7 @@ namespace Ordering.BackgroundTasks.Extensions else { hcBuilder.AddRabbitMQ( - $"amqp://{configuration["EventBusConnection"]}", + configuration["EventBusConnection"], name: "orderingtask-rabbitmqbus-check", tags: new string[] { "rabbitmqbus" }); } @@ -75,20 +75,10 @@ namespace Ordering.BackgroundTasks.Extensions var factory = new ConnectionFactory() { - HostName = configuration["EventBusConnection"], + Uri = new System.Uri(configuration["EventBusConnection"]), DispatchConsumersAsync = true }; - if (!string.IsNullOrEmpty(configuration["EventBusUserName"])) - { - factory.UserName = configuration["EventBusUserName"]; - } - - if (!string.IsNullOrEmpty(configuration["EventBusPassword"])) - { - factory.Password = configuration["EventBusPassword"]; - } - var retryCount = 5; if (!string.IsNullOrEmpty(configuration["EventBusRetryCount"])) diff --git a/src/Services/Ordering/Ordering.SignalrHub/Program.cs b/src/Services/Ordering/Ordering.SignalrHub/Program.cs index ffbb5b8dc..927198b47 100644 --- a/src/Services/Ordering/Ordering.SignalrHub/Program.cs +++ b/src/Services/Ordering/Ordering.SignalrHub/Program.cs @@ -50,23 +50,12 @@ else { var logger = sp.GetRequiredService>(); - var factory = new ConnectionFactory() { - HostName = builder.Configuration["EventBusConnection"], + Uri = new System.Uri(builder.Configuration["EventBusConnection"]), DispatchConsumersAsync = true }; - if (!string.IsNullOrEmpty(builder.Configuration["EventBusUserName"])) - { - factory.UserName = builder.Configuration["EventBusUserName"]; - } - - if (!string.IsNullOrEmpty(builder.Configuration["EventBusPassword"])) - { - factory.Password = builder.Configuration["EventBusPassword"]; - } - var retryCount = 5; if (!string.IsNullOrEmpty(builder.Configuration["EventBusRetryCount"])) { @@ -251,7 +240,7 @@ public static class CustomExtensionMethods { hcBuilder .AddRabbitMQ( - $"amqp://{configuration["EventBusConnection"]}", + configuration["EventBusConnection"], name: "signalr-rabbitmqbus-check", tags: new string[] { "rabbitmqbus" }); } diff --git a/src/Services/Payment/Payment.API/Program.cs b/src/Services/Payment/Payment.API/Program.cs index acfc73217..022a8b9c5 100644 --- a/src/Services/Payment/Payment.API/Program.cs +++ b/src/Services/Payment/Payment.API/Program.cs @@ -37,22 +37,13 @@ else builder.Services.AddSingleton(sp => { var logger = sp.GetRequiredService>(); + var factory = new ConnectionFactory() { - HostName = builder.Configuration["EventBusConnection"], + Uri = new System.Uri(builder.Configuration["EventBusConnection"]), DispatchConsumersAsync = true }; - if (!string.IsNullOrEmpty(builder.Configuration["EventBusUserName"])) - { - factory.UserName = builder.Configuration["EventBusUserName"]; - } - - if (!string.IsNullOrEmpty(builder.Configuration["EventBusPassword"])) - { - factory.Password = builder.Configuration["EventBusPassword"]; - } - var retryCount = 5; if (!string.IsNullOrEmpty(builder.Configuration["EventBusRetryCount"])) { @@ -212,7 +203,7 @@ public static class CustomExtensionMethods { hcBuilder .AddRabbitMQ( - $"amqp://{configuration["EventBusConnection"]}", + configuration["EventBusConnection"], name: "payment-rabbitmqbus-check", tags: new string[] { "rabbitmqbus" }); } diff --git a/src/Services/Webhooks/Webhooks.API/Startup.cs b/src/Services/Webhooks/Webhooks.API/Startup.cs index 05d760b7b..cf9e01a44 100644 --- a/src/Services/Webhooks/Webhooks.API/Startup.cs +++ b/src/Services/Webhooks/Webhooks.API/Startup.cs @@ -255,20 +255,10 @@ internal static class CustomExtensionMethods var factory = new ConnectionFactory() { - HostName = configuration["EventBusConnection"], + Uri = new System.Uri(configuration["EventBusConnection"]), DispatchConsumersAsync = true }; - if (!string.IsNullOrEmpty(configuration["EventBusUserName"])) - { - factory.UserName = configuration["EventBusUserName"]; - } - - if (!string.IsNullOrEmpty(configuration["EventBusPassword"])) - { - factory.Password = configuration["EventBusPassword"]; - } - var retryCount = 5; if (!string.IsNullOrEmpty(configuration["EventBusRetryCount"])) { diff --git a/src/docker-compose.override.yml b/src/docker-compose.override.yml index dd1a95f3d..88c090008 100644 --- a/src/docker-compose.override.yml +++ b/src/docker-compose.override.yml @@ -65,7 +65,7 @@ services: - ConnectionString=${ESHOP_AZURE_REDIS_BASKET_DB:-basketdata} - identityUrl=http://identity-api - IdentityUrlExternal=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5105 - - EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq} + - EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-amqp://rabbitmq} - EventBusUserName=${ESHOP_SERVICE_BUS_USERNAME} - EventBusPassword=${ESHOP_SERVICE_BUS_PASSWORD} - AzureServiceBusEnabled=False @@ -84,7 +84,7 @@ services: - ASPNETCORE_ENVIRONMENT=Development - ConnectionString=${ESHOP_AZURE_CATALOG_DB:-Server=sqldata;Database=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word;Encrypt=False;TrustServerCertificate=true} - PicBaseUrl=${ESHOP_STORAGE_CATALOG_URL} - - EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq} + - EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-amqp://rabbitmq} - EventBusUserName=${ESHOP_SERVICE_BUS_USERNAME} - EventBusPassword=${ESHOP_SERVICE_BUS_PASSWORD} - AzureStorageAccountName=${ESHOP_AZURE_STORAGE_CATALOG_NAME} @@ -108,7 +108,7 @@ services: - ConnectionString=${ESHOP_AZURE_ORDERING_DB:-Server=sqldata;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;Encrypt=False;TrustServerCertificate=true} - identityUrl=http://identity-api - IdentityUrlExternal=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5105 - - EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq} + - EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-amqp://rabbitmq} - EventBusUserName=${ESHOP_SERVICE_BUS_USERNAME} - EventBusPassword=${ESHOP_SERVICE_BUS_PASSWORD} - UseCustomizationData=True @@ -131,7 +131,7 @@ services: - ASPNETCORE_ENVIRONMENT=Development - ASPNETCORE_URLS=http://0.0.0.0:80 - ConnectionString=${ESHOP_AZURE_ORDERING_DB:-Server=sqldata;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;Encrypt=False;TrustServerCertificate=true} - - EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq} + - EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-amqp://rabbitmq} - EventBusUserName=${ESHOP_SERVICE_BUS_USERNAME} - EventBusPassword=${ESHOP_SERVICE_BUS_PASSWORD} - UseCustomizationData=True @@ -149,7 +149,7 @@ services: environment: - ASPNETCORE_ENVIRONMENT=Development - ASPNETCORE_URLS=http://0.0.0.0:80 - - EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq} + - EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-amqp://rabbitmq} - EventBusUserName=${ESHOP_SERVICE_BUS_USERNAME} - EventBusPassword=${ESHOP_SERVICE_BUS_PASSWORD} - AzureServiceBusEnabled=False @@ -165,7 +165,7 @@ services: - ASPNETCORE_ENVIRONMENT=Development - ASPNETCORE_URLS=http://0.0.0.0:80 - ConnectionString=${ESHOP_AZURE_WEBHOOKS_DB:-Server=sqldata;Database=Microsoft.eShopOnContainers.Services.WebhooksDb;User Id=sa;Password=Pass@word;Encrypt=False;TrustServerCertificate=true} - - EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq} + - EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-amqp://rabbitmq} - EventBusUserName=${ESHOP_SERVICE_BUS_USERNAME} - EventBusPassword=${ESHOP_SERVICE_BUS_PASSWORD} - IdentityUrl=http://identity-api @@ -229,7 +229,7 @@ services: environment: - ASPNETCORE_ENVIRONMENT=Development - ASPNETCORE_URLS=http://0.0.0.0:80 - - EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq} + - EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-amqp://rabbitmq} - EventBusUserName=${ESHOP_SERVICE_BUS_USERNAME} - EventBusPassword=${ESHOP_SERVICE_BUS_PASSWORD} - AzureServiceBusEnabled=False