mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-04-28 16:52:47 +08:00
commit
dcfe3a8abf
@ -8,6 +8,10 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Ardalis.GuardClauses" Version="3.3.0" />
|
<PackageReference Include="Ardalis.GuardClauses" Version="3.3.0" />
|
||||||
|
<PackageReference Include="AspNetCore.HealthChecks.Elasticsearch" Version="6.0.1" />
|
||||||
|
<PackageReference Include="AspNetCore.HealthChecks.EventStore" Version="5.0.1" />
|
||||||
|
<PackageReference Include="AspNetCore.HealthChecks.Rabbitmq" Version="6.0.1" />
|
||||||
|
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="6.0.2" />
|
||||||
<PackageReference Include="AspNetCore.HealthChecks.UI.SQLite.Storage" Version="5.0.1" />
|
<PackageReference Include="AspNetCore.HealthChecks.UI.SQLite.Storage" Version="5.0.1" />
|
||||||
<PackageReference Include="Ben.BlockingDetector" Version="0.0.4" />
|
<PackageReference Include="Ben.BlockingDetector" Version="0.0.4" />
|
||||||
<PackageReference Include="EasyCaching.Core" Version="1.4.1" />
|
<PackageReference Include="EasyCaching.Core" Version="1.4.1" />
|
||||||
@ -66,8 +70,8 @@
|
|||||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.2.3" />
|
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.2.3" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.2.3" />
|
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.2.3" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||||
<PackageReference Include="AspNetCore.HealthChecks.UI" Version="5.0.1" />
|
<PackageReference Include="AspNetCore.HealthChecks.UI" Version="6.0.2" />
|
||||||
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="5.0.1" />
|
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="6.0.2" />
|
||||||
<PackageReference Include="AspNetCore.HealthChecks.UI.InMemory.Storage" Version="5.0.1" />
|
<PackageReference Include="AspNetCore.HealthChecks.UI.InMemory.Storage" Version="5.0.1" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="6.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="6.0.1" />
|
||||||
<PackageReference Include="AspNetCore.HealthChecks.MongoDb" Version="6.0.1" />
|
<PackageReference Include="AspNetCore.HealthChecks.MongoDb" Version="6.0.1" />
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
namespace BuildingBlocks.EFCore;
|
namespace BuildingBlocks.EFCore;
|
||||||
|
|
||||||
public class DatabaseOptions
|
public class SqlOptions
|
||||||
{
|
{
|
||||||
public string ConnectionString { get; set; }
|
public string DefaultConnection { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
56
src/BuildingBlocks/HealthCheck/Extensions.cs
Normal file
56
src/BuildingBlocks/HealthCheck/Extensions.cs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
using BuildingBlocks.EFCore;
|
||||||
|
using BuildingBlocks.MassTransit;
|
||||||
|
using BuildingBlocks.Web;
|
||||||
|
using HealthChecks.UI.Client;
|
||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
||||||
|
|
||||||
|
namespace BuildingBlocks.HealthCheck;
|
||||||
|
|
||||||
|
public static class Extensions
|
||||||
|
{
|
||||||
|
public static IServiceCollection AddCustomHealthCheck(this IServiceCollection services)
|
||||||
|
{
|
||||||
|
var sqlOptions = services.GetOptions<SqlOptions>("ConnectionStrings");
|
||||||
|
var rabbitMqOptions = services.GetOptions<RabbitMqOptions>("RabbitMq");
|
||||||
|
|
||||||
|
services.AddHealthChecks()
|
||||||
|
.AddSqlServer(sqlOptions.DefaultConnection)
|
||||||
|
.AddRabbitMQ(rabbitConnectionString:
|
||||||
|
$"amqp://{rabbitMqOptions.UserName}:{rabbitMqOptions.Password}@{rabbitMqOptions.HostName}");
|
||||||
|
|
||||||
|
services.AddHealthChecksUI(setup =>
|
||||||
|
{
|
||||||
|
setup.SetEvaluationTimeInSeconds(60); // time in seconds between check
|
||||||
|
setup.AddHealthCheckEndpoint("Basic Health Check", "/healthz");
|
||||||
|
}).AddInMemoryStorage();
|
||||||
|
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static WebApplication UseCustomHealthCheck(this WebApplication app)
|
||||||
|
{
|
||||||
|
app.UseHealthChecks("/healthz",
|
||||||
|
new HealthCheckOptions
|
||||||
|
{
|
||||||
|
Predicate = _ => true,
|
||||||
|
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse,
|
||||||
|
ResultStatusCodes =
|
||||||
|
{
|
||||||
|
[HealthStatus.Healthy] = StatusCodes.Status200OK,
|
||||||
|
[HealthStatus.Degraded] = StatusCodes.Status500InternalServerError,
|
||||||
|
[HealthStatus.Unhealthy] = StatusCodes.Status503ServiceUnavailable
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.UseHealthChecksUI(options =>
|
||||||
|
{
|
||||||
|
options.ApiPath = "/healthcheck";
|
||||||
|
options.UIPath = "/healthcheck-ui";
|
||||||
|
});
|
||||||
|
|
||||||
|
return app;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -5,6 +5,7 @@ using Booking.Extensions;
|
|||||||
using BuildingBlocks.Domain;
|
using BuildingBlocks.Domain;
|
||||||
using BuildingBlocks.EFCore;
|
using BuildingBlocks.EFCore;
|
||||||
using BuildingBlocks.EventStoreDB;
|
using BuildingBlocks.EventStoreDB;
|
||||||
|
using BuildingBlocks.HealthCheck;
|
||||||
using BuildingBlocks.IdsGenerator;
|
using BuildingBlocks.IdsGenerator;
|
||||||
using BuildingBlocks.Jwt;
|
using BuildingBlocks.Jwt;
|
||||||
using BuildingBlocks.Logging;
|
using BuildingBlocks.Logging;
|
||||||
@ -46,7 +47,7 @@ builder.Services.AddHttpContextAccessor();
|
|||||||
|
|
||||||
builder.Services.AddTransient<IEventMapper, EventMapper>();
|
builder.Services.AddTransient<IEventMapper, EventMapper>();
|
||||||
builder.Services.AddTransient<IBusPublisher, BusPublisher>();
|
builder.Services.AddTransient<IBusPublisher, BusPublisher>();
|
||||||
|
builder.Services.AddCustomHealthCheck();
|
||||||
builder.Services.AddCustomMassTransit(typeof(BookingRoot).Assembly, env);
|
builder.Services.AddCustomMassTransit(typeof(BookingRoot).Assembly, env);
|
||||||
builder.Services.AddCustomOpenTelemetry();
|
builder.Services.AddCustomOpenTelemetry();
|
||||||
builder.Services.AddTransient<AuthHeaderHandler>();
|
builder.Services.AddTransient<AuthHeaderHandler>();
|
||||||
@ -76,6 +77,7 @@ app.UseHttpsRedirection();
|
|||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
app.UseProblemDetails();
|
app.UseProblemDetails();
|
||||||
|
app.UseCustomHealthCheck();
|
||||||
|
|
||||||
app.UseEndpoints(endpoints =>
|
app.UseEndpoints(endpoints =>
|
||||||
{
|
{
|
||||||
|
|||||||
@ -3,6 +3,7 @@ using BuildingBlocks.Caching;
|
|||||||
using BuildingBlocks.Domain;
|
using BuildingBlocks.Domain;
|
||||||
using BuildingBlocks.EFCore;
|
using BuildingBlocks.EFCore;
|
||||||
using BuildingBlocks.Exception;
|
using BuildingBlocks.Exception;
|
||||||
|
using BuildingBlocks.HealthCheck;
|
||||||
using BuildingBlocks.IdsGenerator;
|
using BuildingBlocks.IdsGenerator;
|
||||||
using BuildingBlocks.Jwt;
|
using BuildingBlocks.Jwt;
|
||||||
using BuildingBlocks.Logging;
|
using BuildingBlocks.Logging;
|
||||||
@ -17,7 +18,9 @@ using Flight.Data;
|
|||||||
using Flight.Data.Seed;
|
using Flight.Data.Seed;
|
||||||
using Flight.Extensions;
|
using Flight.Extensions;
|
||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
|
using HealthChecks.UI.Client;
|
||||||
using Hellang.Middleware.ProblemDetails;
|
using Hellang.Middleware.ProblemDetails;
|
||||||
|
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||||
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
||||||
using Prometheus;
|
using Prometheus;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
@ -48,6 +51,7 @@ builder.Services.AddTransient<IEventMapper, EventMapper>();
|
|||||||
builder.Services.AddCustomMassTransit(typeof(FlightRoot).Assembly, env);
|
builder.Services.AddCustomMassTransit(typeof(FlightRoot).Assembly, env);
|
||||||
builder.Services.AddCustomOpenTelemetry();
|
builder.Services.AddCustomOpenTelemetry();
|
||||||
builder.Services.AddRouting(options => options.LowercaseUrls = true);
|
builder.Services.AddRouting(options => options.LowercaseUrls = true);
|
||||||
|
builder.Services.AddCustomHealthCheck();
|
||||||
|
|
||||||
builder.Services.AddGrpc(options =>
|
builder.Services.AddGrpc(options =>
|
||||||
{
|
{
|
||||||
@ -58,10 +62,7 @@ builder.Services.AddMagicOnion();
|
|||||||
|
|
||||||
SnowFlakIdGenerator.Configure(1);
|
SnowFlakIdGenerator.Configure(1);
|
||||||
|
|
||||||
builder.Services.AddCachingRequest(new List<Assembly>
|
builder.Services.AddCachingRequest(new List<Assembly> {typeof(FlightRoot).Assembly});
|
||||||
{
|
|
||||||
typeof(FlightRoot).Assembly
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.Services.AddEasyCaching(options => { options.UseInMemory(configuration, "mem"); });
|
builder.Services.AddEasyCaching(options => { options.UseInMemory(configuration, "mem"); });
|
||||||
|
|
||||||
@ -80,6 +81,7 @@ app.UseHttpMetrics();
|
|||||||
app.UseMigrations();
|
app.UseMigrations();
|
||||||
app.UseProblemDetails();
|
app.UseProblemDetails();
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
|
app.UseCustomHealthCheck();
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
@ -93,4 +95,6 @@ app.UseEndpoints(endpoints =>
|
|||||||
app.MapGet("/", x => x.Response.WriteAsync(appOptions.Name));
|
app.MapGet("/", x => x.Response.WriteAsync(appOptions.Name));
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|
||||||
public partial class Program {}
|
public partial class Program
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|||||||
@ -20,11 +20,5 @@
|
|||||||
"UserName": "guest",
|
"UserName": "guest",
|
||||||
"Password": "guest"
|
"Password": "guest"
|
||||||
},
|
},
|
||||||
"Kestrel": {
|
|
||||||
"EndpointDefaults": {
|
|
||||||
"Protocols": "Http2",
|
|
||||||
"Url": "https://localhost:5003"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
using BuildingBlocks.Domain;
|
using BuildingBlocks.Domain;
|
||||||
using BuildingBlocks.EFCore;
|
using BuildingBlocks.EFCore;
|
||||||
|
using BuildingBlocks.HealthCheck;
|
||||||
using BuildingBlocks.Logging;
|
using BuildingBlocks.Logging;
|
||||||
using BuildingBlocks.Mapster;
|
using BuildingBlocks.Mapster;
|
||||||
using BuildingBlocks.MassTransit;
|
using BuildingBlocks.MassTransit;
|
||||||
@ -42,7 +43,7 @@ builder.Services.AddValidatorsFromAssembly(typeof(IdentityRoot).Assembly);
|
|||||||
builder.Services.AddCustomProblemDetails();
|
builder.Services.AddCustomProblemDetails();
|
||||||
builder.Services.AddCustomMapster(typeof(IdentityRoot).Assembly);
|
builder.Services.AddCustomMapster(typeof(IdentityRoot).Assembly);
|
||||||
builder.Services.AddScoped<IDataSeeder, IdentityDataSeeder>();
|
builder.Services.AddScoped<IDataSeeder, IdentityDataSeeder>();
|
||||||
|
builder.Services.AddCustomHealthCheck();
|
||||||
builder.Services.AddTransient<IEventMapper, EventMapper>();
|
builder.Services.AddTransient<IEventMapper, EventMapper>();
|
||||||
builder.Services.AddTransient<IBusPublisher, BusPublisher>();
|
builder.Services.AddTransient<IBusPublisher, BusPublisher>();
|
||||||
|
|
||||||
@ -69,6 +70,7 @@ app.UseHttpsRedirection();
|
|||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
app.UseIdentityServer();
|
app.UseIdentityServer();
|
||||||
|
app.UseCustomHealthCheck();
|
||||||
|
|
||||||
app.UseEndpoints(endpoints =>
|
app.UseEndpoints(endpoints =>
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
using BuildingBlocks.Domain;
|
using BuildingBlocks.Domain;
|
||||||
using BuildingBlocks.EFCore;
|
using BuildingBlocks.EFCore;
|
||||||
using BuildingBlocks.Exception;
|
using BuildingBlocks.Exception;
|
||||||
|
using BuildingBlocks.HealthCheck;
|
||||||
using BuildingBlocks.IdsGenerator;
|
using BuildingBlocks.IdsGenerator;
|
||||||
using BuildingBlocks.Jwt;
|
using BuildingBlocks.Jwt;
|
||||||
using BuildingBlocks.Logging;
|
using BuildingBlocks.Logging;
|
||||||
@ -39,7 +40,7 @@ builder.Services.AddCustomProblemDetails();
|
|||||||
builder.Services.AddCustomMapster(typeof(PassengerRoot).Assembly);
|
builder.Services.AddCustomMapster(typeof(PassengerRoot).Assembly);
|
||||||
builder.Services.AddHttpContextAccessor();
|
builder.Services.AddHttpContextAccessor();
|
||||||
builder.Services.AddTransient<IEventMapper, EventMapper>();
|
builder.Services.AddTransient<IEventMapper, EventMapper>();
|
||||||
|
builder.Services.AddCustomHealthCheck();
|
||||||
builder.Services.AddCustomMassTransit(typeof(PassengerRoot).Assembly, env);
|
builder.Services.AddCustomMassTransit(typeof(PassengerRoot).Assembly, env);
|
||||||
builder.Services.AddCustomOpenTelemetry();
|
builder.Services.AddCustomOpenTelemetry();
|
||||||
builder.Services.AddGrpc(options =>
|
builder.Services.AddGrpc(options =>
|
||||||
@ -67,6 +68,7 @@ app.UseProblemDetails();
|
|||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
app.UseCustomHealthCheck();
|
||||||
|
|
||||||
app.UseEndpoints(endpoints =>
|
app.UseEndpoints(endpoints =>
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user