|
|
@ -12,10 +12,12 @@ |
|
|
|
using Infrastructure.Services; |
|
|
|
using Microsoft.AspNetCore.Builder; |
|
|
|
using Microsoft.AspNetCore.Hosting; |
|
|
|
using Microsoft.Azure.ServiceBus; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus; |
|
|
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBus.Abstractions; |
|
|
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ; |
|
|
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus; |
|
|
|
using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF; |
|
|
|
using Microsoft.eShopOnContainers.BuildingBlocks.IntegrationEventLogEF.Services; |
|
|
|
using Microsoft.Extensions.Configuration; |
|
|
@ -113,20 +115,33 @@ |
|
|
|
var serviceProvider = services.BuildServiceProvider(); |
|
|
|
services.AddTransient<IOrderingIntegrationEventService, OrderingIntegrationEventService>(); |
|
|
|
|
|
|
|
services.AddSingleton<IRabbitMQPersistentConnection>(sp => |
|
|
|
if (Configuration.GetValue<bool>("AzureServiceBus")) |
|
|
|
{ |
|
|
|
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>(); |
|
|
|
services.AddSingleton<IServiceBusPersisterConnection>(sp => |
|
|
|
{ |
|
|
|
var logger = sp.GetRequiredService<ILogger<DefaultServiceBusPersisterConnection>>(); |
|
|
|
|
|
|
|
var serviceBusConnection = new ServiceBusConnectionStringBuilder(Configuration["ServiceBusConnection"]); |
|
|
|
|
|
|
|
var factory = new ConnectionFactory() |
|
|
|
return new DefaultServiceBusPersisterConnection(serviceBusConnection, TimeSpan.FromSeconds(5), RetryPolicy.Default, logger); |
|
|
|
}); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
services.AddSingleton<IRabbitMQPersistentConnection>(sp => |
|
|
|
{ |
|
|
|
HostName = Configuration["EventBusConnection"] |
|
|
|
}; |
|
|
|
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>(); |
|
|
|
|
|
|
|
return new DefaultRabbitMQPersistentConnection(factory, logger); |
|
|
|
}); |
|
|
|
var factory = new ConnectionFactory() |
|
|
|
{ |
|
|
|
HostName = Configuration["EventBusConnection"] |
|
|
|
}; |
|
|
|
|
|
|
|
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>(); |
|
|
|
services.AddSingleton<IEventBus, EventBusRabbitMQ>(); |
|
|
|
return new DefaultRabbitMQPersistentConnection(factory, logger); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
RegisterServiceBus(services); |
|
|
|
|
|
|
|
services.AddOptions(); |
|
|
|
|
|
|
@ -174,5 +189,28 @@ |
|
|
|
RequireHttpsMetadata = false |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private void RegisterServiceBus(IServiceCollection services) |
|
|
|
{ |
|
|
|
if (Configuration.GetValue<bool>("AzureServiceBus")) |
|
|
|
{ |
|
|
|
services.AddSingleton<IEventBus, EventBusServiceBus>(sp => |
|
|
|
{ |
|
|
|
var serviceBusPersisterConnection = sp.GetRequiredService<IServiceBusPersisterConnection>(); |
|
|
|
var logger = sp.GetRequiredService<ILogger<EventBusServiceBus>>(); |
|
|
|
var eventBusSubcriptionsManager = sp.GetRequiredService<IEventBusSubscriptionsManager>(); |
|
|
|
var subscriptionClientName = "Ordering"; |
|
|
|
|
|
|
|
return new EventBusServiceBus(serviceBusPersisterConnection, logger, |
|
|
|
eventBusSubcriptionsManager, subscriptionClientName); |
|
|
|
}); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
services.AddSingleton<IEventBus, EventBusRabbitMQ>(); |
|
|
|
} |
|
|
|
|
|
|
|
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |