From 926cc9f5e5ee5018ad5dbf65ebbd811383d1f2f2 Mon Sep 17 00:00:00 2001 From: Igor Sychev Date: Wed, 6 Sep 2017 14:36:22 +0300 Subject: [PATCH 1/2] Health check for Payment --- docker-compose.override.yml | 1 + src/Services/Payment/Payment.API/Program.cs | 2 +- src/Services/Payment/Payment.API/Startup.cs | 7 +++++++ src/Web/WebStatus/Startup.cs | 1 + src/Web/WebStatus/appsettings.json | 3 ++- 5 files changed, 12 insertions(+), 2 deletions(-) diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 892db9b52..7d1979091 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -137,6 +137,7 @@ services: - IdentityUrl=http://identity.api/hc - LocationsUrl=http://locations.api/hc - MarketingUrl=http://marketing.api/hc + - PaymentUrl=http://payment.api/hc - mvc=http://webmvc/hc - spa=http://webspa/hc ports: diff --git a/src/Services/Payment/Payment.API/Program.cs b/src/Services/Payment/Payment.API/Program.cs index c45d786b9..a373e2695 100644 --- a/src/Services/Payment/Payment.API/Program.cs +++ b/src/Services/Payment/Payment.API/Program.cs @@ -15,7 +15,7 @@ namespace Payment.API public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) - + .UseHealthChecks("/hc") .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup() .ConfigureLogging((hostingContext, builder) => diff --git a/src/Services/Payment/Payment.API/Startup.cs b/src/Services/Payment/Payment.API/Startup.cs index e4378dcef..1d2ba4fb6 100644 --- a/src/Services/Payment/Payment.API/Startup.cs +++ b/src/Services/Payment/Payment.API/Startup.cs @@ -9,11 +9,13 @@ using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ; using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.HealthChecks; using Microsoft.Extensions.Logging; using Payment.API.IntegrationEvents.EventHandling; using Payment.API.IntegrationEvents.Events; using RabbitMQ.Client; using System; +using System.Threading.Tasks; namespace Payment.API { @@ -70,6 +72,11 @@ namespace Payment.API }); } + services.AddHealthChecks(checks => + { + checks.AddValueTaskCheck("HTTP Endpoint", () => new ValueTask(HealthCheckResult.Healthy("Ok"))); + }); + RegisterEventBus(services); services.AddSwaggerGen(options => diff --git a/src/Web/WebStatus/Startup.cs b/src/Web/WebStatus/Startup.cs index 167a01baa..98568c0ab 100644 --- a/src/Web/WebStatus/Startup.cs +++ b/src/Web/WebStatus/Startup.cs @@ -40,6 +40,7 @@ namespace WebStatus checks.AddUrlCheckIfNotNull(Configuration["IdentityUrl"], TimeSpan.FromMinutes(minutes)); checks.AddUrlCheckIfNotNull(Configuration["LocationsUrl"], TimeSpan.FromMinutes(minutes)); checks.AddUrlCheckIfNotNull(Configuration["MarketingUrl"], TimeSpan.FromMinutes(minutes)); + checks.AddUrlCheckIfNotNull(Configuration["PaymentUrl"], TimeSpan.FromMinutes(minutes)); checks.AddUrlCheckIfNotNull(Configuration["mvc"], TimeSpan.FromMinutes(minutes)); checks.AddUrlCheckIfNotNull(Configuration["spa"], TimeSpan.FromMinutes(minutes)); }); diff --git a/src/Web/WebStatus/appsettings.json b/src/Web/WebStatus/appsettings.json index d2f1f4727..df07f1703 100644 --- a/src/Web/WebStatus/appsettings.json +++ b/src/Web/WebStatus/appsettings.json @@ -10,5 +10,6 @@ "CatalogUrl": "http://localhost:5101/hc", "IdentityUrl": "http://localhost:5105/hc", "MarketingUrl": "http://localhost:5110/hc", - "LocationsUrl": "http://localhost:5109/hc" + "LocationsUrl": "http://localhost:5109/hc", + "PaymentUrl": "http://localhost:5108/hc" } From f9c7e386c7c2e71203ce41a69f88efd4012badf0 Mon Sep 17 00:00:00 2001 From: Igor Sychev Date: Wed, 6 Sep 2017 13:35:15 +0300 Subject: [PATCH 2/2] We don't need swagger and MVC contollers in Payment API --- .../Payment.API/Controllers/HomeController.cs | 19 ---------------- .../Payment/Payment.API/Payment.API.csproj | 4 ---- src/Services/Payment/Payment.API/Startup.cs | 22 ------------------- 3 files changed, 45 deletions(-) delete mode 100644 src/Services/Payment/Payment.API/Controllers/HomeController.cs diff --git a/src/Services/Payment/Payment.API/Controllers/HomeController.cs b/src/Services/Payment/Payment.API/Controllers/HomeController.cs deleted file mode 100644 index ae1b931ed..000000000 --- a/src/Services/Payment/Payment.API/Controllers/HomeController.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; - -// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 - -namespace Payment.API.Controllers -{ - public class HomeController : Controller - { - // GET: // - public IActionResult Index() - { - return new RedirectResult("~/swagger"); - } - } -} diff --git a/src/Services/Payment/Payment.API/Payment.API.csproj b/src/Services/Payment/Payment.API/Payment.API.csproj index 49dd3d149..5b7fe983b 100644 --- a/src/Services/Payment/Payment.API/Payment.API.csproj +++ b/src/Services/Payment/Payment.API/Payment.API.csproj @@ -6,13 +6,9 @@ $(AssetTargetFallback);portable-net45+win8+wp8+wpa81; - - - - diff --git a/src/Services/Payment/Payment.API/Startup.cs b/src/Services/Payment/Payment.API/Startup.cs index 1d2ba4fb6..c26d0935a 100644 --- a/src/Services/Payment/Payment.API/Startup.cs +++ b/src/Services/Payment/Payment.API/Startup.cs @@ -31,8 +31,6 @@ namespace Payment.API // This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { - // Add framework services. - services.AddMvc(); services.Configure(Configuration); @@ -79,18 +77,6 @@ namespace Payment.API RegisterEventBus(services); - services.AddSwaggerGen(options => - { - options.DescribeAllEnumsAsStrings(); - options.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info - { - Title = "eShopOnContainers - Payment HTTP API", - Version = "v1", - Description = "The Payment Microservice HTTP API. This is a Data-Driven/CRUD microservice sample", - TermsOfService = "Terms Of Service" - }); - }); - var container = new ContainerBuilder(); container.Populate(services); return new AutofacServiceProvider(container.Build()); @@ -105,14 +91,6 @@ namespace Payment.API app.UsePathBase(pathBase); } - app.UseMvcWithDefaultRoute(); - - app.UseSwagger() - .UseSwaggerUI(c => - { - c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); - }); - ConfigureEventBus(app); }