Merge branch 'azureredis' into dev
# Conflicts: # src/Services/Basket/Basket.API/Startup.cs # src/Services/Basket/Basket.API/appsettings.json
This commit is contained in:
commit
ea02ecc160
@ -1,4 +1,4 @@
|
|||||||
version: '2'
|
version: '2.1'
|
||||||
|
|
||||||
# The default docker-compose.override file can use the "localhost" as the external name for testing web apps within the same dev machine.
|
# The default docker-compose.override file can use the "localhost" as the external name for testing web apps within the same dev machine.
|
||||||
# The ESHOP_EXTERNAL_DNS_NAME_OR_IP environment variable is taken, by default, from the ".env" file defined like:
|
# The ESHOP_EXTERNAL_DNS_NAME_OR_IP environment variable is taken, by default, from the ".env" file defined like:
|
||||||
@ -12,7 +12,7 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
- ASPNETCORE_ENVIRONMENT=Development
|
- ASPNETCORE_ENVIRONMENT=Development
|
||||||
- ASPNETCORE_URLS=http://0.0.0.0:80
|
- ASPNETCORE_URLS=http://0.0.0.0:80
|
||||||
- ConnectionString=basket.data
|
- ConnectionString=${ESHOP_AZURE_REDIS:-basket.data}
|
||||||
- identityUrl=http://identity.api #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105.
|
- identityUrl=http://identity.api #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105.
|
||||||
- EventBusConnection=rabbitmq
|
- EventBusConnection=rabbitmq
|
||||||
ports:
|
ports:
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
version: '2'
|
version: '2.1'
|
||||||
|
|
||||||
# The Production docker-compose file has to have the external/real IPs or DNS names for the services
|
# The Production docker-compose file has to have the external/real IPs or DNS names for the services
|
||||||
# The ESHOP_PROD_EXTERNAL_DNS_NAME_OR_IP environment variable is taken, by default, from the ".env" file defined like:
|
# The ESHOP_PROD_EXTERNAL_DNS_NAME_OR_IP environment variable is taken, by default, from the ".env" file defined like:
|
||||||
@ -17,7 +17,7 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
- ASPNETCORE_ENVIRONMENT=Production
|
- ASPNETCORE_ENVIRONMENT=Production
|
||||||
- ASPNETCORE_URLS=http://0.0.0.0:80
|
- ASPNETCORE_URLS=http://0.0.0.0:80
|
||||||
- ConnectionString=basket.data
|
- ConnectionString=${ESHOP_AZURE_REDIS:-basket.data}
|
||||||
- identityUrl=http://identity.api #Local: You need to open your host's firewall at range 5100-5105. at range 5100-5105.
|
- identityUrl=http://identity.api #Local: You need to open your host's firewall at range 5100-5105. at range 5100-5105.
|
||||||
- EventBusConnection=rabbitmq
|
- EventBusConnection=rabbitmq
|
||||||
ports:
|
ports:
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
version: '2'
|
version: '2.1'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
basket.api:
|
basket.api:
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
version: '2'
|
version: '2.1'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
basket.api:
|
basket.api:
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
version: '2'
|
version: '2.1'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
basket.api:
|
basket.api:
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="StackExchange.Redis" Version="1.2.3" />
|
||||||
<PackageReference Include="System.Threading" Version="4.3.0" />
|
<PackageReference Include="System.Threading" Version="4.3.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.1" />
|
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.1" />
|
||||||
@ -33,7 +34,6 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.1" />
|
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.1" />
|
||||||
<PackageReference Include="StackExchange.Redis" Version="1.1.608" />
|
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
|
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
|
||||||
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="1.0.1-rc3" />
|
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="1.0.1-rc3" />
|
||||||
<PackageReference Include="Swashbuckle" Version="6.0.0-beta902" />
|
<PackageReference Include="Swashbuckle" Version="6.0.0-beta902" />
|
||||||
|
@ -4,7 +4,6 @@ using Newtonsoft.Json;
|
|||||||
using StackExchange.Redis;
|
using StackExchange.Redis;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
|
namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
|
||||||
@ -16,12 +15,10 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
|
|||||||
|
|
||||||
private ConnectionMultiplexer _redis;
|
private ConnectionMultiplexer _redis;
|
||||||
|
|
||||||
|
|
||||||
public RedisBasketRepository(IOptionsSnapshot<BasketSettings> options, ILoggerFactory loggerFactory)
|
public RedisBasketRepository(IOptionsSnapshot<BasketSettings> options, ILoggerFactory loggerFactory)
|
||||||
{
|
{
|
||||||
_settings = options.Value;
|
_settings = options.Value;
|
||||||
_logger = loggerFactory.CreateLogger<RedisBasketRepository>();
|
_logger = loggerFactory.CreateLogger<RedisBasketRepository>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> DeleteBasketAsync(string id)
|
public async Task<bool> DeleteBasketAsync(string id)
|
||||||
@ -93,21 +90,12 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async Task ConnectToRedisAsync()
|
private async Task ConnectToRedisAsync()
|
||||||
{
|
{
|
||||||
// TODO: Need to make this more robust. ConnectionMultiplexer.ConnectAsync doesn't like domain names or IPv6 addresses.
|
var configuration = ConfigurationOptions.Parse(_settings.ConnectionString, true);
|
||||||
if (IPAddress.TryParse(_settings.ConnectionString, out var ip))
|
configuration.ResolveDns = true;
|
||||||
{
|
|
||||||
_redis = await ConnectionMultiplexer.ConnectAsync(ip.ToString());
|
_logger.LogInformation($"Connecting to database {configuration.SslHost}.");
|
||||||
_logger.LogInformation($"Connecting to database at {_settings.ConnectionString}");
|
_redis = await ConnectionMultiplexer.ConnectAsync(configuration);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// workaround for https://github.com/StackExchange/StackExchange.Redis/issues/410
|
|
||||||
var ips = await Dns.GetHostAddressesAsync(_settings.ConnectionString);
|
|
||||||
_logger.LogInformation($"Connecting to database {_settings.ConnectionString} at IP {ips.First().ToString()}");
|
|
||||||
_redis = await ConnectionMultiplexer.ConnectAsync(ips.First().ToString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,13 +16,8 @@ using Microsoft.Extensions.HealthChecks;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using RabbitMQ.Client;
|
using RabbitMQ.Client;
|
||||||
using StackExchange.Redis;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System;
|
using StackExchange.Redis;
|
||||||
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus;
|
|
||||||
using Microsoft.Azure.ServiceBus;
|
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Basket.API
|
namespace Microsoft.eShopOnContainers.Services.Basket.API
|
||||||
{
|
{
|
||||||
@ -66,9 +61,10 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
|
|||||||
services.AddSingleton<ConnectionMultiplexer>(sp =>
|
services.AddSingleton<ConnectionMultiplexer>(sp =>
|
||||||
{
|
{
|
||||||
var settings = sp.GetRequiredService<IOptions<BasketSettings>>().Value;
|
var settings = sp.GetRequiredService<IOptions<BasketSettings>>().Value;
|
||||||
var ips = Dns.GetHostAddressesAsync(settings.ConnectionString).Result;
|
ConfigurationOptions configuration = ConfigurationOptions.Parse(settings.ConnectionString, true);
|
||||||
|
configuration.ResolveDns = true;
|
||||||
|
|
||||||
return ConnectionMultiplexer.Connect(ips.First().ToString());
|
return ConnectionMultiplexer.Connect(configuration);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user