From cb21aa15d6d4cd2438d479db2137c32cbf657919 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Tue, 21 May 2024 18:32:30 -0400 Subject: [PATCH] gateway updates --- aspire/AppHost/Program.cs | 18 ++++++++++++++---- .../eShopOnAbp.ServiceDefaults.csproj | 4 ++-- .../src/EShopOnAbp.WebPublicGateway/yarp.json | 16 ++++++++-------- .../BasketServiceModule.cs | 11 ++++++----- ...EShopOnAbp.Shared.Hosting.AspNetCore.csproj | 6 +++++- .../EShopOnAbp.Shared.Hosting.Gateways.csproj | 3 +++ .../EShopOnAbpSharedHostingGatewaysModule.cs | 13 ++++++++++++- 7 files changed, 50 insertions(+), 21 deletions(-) diff --git a/aspire/AppHost/Program.cs b/aspire/AppHost/Program.cs index 2bf8b397..9333d805 100644 --- a/aspire/AppHost/Program.cs +++ b/aspire/AppHost/Program.cs @@ -1,10 +1,12 @@ var builder = DistributedApplication.CreateBuilder(args); +var launchProfile = "HTTP"; // Microservices var administrationService = - builder.AddProject("administrationService"); + builder.AddProject("administrationService",launchProfile); var identityService = builder.AddProject("identityService"); -var catalogService = builder.AddProject("catalogService"); +var catalogService = builder.AddProject("catalogService") + .AsHttp2Service(); var basketService = builder.AddProject("basketService") .WithReference(catalogService); //? var cmsKitService = builder.AddProject("cmsKitService"); @@ -13,9 +15,17 @@ var paymentService = builder.AddProject("webGateway"); -var webPublicGateway = builder.AddProject("webPublicGateway"); +var webPublicGateway = builder.AddProject("webPublicGateway") + .WithReference(administrationService) + .WithReference(identityService) + .WithReference(catalogService) + .WithReference(basketService) + .WithReference(cmsKitService) + .WithReference(orderingService) + .WithReference(paymentService); // Apps -var publicWebApp = builder.AddProject("public-web"); +var publicWebApp = builder.AddProject("public-web") + .WithExternalHttpEndpoints(); builder.Build().Run(); diff --git a/aspire/ServiceDefaults/eShopOnAbp.ServiceDefaults.csproj b/aspire/ServiceDefaults/eShopOnAbp.ServiceDefaults.csproj index f48299bb..20ff9d9d 100644 --- a/aspire/ServiceDefaults/eShopOnAbp.ServiceDefaults.csproj +++ b/aspire/ServiceDefaults/eShopOnAbp.ServiceDefaults.csproj @@ -10,8 +10,8 @@ - - + + diff --git a/gateways/web-public/src/EShopOnAbp.WebPublicGateway/yarp.json b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/yarp.json index 8c7b6e19..8b611fca 100644 --- a/gateways/web-public/src/EShopOnAbp.WebPublicGateway/yarp.json +++ b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/yarp.json @@ -142,7 +142,7 @@ "Identity": { "Destinations": { "destination1": { - "Address": "https://localhost:44351", + "Address": "http://identityService", "MetaData": { "PublicAddress": "https://identity.eshoponabp.dev" } @@ -152,7 +152,7 @@ "Administration": { "Destinations": { "destination1": { - "Address": "https://localhost:44353", + "Address": "http://admininstrationService", "MetaData": { "PublicAddress": "https://admininstration.eshop.dev" } @@ -162,9 +162,9 @@ "catalogCluster": { "Destinations": { "destination1": { - "Address": "https://localhost:44354", + "Address": "http://catalogService", "MetaData": { - "PublicAddress": "https://admininstration.eshoponabp.dev" + "PublicAddress": "https://catalog.eshoponabp.dev" } } } @@ -172,7 +172,7 @@ "Basket": { "Destinations": { "destination1": { - "Address": "https://localhost:44355", + "Address": "http://basketService", "MetaData": { "PublicAddress": "https://basket.eshoponabp.dev" } @@ -182,7 +182,7 @@ "Ordering": { "Destinations": { "destination1": { - "Address": "https://localhost:44356", + "Address": "http://orderingService", "MetaData": { "PublicAddress": "https://ordering.eshoponabp.dev" } @@ -192,7 +192,7 @@ "CmsKit": { "Destinations": { "destination1": { - "Address": "https://localhost:44358", + "Address": "http://cmsKitService", "MetaData": { "PublicAddress": "https://cmskit.eshoponabp.dev" } @@ -202,7 +202,7 @@ "Payment": { "Destinations": { "destination1": { - "Address": "https://localhost:44357", + "Address": "http://paymentService", "MetaData": { "PublicAddress": "https://payment.eshoponabp.dev" } diff --git a/services/basket/src/EShopOnAbp.BasketService/BasketServiceModule.cs b/services/basket/src/EShopOnAbp.BasketService/BasketServiceModule.cs index 29c769df..d9cab1da 100644 --- a/services/basket/src/EShopOnAbp.BasketService/BasketServiceModule.cs +++ b/services/basket/src/EShopOnAbp.BasketService/BasketServiceModule.cs @@ -156,11 +156,12 @@ public class BasketServiceModule : AbpModule { context.Services.AddGrpcClient((services, options) => { - var remoteServiceOptions = services.GetRequiredService>().CurrentValue; - var catalogServiceConfiguration = remoteServiceOptions.RemoteServices.GetConfigurationOrDefault("Catalog"); - var catalogGrpcUrl = catalogServiceConfiguration.GetOrDefault("GrpcUrl"); - - if (catalogGrpcUrl != null) options.Address = new Uri(catalogGrpcUrl); + options.Address = new Uri("http://catalogService"); + // var remoteServiceOptions = services.GetRequiredService>().CurrentValue; + // var catalogServiceConfiguration = remoteServiceOptions.RemoteServices.GetConfigurationOrDefault("Catalog"); + // var catalogGrpcUrl = catalogServiceConfiguration.GetOrDefault("GrpcUrl"); + // + // if (catalogGrpcUrl != null) options.Address = new Uri(catalogGrpcUrl); }); } diff --git a/shared/EShopOnAbp.Shared.Hosting.AspNetCore/EShopOnAbp.Shared.Hosting.AspNetCore.csproj b/shared/EShopOnAbp.Shared.Hosting.AspNetCore/EShopOnAbp.Shared.Hosting.AspNetCore.csproj index af2061f5..afbcd803 100644 --- a/shared/EShopOnAbp.Shared.Hosting.AspNetCore/EShopOnAbp.Shared.Hosting.AspNetCore.csproj +++ b/shared/EShopOnAbp.Shared.Hosting.AspNetCore/EShopOnAbp.Shared.Hosting.AspNetCore.csproj @@ -7,12 +7,16 @@ - + + + + + diff --git a/shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbp.Shared.Hosting.Gateways.csproj b/shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbp.Shared.Hosting.Gateways.csproj index 2dca4833..f627cf3b 100644 --- a/shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbp.Shared.Hosting.Gateways.csproj +++ b/shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbp.Shared.Hosting.Gateways.csproj @@ -8,6 +8,9 @@ + + + diff --git a/shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbpSharedHostingGatewaysModule.cs b/shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbpSharedHostingGatewaysModule.cs index 11c1d509..859b1a38 100644 --- a/shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbpSharedHostingGatewaysModule.cs +++ b/shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbpSharedHostingGatewaysModule.cs @@ -12,9 +12,20 @@ namespace EShopOnAbp.Shared.Hosting.Gateways public override void ConfigureServices(ServiceConfigurationContext context) { var configuration = context.Services.GetConfiguration(); + + context.Services.AddServiceDiscovery(); + context.Services.ConfigureHttpClientDefaults(http => + { + // Turn on resilience by default + http.AddStandardResilienceHandler(); + + // Turn on service discovery by default + http.AddServiceDiscovery(); + }); context.Services.AddReverseProxy() - .LoadFromConfig(configuration.GetSection("ReverseProxy")); + .LoadFromConfig(configuration.GetSection("ReverseProxy")) + .AddServiceDiscoveryDestinationResolver(); } } } \ No newline at end of file