2017-05-18 08:40:35 +02:00
|
|
|
|
using Autofac;
|
|
|
|
|
using Autofac.Extensions.DependencyInjection;
|
|
|
|
|
using Basket.API.Infrastructure.Filters;
|
2017-10-23 17:39:45 +02:00
|
|
|
|
using Basket.API.Infrastructure.Middlewares;
|
2017-04-17 12:28:12 +02:00
|
|
|
|
using Basket.API.IntegrationEvents.EventHandling;
|
|
|
|
|
using Basket.API.IntegrationEvents.Events;
|
2018-11-30 17:43:22 +01:00
|
|
|
|
using HealthChecks.UI.Client;
|
|
|
|
|
|
2017-10-13 11:35:26 +02:00
|
|
|
|
using Microsoft.ApplicationInsights.Extensibility;
|
|
|
|
|
using Microsoft.ApplicationInsights.ServiceFabric;
|
2017-08-29 18:11:30 +02:00
|
|
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
2016-09-06 17:09:19 -07:00
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
2018-11-30 17:43:22 +01:00
|
|
|
|
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
2016-09-06 17:09:19 -07:00
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
2017-05-18 08:40:35 +02:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2018-11-14 16:21:50 +01:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2017-08-29 10:20:13 +02:00
|
|
|
|
using Microsoft.Azure.ServiceBus;
|
2017-05-03 10:59:36 +02:00
|
|
|
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus;
|
2017-04-17 12:28:12 +02:00
|
|
|
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions;
|
|
|
|
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ;
|
2017-08-29 10:20:13 +02:00
|
|
|
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus;
|
2017-04-17 12:28:12 +02:00
|
|
|
|
using Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.EventHandling;
|
|
|
|
|
using Microsoft.eShopOnContainers.Services.Basket.API.IntegrationEvents.Events;
|
|
|
|
|
using Microsoft.eShopOnContainers.Services.Basket.API.Model;
|
2017-05-18 08:40:35 +02:00
|
|
|
|
using Microsoft.eShopOnContainers.Services.Basket.API.Services;
|
2016-09-06 17:09:19 -07:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2019-01-03 17:11:56 +01:00
|
|
|
|
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
2016-09-06 17:09:19 -07:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2016-10-17 20:10:18 -07:00
|
|
|
|
using Microsoft.Extensions.Options;
|
2017-04-20 10:53:17 +02:00
|
|
|
|
using RabbitMQ.Client;
|
2017-05-27 18:35:28 +02:00
|
|
|
|
using StackExchange.Redis;
|
2017-07-12 12:10:10 +02:00
|
|
|
|
using Swashbuckle.AspNetCore.Swagger;
|
2017-08-29 10:20:13 +02:00
|
|
|
|
using System;
|
2017-07-12 12:10:10 +02:00
|
|
|
|
using System.Collections.Generic;
|
2017-08-29 18:11:30 +02:00
|
|
|
|
using System.IdentityModel.Tokens.Jwt;
|
2016-09-06 17:09:19 -07:00
|
|
|
|
|
2016-09-07 13:52:26 -07:00
|
|
|
|
namespace Microsoft.eShopOnContainers.Services.Basket.API
|
2016-09-06 17:09:19 -07:00
|
|
|
|
{
|
|
|
|
|
public class Startup
|
|
|
|
|
{
|
2017-08-29 10:20:13 +02:00
|
|
|
|
public Startup(IConfiguration configuration)
|
2016-09-06 17:09:19 -07:00
|
|
|
|
{
|
2017-08-29 10:20:13 +02:00
|
|
|
|
Configuration = configuration;
|
2016-09-06 17:09:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-29 10:20:13 +02:00
|
|
|
|
public IConfiguration Configuration { get; }
|
|
|
|
|
|
2016-09-06 17:09:19 -07:00
|
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
2017-05-11 13:44:38 +02:00
|
|
|
|
public IServiceProvider ConfigureServices(IServiceCollection services)
|
2017-10-11 16:26:44 +02:00
|
|
|
|
{
|
2019-01-31 13:33:36 +00:00
|
|
|
|
RegisterAppInsights(services);
|
2017-10-11 16:26:44 +02:00
|
|
|
|
|
2016-09-06 17:09:19 -07:00
|
|
|
|
// Add framework services.
|
2017-03-27 14:05:28 +02:00
|
|
|
|
services.AddMvc(options =>
|
2018-11-14 16:21:50 +01:00
|
|
|
|
{
|
|
|
|
|
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
|
|
|
|
|
options.Filters.Add(typeof(ValidateModelStateFilter));
|
2017-08-29 10:20:13 +02:00
|
|
|
|
|
2018-11-14 16:21:50 +01:00
|
|
|
|
})
|
|
|
|
|
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
|
|
|
|
|
.AddControllersAsServices();
|
2017-03-27 14:05:28 +02:00
|
|
|
|
|
2017-08-29 18:11:30 +02:00
|
|
|
|
ConfigureAuthService(services);
|
|
|
|
|
|
2018-11-30 17:43:22 +01:00
|
|
|
|
services.AddCustomHealthCheck(Configuration);
|
2017-07-12 12:10:10 +02:00
|
|
|
|
|
2019-01-31 13:33:36 +00:00
|
|
|
|
services.Configure<BasketSettings>(Configuration);
|
2017-10-11 18:53:26 +02:00
|
|
|
|
|
2017-02-26 13:03:46 -05:00
|
|
|
|
//By connecting here we are making sure that our service
|
2016-10-17 20:10:18 -07:00
|
|
|
|
//cannot start until redis is ready. This might slow down startup,
|
2017-02-26 13:03:46 -05:00
|
|
|
|
//but given that there is a delay on resolving the ip address
|
2016-10-17 20:10:18 -07:00
|
|
|
|
//and then creating the connection it seems reasonable to move
|
|
|
|
|
//that cost to startup instead of having the first request pay the
|
|
|
|
|
//penalty.
|
2017-04-20 10:53:17 +02:00
|
|
|
|
services.AddSingleton<ConnectionMultiplexer>(sp =>
|
|
|
|
|
{
|
2017-04-17 12:28:12 +02:00
|
|
|
|
var settings = sp.GetRequiredService<IOptions<BasketSettings>>().Value;
|
2017-10-13 11:35:26 +02:00
|
|
|
|
var configuration = ConfigurationOptions.Parse(settings.ConnectionString, true);
|
2017-08-29 10:20:13 +02:00
|
|
|
|
|
2017-05-27 18:35:28 +02:00
|
|
|
|
configuration.ResolveDns = true;
|
2017-04-17 12:28:12 +02:00
|
|
|
|
|
2017-05-27 18:35:28 +02:00
|
|
|
|
return ConnectionMultiplexer.Connect(configuration);
|
2016-10-17 20:10:18 -07:00
|
|
|
|
});
|
|
|
|
|
|
2017-04-20 10:53:17 +02:00
|
|
|
|
|
2017-05-24 19:23:14 +02:00
|
|
|
|
if (Configuration.GetValue<bool>("AzureServiceBusEnabled"))
|
2017-04-17 12:28:12 +02:00
|
|
|
|
{
|
2017-05-24 15:33:38 +02:00
|
|
|
|
services.AddSingleton<IServiceBusPersisterConnection>(sp =>
|
2017-04-20 10:53:17 +02:00
|
|
|
|
{
|
2017-05-24 15:33:38 +02:00
|
|
|
|
var logger = sp.GetRequiredService<ILogger<DefaultServiceBusPersisterConnection>>();
|
|
|
|
|
|
2017-06-30 08:59:26 +02:00
|
|
|
|
var serviceBusConnectionString = Configuration["EventBusConnection"];
|
|
|
|
|
var serviceBusConnection = new ServiceBusConnectionStringBuilder(serviceBusConnectionString);
|
2017-05-24 15:33:38 +02:00
|
|
|
|
|
2017-05-24 18:59:29 +02:00
|
|
|
|
return new DefaultServiceBusPersisterConnection(serviceBusConnection, logger);
|
2017-05-24 15:33:38 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
services.AddSingleton<IRabbitMQPersistentConnection>(sp =>
|
|
|
|
|
{
|
|
|
|
|
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>();
|
2017-06-30 08:59:26 +02:00
|
|
|
|
|
2017-05-24 15:33:38 +02:00
|
|
|
|
var factory = new ConnectionFactory()
|
|
|
|
|
{
|
2019-04-02 15:36:20 +01:00
|
|
|
|
HostName = Configuration["EventBusConnection"],
|
|
|
|
|
DispatchConsumersAsync = true
|
2017-05-24 15:33:38 +02:00
|
|
|
|
};
|
|
|
|
|
|
2017-10-13 11:35:26 +02:00
|
|
|
|
if (!string.IsNullOrEmpty(Configuration["EventBusUserName"]))
|
|
|
|
|
{
|
2017-09-05 15:55:17 +02:00
|
|
|
|
factory.UserName = Configuration["EventBusUserName"];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(Configuration["EventBusPassword"]))
|
|
|
|
|
{
|
|
|
|
|
factory.Password = Configuration["EventBusPassword"];
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-12 09:25:01 +01:00
|
|
|
|
var retryCount = 5;
|
|
|
|
|
if (!string.IsNullOrEmpty(Configuration["EventBusRetryCount"]))
|
|
|
|
|
{
|
|
|
|
|
retryCount = int.Parse(Configuration["EventBusRetryCount"]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new DefaultRabbitMQPersistentConnection(factory, logger, retryCount);
|
2017-05-24 15:33:38 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
2017-04-17 12:28:12 +02:00
|
|
|
|
|
2017-06-30 08:59:26 +02:00
|
|
|
|
RegisterEventBus(services);
|
|
|
|
|
|
2017-05-18 21:50:51 +03:00
|
|
|
|
services.AddSwaggerGen(options =>
|
2016-12-19 10:20:02 +01:00
|
|
|
|
{
|
|
|
|
|
options.DescribeAllEnumsAsStrings();
|
2017-08-29 10:20:13 +02:00
|
|
|
|
options.SwaggerDoc("v1", new Info
|
2016-12-19 10:20:02 +01:00
|
|
|
|
{
|
|
|
|
|
Title = "Basket HTTP API",
|
|
|
|
|
Version = "v1",
|
|
|
|
|
Description = "The Basket Service HTTP API",
|
|
|
|
|
TermsOfService = "Terms Of Service"
|
|
|
|
|
});
|
2017-07-12 12:10:10 +02:00
|
|
|
|
|
|
|
|
|
options.AddSecurityDefinition("oauth2", new OAuth2Scheme
|
|
|
|
|
{
|
|
|
|
|
Type = "oauth2",
|
|
|
|
|
Flow = "implicit",
|
|
|
|
|
AuthorizationUrl = $"{Configuration.GetValue<string>("IdentityUrlExternal")}/connect/authorize",
|
|
|
|
|
TokenUrl = $"{Configuration.GetValue<string>("IdentityUrlExternal")}/connect/token",
|
|
|
|
|
Scopes = new Dictionary<string, string>()
|
|
|
|
|
{
|
|
|
|
|
{ "basket", "Basket API" }
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
options.OperationFilter<AuthorizeCheckOperationFilter>();
|
2016-12-19 10:20:02 +01:00
|
|
|
|
});
|
|
|
|
|
|
2016-11-29 15:10:16 +01:00
|
|
|
|
services.AddCors(options =>
|
|
|
|
|
{
|
|
|
|
|
options.AddPolicy("CorsPolicy",
|
2019-01-04 13:39:25 +01:00
|
|
|
|
builder => builder
|
|
|
|
|
.SetIsOriginAllowed((host) => true)
|
2016-11-29 15:10:16 +01:00
|
|
|
|
.AllowAnyMethod()
|
|
|
|
|
.AllowAnyHeader()
|
|
|
|
|
.AllowCredentials());
|
|
|
|
|
});
|
2017-05-08 13:36:31 +02:00
|
|
|
|
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
2016-10-17 20:10:18 -07:00
|
|
|
|
services.AddTransient<IBasketRepository, RedisBasketRepository>();
|
2017-05-08 13:36:31 +02:00
|
|
|
|
services.AddTransient<IIdentityService, IdentityService>();
|
2017-10-13 11:35:26 +02:00
|
|
|
|
|
2017-05-18 08:40:35 +02:00
|
|
|
|
services.AddOptions();
|
2017-05-11 13:44:38 +02:00
|
|
|
|
|
|
|
|
|
var container = new ContainerBuilder();
|
|
|
|
|
container.Populate(services);
|
2017-08-29 10:20:13 +02:00
|
|
|
|
|
2017-05-11 13:44:38 +02:00
|
|
|
|
return new AutofacServiceProvider(container.Build());
|
2017-05-03 10:59:36 +02:00
|
|
|
|
}
|
2017-10-13 11:35:26 +02:00
|
|
|
|
|
2017-08-29 10:20:13 +02:00
|
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
2017-10-11 16:26:44 +02:00
|
|
|
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
2017-08-29 10:20:13 +02:00
|
|
|
|
{
|
2019-02-06 13:03:54 +00:00
|
|
|
|
//loggerFactory.AddAzureWebAppDiagnostics();
|
|
|
|
|
//loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace);
|
2017-09-07 19:18:53 +02:00
|
|
|
|
|
|
|
|
|
var pathBase = Configuration["PATH_BASE"];
|
|
|
|
|
if (!string.IsNullOrEmpty(pathBase))
|
|
|
|
|
{
|
|
|
|
|
app.UsePathBase(pathBase);
|
2017-10-11 16:26:44 +02:00
|
|
|
|
}
|
2018-01-22 11:46:18 +01:00
|
|
|
|
|
2018-11-30 17:43:22 +01:00
|
|
|
|
app.UseHealthChecks("/hc", new HealthCheckOptions()
|
|
|
|
|
{
|
|
|
|
|
Predicate = _ => true,
|
|
|
|
|
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
|
|
|
|
|
});
|
2018-01-22 11:46:18 +01:00
|
|
|
|
|
2019-01-03 17:11:56 +01:00
|
|
|
|
app.UseHealthChecks("/liveness", new HealthCheckOptions
|
|
|
|
|
{
|
|
|
|
|
Predicate = r => r.Name.Contains("self")
|
|
|
|
|
});
|
2018-01-22 11:46:18 +01:00
|
|
|
|
|
2017-08-29 10:20:13 +02:00
|
|
|
|
app.UseStaticFiles();
|
|
|
|
|
app.UseCors("CorsPolicy");
|
2017-08-29 12:48:04 +02:00
|
|
|
|
|
2017-08-29 18:11:30 +02:00
|
|
|
|
ConfigureAuth(app);
|
2017-08-29 12:48:04 +02:00
|
|
|
|
|
2017-08-29 10:20:13 +02:00
|
|
|
|
app.UseMvcWithDefaultRoute();
|
|
|
|
|
|
|
|
|
|
app.UseSwagger()
|
|
|
|
|
.UseSwaggerUI(c =>
|
|
|
|
|
{
|
2017-10-27 14:28:27 -07:00
|
|
|
|
c.SwaggerEndpoint($"{ (!string.IsNullOrEmpty(pathBase) ? pathBase : string.Empty) }/swagger/v1/swagger.json", "Basket.API V1");
|
2018-03-04 13:53:59 +03:00
|
|
|
|
c.OAuthClientId ("basketswaggerui");
|
|
|
|
|
c.OAuthAppName("Basket Swagger UI");
|
2017-08-29 10:20:13 +02:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
ConfigureEventBus(app);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-13 11:35:26 +02:00
|
|
|
|
private void RegisterAppInsights(IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
services.AddApplicationInsightsTelemetry(Configuration);
|
2017-10-16 16:10:40 +02:00
|
|
|
|
var orchestratorType = Configuration.GetValue<string>("OrchestratorType");
|
2017-10-23 17:39:45 +02:00
|
|
|
|
|
|
|
|
|
if (orchestratorType?.ToUpper() == "K8S")
|
2017-10-13 11:35:26 +02:00
|
|
|
|
{
|
|
|
|
|
// Enable K8s telemetry initializer
|
2019-02-19 12:07:04 +03:00
|
|
|
|
services.AddApplicationInsightsKubernetesEnricher();
|
2017-10-13 11:35:26 +02:00
|
|
|
|
}
|
2017-10-23 17:39:45 +02:00
|
|
|
|
if (orchestratorType?.ToUpper() == "SF")
|
2017-10-13 11:35:26 +02:00
|
|
|
|
{
|
|
|
|
|
// Enable SF telemetry initializer
|
|
|
|
|
services.AddSingleton<ITelemetryInitializer>((serviceProvider) =>
|
|
|
|
|
new FabricTelemetryInitializer());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-29 18:11:30 +02:00
|
|
|
|
private void ConfigureAuthService(IServiceCollection services)
|
|
|
|
|
{
|
|
|
|
|
// prevent from mapping "sub" claim to nameidentifier.
|
|
|
|
|
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
|
|
|
|
|
|
2017-10-11 18:53:26 +02:00
|
|
|
|
var identityUrl = Configuration.GetValue<string>("IdentityUrl");
|
|
|
|
|
|
2017-08-29 18:11:30 +02:00
|
|
|
|
services.AddAuthentication(options =>
|
|
|
|
|
{
|
|
|
|
|
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
|
|
|
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
|
|
|
|
|
|
|
|
|
}).AddJwtBearer(options =>
|
|
|
|
|
{
|
|
|
|
|
options.Authority = identityUrl;
|
|
|
|
|
options.RequireHttpsMetadata = false;
|
|
|
|
|
options.Audience = "basket";
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual void ConfigureAuth(IApplicationBuilder app)
|
|
|
|
|
{
|
2017-10-23 17:39:45 +02:00
|
|
|
|
if (Configuration.GetValue<bool>("UseLoadTest"))
|
|
|
|
|
{
|
|
|
|
|
app.UseMiddleware<ByPassAuthMiddleware>();
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-29 18:11:30 +02:00
|
|
|
|
app.UseAuthentication();
|
|
|
|
|
}
|
2017-08-29 10:20:13 +02:00
|
|
|
|
|
2017-05-26 01:35:44 +02:00
|
|
|
|
private void RegisterEventBus(IServiceCollection services)
|
2017-05-03 10:59:36 +02:00
|
|
|
|
{
|
2017-11-10 17:37:18 +01:00
|
|
|
|
var subscriptionClientName = Configuration["SubscriptionClientName"];
|
|
|
|
|
|
2017-05-24 19:23:14 +02:00
|
|
|
|
if (Configuration.GetValue<bool>("AzureServiceBusEnabled"))
|
2017-05-24 15:33:38 +02:00
|
|
|
|
{
|
|
|
|
|
services.AddSingleton<IEventBus, EventBusServiceBus>(sp =>
|
|
|
|
|
{
|
|
|
|
|
var serviceBusPersisterConnection = sp.GetRequiredService<IServiceBusPersisterConnection>();
|
2017-06-26 18:05:02 +02:00
|
|
|
|
var iLifetimeScope = sp.GetRequiredService<ILifetimeScope>();
|
2017-05-24 15:33:38 +02:00
|
|
|
|
var logger = sp.GetRequiredService<ILogger<EventBusServiceBus>>();
|
2017-11-10 17:37:18 +01:00
|
|
|
|
var eventBusSubcriptionsManager = sp.GetRequiredService<IEventBusSubscriptionsManager>();
|
2017-05-24 15:33:38 +02:00
|
|
|
|
|
2017-08-29 10:20:13 +02:00
|
|
|
|
return new EventBusServiceBus(serviceBusPersisterConnection, logger,
|
2017-06-26 18:05:02 +02:00
|
|
|
|
eventBusSubcriptionsManager, subscriptionClientName, iLifetimeScope);
|
2017-05-24 15:33:38 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-10-12 09:25:01 +01:00
|
|
|
|
services.AddSingleton<IEventBus, EventBusRabbitMQ>(sp =>
|
|
|
|
|
{
|
|
|
|
|
var rabbitMQPersistentConnection = sp.GetRequiredService<IRabbitMQPersistentConnection>();
|
|
|
|
|
var iLifetimeScope = sp.GetRequiredService<ILifetimeScope>();
|
|
|
|
|
var logger = sp.GetRequiredService<ILogger<EventBusRabbitMQ>>();
|
|
|
|
|
var eventBusSubcriptionsManager = sp.GetRequiredService<IEventBusSubscriptionsManager>();
|
|
|
|
|
|
|
|
|
|
var retryCount = 5;
|
|
|
|
|
if (!string.IsNullOrEmpty(Configuration["EventBusRetryCount"]))
|
|
|
|
|
{
|
|
|
|
|
retryCount = int.Parse(Configuration["EventBusRetryCount"]);
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-10 17:37:18 +01:00
|
|
|
|
return new EventBusRabbitMQ(rabbitMQPersistentConnection, logger, iLifetimeScope, eventBusSubcriptionsManager, subscriptionClientName, retryCount);
|
2017-10-12 09:25:01 +01:00
|
|
|
|
});
|
2017-05-24 15:33:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-03 10:59:36 +02:00
|
|
|
|
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
|
|
|
|
|
|
|
|
|
|
services.AddTransient<ProductPriceChangedIntegrationEventHandler>();
|
|
|
|
|
services.AddTransient<OrderStartedIntegrationEventHandler>();
|
2016-09-06 17:09:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-29 10:20:13 +02:00
|
|
|
|
private void ConfigureEventBus(IApplicationBuilder app)
|
2017-04-17 12:28:12 +02:00
|
|
|
|
{
|
2017-05-03 10:59:36 +02:00
|
|
|
|
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
|
2017-08-29 10:20:13 +02:00
|
|
|
|
|
2017-05-11 13:44:38 +02:00
|
|
|
|
eventBus.Subscribe<ProductPriceChangedIntegrationEvent, ProductPriceChangedIntegrationEventHandler>();
|
|
|
|
|
eventBus.Subscribe<OrderStartedIntegrationEvent, OrderStartedIntegrationEventHandler>();
|
2018-11-30 17:43:22 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class CustomExtensionMethods
|
|
|
|
|
{
|
|
|
|
|
public static IServiceCollection AddCustomHealthCheck(this IServiceCollection services, IConfiguration configuration)
|
|
|
|
|
{
|
|
|
|
|
var hcBuilder = services.AddHealthChecks();
|
|
|
|
|
|
2019-01-03 17:11:56 +01:00
|
|
|
|
hcBuilder.AddCheck("self", () => HealthCheckResult.Healthy());
|
|
|
|
|
|
2018-11-30 17:43:22 +01:00
|
|
|
|
hcBuilder
|
|
|
|
|
.AddRedis(
|
|
|
|
|
configuration["ConnectionString"],
|
|
|
|
|
name: "redis-check",
|
|
|
|
|
tags: new string[] { "redis" });
|
|
|
|
|
|
|
|
|
|
if (configuration.GetValue<bool>("AzureServiceBusEnabled"))
|
|
|
|
|
{
|
|
|
|
|
hcBuilder
|
|
|
|
|
.AddAzureServiceBusTopic(
|
|
|
|
|
configuration["EventBusConnection"],
|
|
|
|
|
topicName: "eshop_event_bus",
|
|
|
|
|
name: "basket-servicebus-check",
|
|
|
|
|
tags: new string[] { "servicebus" });
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
hcBuilder
|
|
|
|
|
.AddRabbitMQ(
|
|
|
|
|
$"amqp://{configuration["EventBusConnection"]}",
|
|
|
|
|
name: "basket-rabbitmqbus-check",
|
|
|
|
|
tags: new string[] { "rabbitmqbus" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return services;
|
2017-04-17 12:28:12 +02:00
|
|
|
|
}
|
2016-09-06 17:09:19 -07:00
|
|
|
|
}
|
|
|
|
|
}
|