|
@ -9,11 +9,6 @@ using Microsoft.AspNetCore.Diagnostics.HealthChecks; |
|
|
using Microsoft.AspNetCore.Hosting; |
|
|
using Microsoft.AspNetCore.Hosting; |
|
|
using Microsoft.AspNetCore.Http; |
|
|
using Microsoft.AspNetCore.Http; |
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
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.eShopOnContainers.Services.Locations.API.Infrastructure; |
|
|
using Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure; |
|
|
using Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Filters; |
|
|
using Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Filters; |
|
|
using Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Middlewares; |
|
|
using Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Middlewares; |
|
@ -57,50 +52,45 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API |
|
|
|
|
|
|
|
|
services.Configure<LocationSettings>(Configuration); |
|
|
services.Configure<LocationSettings>(Configuration); |
|
|
|
|
|
|
|
|
if (Configuration.GetValue<bool>("AzureServiceBusEnabled")) |
|
|
|
|
|
|
|
|
services.AddCap(options => |
|
|
{ |
|
|
{ |
|
|
services.AddSingleton<IServiceBusPersisterConnection>(sp => |
|
|
|
|
|
|
|
|
// using MongoDB as the event storage
|
|
|
|
|
|
options.UseMongoDB(configure => |
|
|
{ |
|
|
{ |
|
|
var logger = sp.GetRequiredService<ILogger<DefaultServiceBusPersisterConnection>>(); |
|
|
|
|
|
|
|
|
|
|
|
var serviceBusConnectionString = Configuration["EventBusConnection"]; |
|
|
|
|
|
var serviceBusConnection = new ServiceBusConnectionStringBuilder(serviceBusConnectionString); |
|
|
|
|
|
|
|
|
|
|
|
return new DefaultServiceBusPersisterConnection(serviceBusConnection, logger); |
|
|
|
|
|
|
|
|
configure.DatabaseConnection = Configuration["ConnectionString"]; |
|
|
|
|
|
configure.DatabaseName= Configuration["Database"]; |
|
|
}); |
|
|
}); |
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
services.AddSingleton<IRabbitMQPersistentConnection>(sp => |
|
|
|
|
|
{ |
|
|
|
|
|
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>(); |
|
|
|
|
|
|
|
|
|
|
|
var factory = new ConnectionFactory() |
|
|
|
|
|
{ |
|
|
|
|
|
HostName = Configuration["EventBusConnection"] |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
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"])) |
|
|
|
|
|
|
|
|
if (Configuration.GetValue<bool>("AzureServiceBusEnabled")) |
|
|
|
|
|
{ |
|
|
|
|
|
options.UseAzureServiceBus(Configuration["EventBusConnection"]); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
options.UseRabbitMQ(conf => |
|
|
{ |
|
|
{ |
|
|
retryCount = int.Parse(Configuration["EventBusRetryCount"]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return new DefaultRabbitMQPersistentConnection(factory, logger, retryCount); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
conf.HostName = Configuration["EventBusConnection"]; |
|
|
|
|
|
if (!string.IsNullOrEmpty(Configuration["EventBusUserName"])) |
|
|
|
|
|
{ |
|
|
|
|
|
conf.UserName = Configuration["EventBusUserName"]; |
|
|
|
|
|
} |
|
|
|
|
|
if (!string.IsNullOrEmpty(Configuration["EventBusPassword"])) |
|
|
|
|
|
{ |
|
|
|
|
|
conf.Password = Configuration["EventBusPassword"]; |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(Configuration["EventBusRetryCount"])) |
|
|
|
|
|
{ |
|
|
|
|
|
options.FailedRetryCount = int.Parse(Configuration["EventBusRetryCount"]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
RegisterEventBus(services); |
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(Configuration["SubscriptionClientName"])) |
|
|
|
|
|
{ |
|
|
|
|
|
options.DefaultGroup = Configuration["SubscriptionClientName"]; |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
// Add framework services.
|
|
|
// Add framework services.
|
|
|
services.AddSwaggerGen(options => |
|
|
services.AddSwaggerGen(options => |
|
@ -238,45 +228,6 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API |
|
|
|
|
|
|
|
|
app.UseAuthentication(); |
|
|
app.UseAuthentication(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
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 class CustomExtensionMethods |
|
|