- Declare new ServiceBus instance with "AzureServiceBus" boolean condition DI
- Add ServiceBusConnection and AzureServiceBus variables in settings - Add EventBusServiceBus dependencies
This commit is contained in:
parent
3acd556c5c
commit
721a4fd02b
@ -41,6 +41,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBusRabbitMQ\EventBusRabbitMQ.csproj" />
|
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBusRabbitMQ\EventBusRabbitMQ.csproj" />
|
||||||
|
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBusServiceBus\EventBusServiceBus.csproj" />
|
||||||
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBus\EventBus.csproj" />
|
<ProjectReference Include="..\..\..\BuildingBlocks\EventBus\EventBus\EventBus.csproj" />
|
||||||
<ProjectReference Include="..\..\..\BuildingBlocks\HealthChecks\src\Microsoft.AspNetCore.HealthChecks\Microsoft.AspNetCore.HealthChecks.csproj" />
|
<ProjectReference Include="..\..\..\BuildingBlocks\HealthChecks\src\Microsoft.AspNetCore.HealthChecks\Microsoft.AspNetCore.HealthChecks.csproj" />
|
||||||
<ProjectReference Include="..\..\..\BuildingBlocks\HealthChecks\src\Microsoft.Extensions.HealthChecks\Microsoft.Extensions.HealthChecks.csproj" />
|
<ProjectReference Include="..\..\..\BuildingBlocks\HealthChecks\src\Microsoft.Extensions.HealthChecks\Microsoft.Extensions.HealthChecks.csproj" />
|
||||||
|
@ -5,5 +5,7 @@
|
|||||||
public string ConnectionString { get; set; }
|
public string ConnectionString { get; set; }
|
||||||
|
|
||||||
public string EventBusConnection { get; set; }
|
public string EventBusConnection { get; set; }
|
||||||
|
|
||||||
|
public string ServiceBusConnection { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,8 @@ using System.Linq;
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System;
|
using System;
|
||||||
|
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus;
|
||||||
|
using Microsoft.Azure.ServiceBus;
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Basket.API
|
namespace Microsoft.eShopOnContainers.Services.Basket.API
|
||||||
{
|
{
|
||||||
@ -70,17 +72,33 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
services.AddSingleton<IRabbitMQPersistentConnection>(sp =>
|
if (Configuration.GetValue<bool>("AzureServiceBus"))
|
||||||
{
|
{
|
||||||
var settings = sp.GetRequiredService<IOptions<BasketSettings>>().Value;
|
services.AddSingleton<IServiceBusPersisterConnection>(sp =>
|
||||||
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>();
|
|
||||||
var factory = new ConnectionFactory()
|
|
||||||
{
|
{
|
||||||
HostName = settings.EventBusConnection
|
var settings = sp.GetRequiredService<IOptions<BasketSettings>>().Value;
|
||||||
};
|
var logger = sp.GetRequiredService<ILogger<DefaultServiceBusPersisterConnection>>();
|
||||||
|
|
||||||
|
var serviceBusConnection = new ServiceBusConnectionStringBuilder(settings.ServiceBusConnection);
|
||||||
|
|
||||||
|
return new DefaultServiceBusPersisterConnection(serviceBusConnection, TimeSpan.FromSeconds(5) , RetryPolicy.Default,logger);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
services.AddSingleton<IRabbitMQPersistentConnection>(sp =>
|
||||||
|
{
|
||||||
|
var settings = sp.GetRequiredService<IOptions<BasketSettings>>().Value;
|
||||||
|
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>();
|
||||||
|
var factory = new ConnectionFactory()
|
||||||
|
{
|
||||||
|
HostName = settings.EventBusConnection
|
||||||
|
};
|
||||||
|
|
||||||
|
return new DefaultRabbitMQPersistentConnection(factory, logger);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return new DefaultRabbitMQPersistentConnection(factory, logger);
|
|
||||||
});
|
|
||||||
|
|
||||||
services.AddSwaggerGen();
|
services.AddSwaggerGen();
|
||||||
|
|
||||||
@ -113,7 +131,24 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
|
|||||||
|
|
||||||
private void RegisterServiceBus(IServiceCollection services)
|
private void RegisterServiceBus(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddSingleton<IEventBus, EventBusRabbitMQ>();
|
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 = "Basket";
|
||||||
|
|
||||||
|
return new EventBusServiceBus(serviceBusPersisterConnection, logger,
|
||||||
|
eventBusSubcriptionsManager, subscriptionClientName);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
services.AddSingleton<IEventBus, EventBusRabbitMQ>();
|
||||||
|
}
|
||||||
|
|
||||||
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
|
services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
|
||||||
|
|
||||||
services.AddTransient<ProductPriceChangedIntegrationEventHandler>();
|
services.AddTransient<ProductPriceChangedIntegrationEventHandler>();
|
||||||
|
@ -8,5 +8,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"IdentityUrl": "http://localhost:5105",
|
"IdentityUrl": "http://localhost:5105",
|
||||||
"ConnectionString": "127.0.0.1"
|
"ConnectionString": "127.0.0.1",
|
||||||
|
"ServiceBusConnection": "Endpoint=sb://eshoponazuretest.servicebus.windows.net/;SharedAccessKeyName=Root;SharedAccessKey=Xo9wlr4bRv5iqTTditgFhTeZqxIpczaAUqfspo+QE/s=;EntityPath=eshop_event_bus",
|
||||||
|
"AzureServiceBus": "true"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user