Browse Source

Merge branch 'azureredis' into dev

# Conflicts:
#	src/Services/Basket/Basket.API/Startup.cs
#	src/Services/Basket/Basket.API/appsettings.json
pull/235/head
Christian Arenas 7 years ago
parent
commit
ea02ecc160
8 changed files with 18 additions and 34 deletions
  1. +2
    -2
      docker-compose.override.yml
  2. +2
    -2
      docker-compose.prod.yml
  3. +1
    -1
      docker-compose.vs.debug.yml
  4. +1
    -1
      docker-compose.vs.release.yml
  5. +1
    -1
      docker-compose.yml
  6. +1
    -1
      src/Services/Basket/Basket.API/Basket.API.csproj
  7. +6
    -18
      src/Services/Basket/Basket.API/Model/RedisBasketRepository.cs
  8. +4
    -8
      src/Services/Basket/Basket.API/Startup.cs

+ 2
- 2
docker-compose.override.yml View File

@ -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 ESHOP_EXTERNAL_DNS_NAME_OR_IP environment variable is taken, by default, from the ".env" file defined like:
@ -12,7 +12,7 @@ services:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- 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.
- EventBusConnection=rabbitmq
ports:


+ 2
- 2
docker-compose.prod.yml View File

@ -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 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:
- ASPNETCORE_ENVIRONMENT=Production
- 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.
- EventBusConnection=rabbitmq
ports:


+ 1
- 1
docker-compose.vs.debug.yml View File

@ -1,4 +1,4 @@
version: '2'
version: '2.1'
services:
basket.api:


+ 1
- 1
docker-compose.vs.release.yml View File

@ -1,4 +1,4 @@
version: '2'
version: '2.1'
services:
basket.api:


+ 1
- 1
docker-compose.yml View File

@ -1,4 +1,4 @@
version: '2'
version: '2.1'
services:
basket.api:


+ 1
- 1
src/Services/Basket/Basket.API/Basket.API.csproj View File

@ -22,6 +22,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="StackExchange.Redis" Version="1.2.3" />
<PackageReference Include="System.Threading" Version="4.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
<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.Debug" 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="IdentityServer4.AccessTokenValidation" Version="1.0.1-rc3" />
<PackageReference Include="Swashbuckle" Version="6.0.0-beta902" />


+ 6
- 18
src/Services/Basket/Basket.API/Model/RedisBasketRepository.cs View File

@ -4,7 +4,6 @@ using Newtonsoft.Json;
using StackExchange.Redis;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
@ -16,12 +15,10 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
private ConnectionMultiplexer _redis;
public RedisBasketRepository(IOptionsSnapshot<BasketSettings> options, ILoggerFactory loggerFactory)
{
_settings = options.Value;
_logger = loggerFactory.CreateLogger<RedisBasketRepository>();
}
public async Task<bool> DeleteBasketAsync(string id)
@ -93,21 +90,12 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
}
private async Task ConnectToRedisAsync()
{
// TODO: Need to make this more robust. ConnectionMultiplexer.ConnectAsync doesn't like domain names or IPv6 addresses.
if (IPAddress.TryParse(_settings.ConnectionString, out var ip))
{
_redis = await ConnectionMultiplexer.ConnectAsync(ip.ToString());
_logger.LogInformation($"Connecting to database at {_settings.ConnectionString}");
}
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());
}
{
var configuration = ConfigurationOptions.Parse(_settings.ConnectionString, true);
configuration.ResolveDns = true;
_logger.LogInformation($"Connecting to database {configuration.SslHost}.");
_redis = await ConnectionMultiplexer.ConnectAsync(configuration);
}
}
}

+ 4
- 8
src/Services/Basket/Basket.API/Startup.cs View File

@ -16,13 +16,8 @@ using Microsoft.Extensions.HealthChecks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using RabbitMQ.Client;
using StackExchange.Redis;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using System;
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus;
using Microsoft.Azure.ServiceBus;
using StackExchange.Redis;
namespace Microsoft.eShopOnContainers.Services.Basket.API
{
@ -66,9 +61,10 @@ namespace Microsoft.eShopOnContainers.Services.Basket.API
services.AddSingleton<ConnectionMultiplexer>(sp =>
{
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…
Cancel
Save