Merge from gababu : Add Basket signalR projectpull/1207/head
@ -0,0 +1,29 @@ | |||||
using Autofac; | |||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Reflection; | |||||
using System.Threading.Tasks; | |||||
namespace Basket.SignalrHub.AutofacModules | |||||
{ | |||||
public class ApplicationModule | |||||
: Autofac.Module | |||||
{ | |||||
public string QueriesConnectionString { get; } | |||||
public ApplicationModule() | |||||
{ | |||||
} | |||||
protected override void Load(ContainerBuilder builder) | |||||
{ | |||||
// New integration event registrations go here | |||||
// builder.RegisterAssemblyTypes(typeof(NewIntegrationEvent).GetTypeInfo().Assembly) | |||||
// .AsClosedTypesOf(typeof(IIntegrationEventHandler<>)); | |||||
} | |||||
} | |||||
} |
@ -0,0 +1,44 @@ | |||||
<Project Sdk="Microsoft.NET.Sdk.Web"> | |||||
<PropertyGroup> | |||||
<TargetFramework>netcoreapp2.2</TargetFramework> | |||||
<DockerComposeProjectPath>..\..\..\..\docker-compose.dcproj</DockerComposeProjectPath> | |||||
</PropertyGroup> | |||||
<ItemGroup> | |||||
<Folder Include="IntegrationEvents\EventHandling\" /> | |||||
<Folder Include="IntegrationEvents\Events\" /> | |||||
<Folder Include="wwwroot\" /> | |||||
</ItemGroup> | |||||
<ItemGroup> | |||||
<PackageReference Include="AspNetCore.HealthChecks.AzureServiceBus" Version="2.2.0" /> | |||||
<PackageReference Include="AspNetCore.HealthChecks.Rabbitmq" Version="2.2.0" /> | |||||
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="2.2.4" /> | |||||
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.2.1" /> | |||||
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.2.1" /> | |||||
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.6.1" /> | |||||
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="1.0.2" /> | |||||
<PackageReference Include="Microsoft.ApplicationInsights.ServiceFabric" Version="2.2.2" /> | |||||
<PackageReference Include="Microsoft.AspNetCore.App" /> | |||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" Version="2.2.0" /> | |||||
<PackageReference Include="Microsoft.AspNetCore.HealthChecks" Version="1.0.0" /> | |||||
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" /> | |||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Core" Version="1.1.0" /> | |||||
<PackageReference Include="Microsoft.AspNetCore.SignalR.Redis" Version="1.1.0" /> | |||||
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="2.2.0" /> | |||||
<PackageReference Include="Serilog.AspNetCore" Version="2.1.1" /> | |||||
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.1.3" /> | |||||
<PackageReference Include="Serilog.Settings.Configuration" Version="3.0.1" /> | |||||
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" /> | |||||
<PackageReference Include="Serilog.Sinks.Seq" Version="4.0.0" /> | |||||
<PackageReference Include="Serilog.Sinks.Http" Version="4.2.1" /> | |||||
</ItemGroup> | |||||
<ItemGroup> | |||||
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBusRabbitMQ\EventBusRabbitMQ.csproj" /> | |||||
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBusServiceBus\EventBusServiceBus.csproj" /> | |||||
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBus\EventBus.csproj" /> | |||||
</ItemGroup> | |||||
</Project> |
@ -0,0 +1,60 @@ | |||||
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS base | |||||
WORKDIR /app | |||||
EXPOSE 80 | |||||
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build | |||||
WORKDIR /src | |||||
# Keep the project list and command dotnet restore identical in all Dockfiles to maximize image cache utilization | |||||
COPY eShopOnContainers-ServicesAndWebApps.sln . | |||||
COPY docker-compose.dcproj /src/ | |||||
COPY src/ApiGateways/ApiGw-Base/OcelotApiGw.csproj src/ApiGateways/ApiGw-Base/ | |||||
COPY src/ApiGateways/Mobile.Bff.Shopping/aggregator/Mobile.Shopping.HttpAggregator.csproj src/ApiGateways/Mobile.Bff.Shopping/aggregator/ | |||||
COPY src/ApiGateways/Web.Bff.Shopping/aggregator/Web.Shopping.HttpAggregator.csproj src/ApiGateways/Web.Bff.Shopping/aggregator/ | |||||
COPY src/BuildingBlocks/Devspaces.Support/Devspaces.Support.csproj src/BuildingBlocks/Devspaces.Support/ | |||||
COPY src/BuildingBlocks/EventBus/EventBus/EventBus.csproj src/BuildingBlocks/EventBus/EventBus/ | |||||
COPY src/BuildingBlocks/EventBus/EventBus.Tests/EventBus.Tests.csproj src/BuildingBlocks/EventBus/EventBus.Tests/ | |||||
COPY src/BuildingBlocks/EventBus/EventBusRabbitMQ/EventBusRabbitMQ.csproj src/BuildingBlocks/EventBus/EventBusRabbitMQ/ | |||||
COPY src/BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.csproj src/BuildingBlocks/EventBus/EventBusServiceBus/ | |||||
COPY src/BuildingBlocks/EventBus/IntegrationEventLogEF/IntegrationEventLogEF.csproj src/BuildingBlocks/EventBus/IntegrationEventLogEF/ | |||||
COPY src/BuildingBlocks/WebHostCustomization/WebHost.Customization/WebHost.Customization.csproj src/BuildingBlocks/WebHostCustomization/WebHost.Customization/ | |||||
COPY src/Services/Basket/Basket.API/Basket.API.csproj src/Services/Basket/Basket.API/ | |||||
COPY src/Services/Basket/Basket.FunctionalTests/Basket.FunctionalTests.csproj src/Services/Basket/Basket.FunctionalTests/ | |||||
COPY src/Services/Basket/Basket.UnitTests/Basket.UnitTests.csproj src/Services/Basket/Basket.UnitTests/ | |||||
COPY src/Services/Basket/Basket.SignalrHub/Basket.SignalrHub.csproj src/Services/Basket/Basket.SignalrHub/ | |||||
COPY src/Services/Catalog/Catalog.API/Catalog.API.csproj src/Services/Catalog/Catalog.API/ | |||||
COPY src/Services/Catalog/Catalog.FunctionalTests/Catalog.FunctionalTests.csproj src/Services/Catalog/Catalog.FunctionalTests/ | |||||
COPY src/Services/Catalog/Catalog.UnitTests/Catalog.UnitTests.csproj src/Services/Catalog/Catalog.UnitTests/ | |||||
COPY src/Services/Identity/Identity.API/Identity.API.csproj src/Services/Identity/Identity.API/ | |||||
COPY src/Services/Location/Locations.API/Locations.API.csproj src/Services/Location/Locations.API/ | |||||
COPY src/Services/Location/Locations.FunctionalTests/Locations.FunctionalTests.csproj src/Services/Location/Locations.FunctionalTests/ | |||||
COPY src/Services/Marketing/Marketing.API/Marketing.API.csproj src/Services/Marketing/Marketing.API/ | |||||
COPY src/Services/Marketing/Marketing.FunctionalTests/Marketing.FunctionalTests.csproj src/Services/Marketing/Marketing.FunctionalTests/ | |||||
COPY src/Services/Ordering/Ordering.API/Ordering.API.csproj src/Services/Ordering/Ordering.API/ | |||||
COPY src/Services/Ordering/Ordering.BackgroundTasks/Ordering.BackgroundTasks.csproj src/Services/Ordering/Ordering.BackgroundTasks/ | |||||
COPY src/Services/Ordering/Ordering.Domain/Ordering.Domain.csproj src/Services/Ordering/Ordering.Domain/ | |||||
COPY src/Services/Ordering/Ordering.FunctionalTests/Ordering.FunctionalTests.csproj src/Services/Ordering/Ordering.FunctionalTests/ | |||||
COPY src/Services/Ordering/Ordering.Infrastructure/Ordering.Infrastructure.csproj src/Services/Ordering/Ordering.Infrastructure/ | |||||
COPY src/Services/Ordering/Ordering.SignalrHub/Ordering.SignalrHub.csproj src/Services/Ordering/Ordering.SignalrHub/ | |||||
COPY src/Services/Ordering/Ordering.UnitTests/Ordering.UnitTests.csproj src/Services/Ordering/Ordering.UnitTests/ | |||||
COPY src/Services/Payment/Payment.API/Payment.API.csproj src/Services/Payment/Payment.API/ | |||||
COPY src/Services/Webhooks/Webhooks.API/Webhooks.API.csproj src/Services/Webhooks/Webhooks.API/ | |||||
COPY src/Web/WebhookClient/WebhookClient.csproj src/Web/WebhookClient/ | |||||
COPY src/Web/WebMVC/WebMVC.csproj src/Web/WebMVC/ | |||||
COPY src/Web/WebSPA/WebSPA.csproj src/Web/WebSPA/ | |||||
COPY src/Web/WebStatus/WebStatus.csproj src/Web/WebStatus/ | |||||
COPY test/ServicesTests/Application.FunctionalTests/Application.FunctionalTests.csproj test/ServicesTests/Application.FunctionalTests/ | |||||
COPY test/ServicesTests/LoadTest/LoadTest.csproj test/ServicesTests/LoadTest/ | |||||
RUN dotnet restore eShopOnContainers-ServicesAndWebApps.sln | |||||
COPY . . | |||||
WORKDIR /src/src/Services/Basket/Basket.SignalrHub | |||||
RUN dotnet publish --no-restore -c Release -o /app | |||||
FROM build AS publish | |||||
FROM base AS final | |||||
WORKDIR /app | |||||
COPY --from=publish /app . | |||||
ENTRYPOINT ["dotnet", "Basket.SignalrHub.dll"] |
@ -0,0 +1,18 @@ | |||||
FROM microsoft/dotnet:2.2-sdk | |||||
ARG BUILD_CONFIGURATION=Debug | |||||
ENV ASPNETCORE_ENVIRONMENT=Development | |||||
ENV DOTNET_USE_POLLING_FILE_WATCHER=true | |||||
EXPOSE 80 | |||||
WORKDIR /src | |||||
COPY ["src/BuildingBlocks/EventBus/EventBus/EventBus.csproj", "src/BuildingBlocks/EventBus/EventBus/"] | |||||
COPY ["src/BuildingBlocks/EventBus/EventBusRabbitMQ/EventBusRabbitMQ.csproj", "src/BuildingBlocks/EventBus/EventBusRabbitMQ/"] | |||||
COPY ["src/BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.csproj", "src/BuildingBlocks/EventBus/EventBusServiceBus/"] | |||||
COPY ["src/Services/Basket/Basket.SignalrHub/Basket.SignalrHub.csproj", "src/Services/Basket/Basket.SignalrHub/"] | |||||
RUN dotnet restore src/Services/Basket/Basket.SignalrHub/Basket.SignalrHub.csproj | |||||
COPY . . | |||||
WORKDIR /src/src/Services/Basket/Basket.SignalrHub | |||||
RUN dotnet build --no-restore -c $BUILD_CONFIGURATION | |||||
ENTRYPOINT ["dotnet", "run", "--no-build", "--no-launch-profile", "-c", "$BUILD_CONFIGURATION", "--"] |
@ -0,0 +1,26 @@ | |||||
using Microsoft.AspNetCore.Authorization; | |||||
using Microsoft.AspNetCore.SignalR; | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.Linq; | |||||
using System.Threading.Tasks; | |||||
namespace Basket.SignalrHub | |||||
{ | |||||
[Authorize] | |||||
public class NotificationsHub : Hub | |||||
{ | |||||
public override async Task OnConnectedAsync() | |||||
{ | |||||
await Groups.AddToGroupAsync(Context.ConnectionId, Context.User.Identity.Name); | |||||
await base.OnConnectedAsync(); | |||||
} | |||||
public override async Task OnDisconnectedAsync(Exception ex) | |||||
{ | |||||
await Groups.RemoveFromGroupAsync(Context.ConnectionId, Context.User.Identity.Name); | |||||
await base.OnDisconnectedAsync(ex); | |||||
} | |||||
} | |||||
} |
@ -0,0 +1,80 @@ | |||||
using System; | |||||
using System.Collections.Generic; | |||||
using System.IO; | |||||
using System.Linq; | |||||
using System.Threading.Tasks; | |||||
using Microsoft.AspNetCore; | |||||
using Microsoft.AspNetCore.Hosting; | |||||
using Microsoft.Extensions.Configuration; | |||||
using Microsoft.Extensions.Logging; | |||||
using Serilog; | |||||
namespace Basket.SignalrHub | |||||
{ | |||||
public class Program | |||||
{ | |||||
public static readonly string Namespace = typeof(Program).Namespace; | |||||
public static readonly string AppName = Namespace; | |||||
public static int Main(string[] args) | |||||
{ | |||||
var configuration = GetConfiguration(); | |||||
Log.Logger = CreateSerilogLogger(configuration); | |||||
try | |||||
{ | |||||
Log.Information("Configuring web host ({ApplicationContext})...", AppName); | |||||
var host = BuildWebHost(configuration, args); | |||||
Log.Information("Starting web host ({ApplicationContext})...", AppName); | |||||
host.Run(); | |||||
return 0; | |||||
} | |||||
catch (Exception ex) | |||||
{ | |||||
Log.Fatal(ex, "Program terminated unexpectedly ({ApplicationContext})!", AppName); | |||||
return 1; | |||||
} | |||||
finally | |||||
{ | |||||
Log.CloseAndFlush(); | |||||
} | |||||
} | |||||
private static IWebHost BuildWebHost(IConfiguration configuration, string[] args) => | |||||
WebHost.CreateDefaultBuilder(args) | |||||
.CaptureStartupErrors(false) | |||||
.UseStartup<Startup>() | |||||
.UseConfiguration(configuration) | |||||
.UseSerilog() | |||||
.Build(); | |||||
private static Serilog.ILogger CreateSerilogLogger(IConfiguration configuration) | |||||
{ | |||||
var seqServerUrl = configuration["Serilog:SeqServerUrl"]; | |||||
var logstashUrl = configuration["Serilog:LogstashgUrl"]; | |||||
return new LoggerConfiguration() | |||||
.MinimumLevel.Verbose() | |||||
.Enrich.WithProperty("ApplicationContext", AppName) | |||||
.Enrich.FromLogContext() | |||||
.WriteTo.Console() | |||||
.WriteTo.Seq(string.IsNullOrWhiteSpace(seqServerUrl) ? "http://seq" : seqServerUrl) | |||||
.WriteTo.Http(string.IsNullOrWhiteSpace(logstashUrl) ? "http://logstash:8080" : logstashUrl) | |||||
.ReadFrom.Configuration(configuration) | |||||
.CreateLogger(); | |||||
} | |||||
private static IConfiguration GetConfiguration() | |||||
{ | |||||
var builder = new ConfigurationBuilder() | |||||
.SetBasePath(Directory.GetCurrentDirectory()) | |||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) | |||||
.AddEnvironmentVariables(); | |||||
return builder.Build(); | |||||
} | |||||
} | |||||
} |
@ -0,0 +1,27 @@ | |||||
{ | |||||
"iisSettings": { | |||||
"windowsAuthentication": false, | |||||
"anonymousAuthentication": true, | |||||
"iisExpress": { | |||||
"applicationUrl": "http://localhost:51313/", | |||||
"sslPort": 0 | |||||
} | |||||
}, | |||||
"profiles": { | |||||
"IIS Express": { | |||||
"commandName": "IISExpress", | |||||
"launchBrowser": true, | |||||
"environmentVariables": { | |||||
"ASPNETCORE_ENVIRONMENT": "Development" | |||||
} | |||||
}, | |||||
"Basket.SignalrHub": { | |||||
"commandName": "Project", | |||||
"launchBrowser": true, | |||||
"environmentVariables": { | |||||
"ASPNETCORE_ENVIRONMENT": "Development" | |||||
}, | |||||
"applicationUrl": "http://localhost:51314/" | |||||
} | |||||
} | |||||
} |
@ -0,0 +1,254 @@ | |||||
using Autofac; | |||||
using Autofac.Extensions.DependencyInjection; | |||||
using Microsoft.AspNetCore.Authentication.JwtBearer; | |||||
using Microsoft.AspNetCore.Builder; | |||||
using Microsoft.Azure.ServiceBus; | |||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus; | |||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; | |||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ; | |||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus; | |||||
using Microsoft.Extensions.Configuration; | |||||
using Microsoft.Extensions.DependencyInjection; | |||||
using Microsoft.Extensions.Logging; | |||||
using RabbitMQ.Client; | |||||
using System; | |||||
using System.IdentityModel.Tokens.Jwt; | |||||
using HealthChecks.UI.Client; | |||||
using Microsoft.AspNetCore.Diagnostics.HealthChecks; | |||||
using Microsoft.Extensions.Diagnostics.HealthChecks; | |||||
using Basket.SignalrHub.AutofacModules; | |||||
namespace Basket.SignalrHub | |||||
{ | |||||
public class Startup | |||||
{ | |||||
public Startup(IConfiguration configuration) | |||||
{ | |||||
Configuration = configuration; | |||||
} | |||||
public IConfiguration Configuration { get; } | |||||
// This method gets called by the runtime. Use this method to add services to the container. | |||||
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 | |||||
public IServiceProvider ConfigureServices(IServiceCollection services) | |||||
{ | |||||
services | |||||
.AddCustomHealthCheck(Configuration) | |||||
.AddCors(options => | |||||
{ | |||||
options.AddPolicy("CorsPolicy", | |||||
builder => builder | |||||
.AllowAnyMethod() | |||||
.AllowAnyHeader() | |||||
.SetIsOriginAllowed((host) => true) | |||||
.AllowCredentials()); | |||||
}); | |||||
if (Configuration.GetValue<string>("IsClusterEnv") == bool.TrueString) | |||||
{ | |||||
services | |||||
.AddSignalR() | |||||
.AddRedis(Configuration["SignalrStoreConnectionString"]); | |||||
} | |||||
else | |||||
{ | |||||
services.AddSignalR(); | |||||
} | |||||
if (Configuration.GetValue<bool>("AzureServiceBusEnabled")) | |||||
{ | |||||
services.AddSingleton<IServiceBusPersisterConnection>(sp => | |||||
{ | |||||
var logger = sp.GetRequiredService<ILogger<DefaultServiceBusPersisterConnection>>(); | |||||
var serviceBusConnectionString = Configuration["EventBusConnection"]; | |||||
var serviceBusConnection = new ServiceBusConnectionStringBuilder(serviceBusConnectionString); | |||||
return new DefaultServiceBusPersisterConnection(serviceBusConnection, logger); | |||||
}); | |||||
} | |||||
else | |||||
{ | |||||
services.AddSingleton<IRabbitMQPersistentConnection>(sp => | |||||
{ | |||||
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>(); | |||||
var factory = new ConnectionFactory() | |||||
{ | |||||
HostName = 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"]); | |||||
} | |||||
return new DefaultRabbitMQPersistentConnection(factory, logger, retryCount); | |||||
}); | |||||
} | |||||
ConfigureAuthService(services); | |||||
RegisterEventBus(services); | |||||
services.AddOptions(); | |||||
//configure autofac | |||||
var container = new ContainerBuilder(); | |||||
container.RegisterModule(new ApplicationModule()); | |||||
container.Populate(services); | |||||
return new AutofacServiceProvider(container.Build()); | |||||
} | |||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | |||||
public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) | |||||
{ | |||||
//loggerFactory.AddConsole(Configuration.GetSection("Logging")); | |||||
//loggerFactory.AddDebug(); | |||||
//loggerFactory.AddAzureWebAppDiagnostics(); | |||||
//loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace); | |||||
var pathBase = Configuration["PATH_BASE"]; | |||||
if (!string.IsNullOrEmpty(pathBase)) | |||||
{ | |||||
loggerFactory.CreateLogger<Startup>().LogDebug("Using PATH BASE '{pathBase}'", pathBase); | |||||
app.UsePathBase(pathBase); | |||||
} | |||||
app.UseHealthChecks("/hc", new HealthCheckOptions() | |||||
{ | |||||
Predicate = _ => true, | |||||
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse | |||||
}); | |||||
app.UseHealthChecks("/liveness", new HealthCheckOptions | |||||
{ | |||||
Predicate = r => r.Name.Contains("self") | |||||
}); | |||||
app.UseCors("CorsPolicy"); | |||||
app.UseAuthentication(); | |||||
app.UseSignalR(routes => | |||||
{ | |||||
routes.MapHub<NotificationsHub>("/notificationhub", options => | |||||
options.Transports = Microsoft.AspNetCore.Http.Connections.HttpTransports.All); | |||||
}); | |||||
ConfigureEventBus(app); | |||||
} | |||||
private void ConfigureEventBus(IApplicationBuilder app) | |||||
{ | |||||
var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>(); | |||||
// Event bus subscribe events goes here | |||||
// eventBus.Subscribe<NewIntegrationEvent, NewIntegrationEventHandler>(); | |||||
} | |||||
private void ConfigureAuthService(IServiceCollection services) | |||||
{ | |||||
// prevent from mapping "sub" claim to nameidentifier. | |||||
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Remove("sub"); | |||||
var identityUrl = Configuration.GetValue<string>("IdentityUrl"); | |||||
services.AddAuthentication(options => | |||||
{ | |||||
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; | |||||
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; | |||||
}).AddJwtBearer(options => | |||||
{ | |||||
options.Authority = identityUrl; | |||||
options.RequireHttpsMetadata = false; | |||||
options.Audience = "basket.signalrhub"; | |||||
}); | |||||
} | |||||
private void RegisterEventBus(IServiceCollection services) | |||||
{ | |||||
var subscriptionClientName = Configuration["SubscriptionClientName"]; | |||||
if (Configuration.GetValue<bool>("AzureServiceBusEnabled")) | |||||
{ | |||||
services.AddSingleton<IEventBus, EventBusServiceBus>(sp => | |||||
{ | |||||
var serviceBusPersisterConnection = sp.GetRequiredService<IServiceBusPersisterConnection>(); | |||||
var iLifetimeScope = sp.GetRequiredService<ILifetimeScope>(); | |||||
var logger = sp.GetRequiredService<ILogger<EventBusServiceBus>>(); | |||||
var eventBusSubcriptionsManager = sp.GetRequiredService<IEventBusSubscriptionsManager>(); | |||||
return new EventBusServiceBus(serviceBusPersisterConnection, logger, | |||||
eventBusSubcriptionsManager, subscriptionClientName, iLifetimeScope); | |||||
}); | |||||
} | |||||
else | |||||
{ | |||||
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"]); | |||||
} | |||||
return new EventBusRabbitMQ(rabbitMQPersistentConnection, logger, iLifetimeScope, eventBusSubcriptionsManager, subscriptionClientName, retryCount); | |||||
}); | |||||
} | |||||
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>(); | |||||
} | |||||
} | |||||
public static class CustomExtensionMethods | |||||
{ | |||||
public static IServiceCollection AddCustomHealthCheck(this IServiceCollection services, IConfiguration configuration) | |||||
{ | |||||
var hcBuilder = services.AddHealthChecks(); | |||||
hcBuilder.AddCheck("self", () => HealthCheckResult.Healthy()); | |||||
if (configuration.GetValue<bool>("AzureServiceBusEnabled")) | |||||
{ | |||||
hcBuilder | |||||
.AddAzureServiceBusTopic( | |||||
configuration["EventBusConnection"], | |||||
topicName: "eshop_event_bus", | |||||
name: "signalr-servicebus-check", | |||||
tags: new string[] { "servicebus" }); | |||||
} | |||||
else | |||||
{ | |||||
hcBuilder | |||||
.AddRabbitMQ( | |||||
$"amqp://{configuration["EventBusConnection"]}", | |||||
name: "signalr-rabbitmqbus-check", | |||||
tags: new string[] { "rabbitmqbus" }); | |||||
} | |||||
return services; | |||||
} | |||||
} | |||||
} |
@ -0,0 +1,19 @@ | |||||
{ | |||||
"IdentityUrl": "http://localhost:5105", | |||||
"Serilog": { | |||||
"SeqServerUrl": null, | |||||
"LogstashgUrl": null, | |||||
"MinimumLevel": { | |||||
"Default": "Information", | |||||
"Override": { | |||||
"Microsoft": "Warning", | |||||
"Microsoft.eShopOnContainers": "Information", | |||||
"System": "Warning" | |||||
} | |||||
} | |||||
}, | |||||
"AzureServiceBusEnabled": false, | |||||
"SubscriptionClientName": "Basket.signalrhub", | |||||
"EventBusRetryCount": 5, | |||||
"EventBusConnection": "localhost" | |||||
} |
@ -0,0 +1,56 @@ | |||||
kind: helm-release | |||||
apiVersion: 1.1 | |||||
build: | |||||
context: ..\..\..\.. | |||||
dockerfile: Dockerfile | |||||
install: | |||||
chart: ../../../../k8s/helm/basket-signalrhub | |||||
set: | |||||
replicaCount: 1 | |||||
image: | |||||
tag: $(tag) | |||||
pullPolicy: Never | |||||
ingress: | |||||
annotations: | |||||
kubernetes.io/ingress.class: traefik-azds | |||||
hosts: | |||||
- $(spacePrefix)eshop$(hostSuffix) | |||||
inf: | |||||
k8s: | |||||
dns: $(spacePrefix)eshop$(hostSuffix) | |||||
values: | |||||
- values.dev.yaml? | |||||
- secrets.dev.yaml? | |||||
- inf.yaml | |||||
- app.yaml | |||||
configurations: | |||||
develop: | |||||
build: | |||||
useGitIgnore: true | |||||
dockerfile: Dockerfile.develop | |||||
args: | |||||
BUILD_CONFIGURATION: ${BUILD_CONFIGURATION:-Debug} | |||||
container: | |||||
sync: | |||||
- '**/Pages/**' | |||||
- '**/Views/**' | |||||
- '**/wwwroot/**' | |||||
- '!**/*.{sln,csproj}' | |||||
command: | |||||
- dotnet | |||||
- run | |||||
- --no-restore | |||||
- --no-build | |||||
- --no-launch-profile | |||||
- -c | |||||
- ${BUILD_CONFIGURATION:-Debug} | |||||
iterate: | |||||
processesToKill: | |||||
- dotnet | |||||
- vsdbg | |||||
buildCommands: | |||||
- - dotnet | |||||
- build | |||||
- --no-restore | |||||
- -c | |||||
- ${BUILD_CONFIGURATION:-Debug} |