Skip to content

Commit bc89bc1

Browse files
committed
2 parents 9979f1a + 39e69ee commit bc89bc1

23 files changed

Lines changed: 212 additions & 79 deletions

docker-compose.override.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '2'
1+
version: '2.1'
22

33
# The default docker-compose.override file can use the "localhost" as the external name for testing web apps within the same dev machine.
44
# The ESHOP_EXTERNAL_DNS_NAME_OR_IP environment variable is taken, by default, from the ".env" file defined like:
@@ -12,9 +12,9 @@ services:
1212
environment:
1313
- ASPNETCORE_ENVIRONMENT=Development
1414
- ASPNETCORE_URLS=http://0.0.0.0:80
15-
- ConnectionString=basket.data
15+
- ConnectionString=${ESHOP_AZURE_REDIS:-basket.data}
1616
- identityUrl=http://identity.api #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105.
17-
- EventBusConnection=rabbitmq
17+
- EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq}
1818
ports:
1919
- "5103:80"
2020

@@ -23,8 +23,8 @@ services:
2323
- ASPNETCORE_ENVIRONMENT=Development
2424
- ASPNETCORE_URLS=http://0.0.0.0:80
2525
- ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word
26-
- ExternalCatalogBaseUrl=http://${ESHOP_EXTERNAL_DNS_NAME_OR_IP}:5101 #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105.
27-
- EventBusConnection=rabbitmq
26+
- PicBaseUrl=${ESHOP_AZURE_STORAGE_ACCOUNT:-http://localhost:5101/api/v1/pic/} #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105.
27+
- EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq}
2828
ports:
2929
- "5101:80"
3030

@@ -45,7 +45,7 @@ services:
4545
- ASPNETCORE_URLS=http://0.0.0.0:80
4646
- ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word
4747
- identityUrl=http://identity.api #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105.
48-
- EventBusConnection=rabbitmq
48+
- EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq}
4949
ports:
5050
- "5102:80"
5151

docker-compose.prod.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '2'
1+
version: '2.1'
22

33
# The Production docker-compose file has to have the external/real IPs or DNS names for the services
44
# The ESHOP_PROD_EXTERNAL_DNS_NAME_OR_IP environment variable is taken, by default, from the ".env" file defined like:
@@ -17,9 +17,9 @@ services:
1717
environment:
1818
- ASPNETCORE_ENVIRONMENT=Production
1919
- ASPNETCORE_URLS=http://0.0.0.0:80
20-
- ConnectionString=basket.data
20+
- ConnectionString=${ESHOP_AZURE_REDIS:-basket.data}
2121
- identityUrl=http://identity.api #Local: You need to open your host's firewall at range 5100-5105. at range 5100-5105.
22-
- EventBusConnection=rabbitmq
22+
- EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq}
2323
ports:
2424
- "5103:80"
2525

@@ -29,7 +29,7 @@ services:
2929
- ASPNETCORE_URLS=http://0.0.0.0:80
3030
- ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word
3131
- ExternalCatalogBaseUrl=http://${ESHOP_PROD_EXTERNAL_DNS_NAME_OR_IP}:5101 #Local: You need to open your host's firewall at range 5100-5105. at range 5100-5105.
32-
- EventBusConnection=rabbitmq
32+
- EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq}
3333
ports:
3434
- "5101:80"
3535

@@ -50,7 +50,7 @@ services:
5050
- ASPNETCORE_URLS=http://0.0.0.0:80
5151
- ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word
5252
- identityUrl=http://identity.api #Local: You need to open your host's firewall at range 5100-5105. at range 5100-5105.
53-
- EventBusConnection=rabbitmq
53+
- EventBusConnection=${ESHOP_AZURE_SERVICE_BUS:-rabbitmq}
5454
ports:
5555
- "5102:80"
5656

docker-compose.vs.debug.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '2'
1+
version: '2.1'
22

33
services:
44
basket.api:

docker-compose.vs.release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '2'
1+
version: '2.1'
22

33
services:
44
basket.api:

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '2'
1+
version: '2.1'
22

33
services:
44
basket.api:

src/Services/Basket/Basket.API/Basket.API.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
</ItemGroup>
2323

2424
<ItemGroup>
25+
<PackageReference Include="StackExchange.Redis" Version="1.2.3" />
2526
<PackageReference Include="System.Threading" Version="4.3.0" />
2627
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
2728
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.1" />
@@ -33,7 +34,6 @@
3334
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
3435
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
3536
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.1" />
36-
<PackageReference Include="StackExchange.Redis" Version="1.1.608" />
3737
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
3838
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="1.0.1-rc3" />
3939
<PackageReference Include="Swashbuckle" Version="6.0.0-beta902" />

src/Services/Basket/Basket.API/BasketSettings.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,5 @@ public class BasketSettings
55
public string ConnectionString { get; set; }
66

77
public string EventBusConnection { get; set; }
8-
9-
public string ServiceBusConnectionString { get; set; }
108
}
119
}

src/Services/Basket/Basket.API/Model/RedisBasketRepository.cs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using StackExchange.Redis;
55
using System.Collections.Generic;
66
using System.Linq;
7-
using System.Net;
87
using System.Threading.Tasks;
98

109
namespace Microsoft.eShopOnContainers.Services.Basket.API.Model
@@ -16,12 +15,10 @@ public class RedisBasketRepository : IBasketRepository
1615

1716
private ConnectionMultiplexer _redis;
1817

19-
2018
public RedisBasketRepository(IOptionsSnapshot<BasketSettings> options, ILoggerFactory loggerFactory)
2119
{
2220
_settings = options.Value;
2321
_logger = loggerFactory.CreateLogger<RedisBasketRepository>();
24-
2522
}
2623

2724
public async Task<bool> DeleteBasketAsync(string id)
@@ -93,21 +90,12 @@ private async Task<IServer> GetServer()
9390
}
9491

9592
private async Task ConnectToRedisAsync()
96-
{
97-
// TODO: Need to make this more robust. ConnectionMultiplexer.ConnectAsync doesn't like domain names or IPv6 addresses.
98-
if (IPAddress.TryParse(_settings.ConnectionString, out var ip))
99-
{
100-
_redis = await ConnectionMultiplexer.ConnectAsync(ip.ToString());
101-
_logger.LogInformation($"Connecting to database at {_settings.ConnectionString}");
102-
}
103-
else
104-
{
105-
// workaround for https://github.com/StackExchange/StackExchange.Redis/issues/410
106-
var ips = await Dns.GetHostAddressesAsync(_settings.ConnectionString);
107-
_logger.LogInformation($"Connecting to database {_settings.ConnectionString} at IP {ips.First().ToString()}");
108-
_redis = await ConnectionMultiplexer.ConnectAsync(ips.First().ToString());
109-
}
93+
{
94+
var configuration = ConfigurationOptions.Parse(_settings.ConnectionString, true);
95+
configuration.ResolveDns = true;
96+
97+
_logger.LogInformation($"Connecting to database {configuration.SslHost}.");
98+
_redis = await ConnectionMultiplexer.ConnectAsync(configuration);
11099
}
111-
112100
}
113101
}

src/Services/Basket/Basket.API/Startup.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,8 @@
1616
using Microsoft.Extensions.Logging;
1717
using Microsoft.Extensions.Options;
1818
using RabbitMQ.Client;
19-
using StackExchange.Redis;
20-
using System.Linq;
21-
using System.Net;
2219
using System.Threading.Tasks;
23-
using System;
20+
using StackExchange.Redis;
2421
using Microsoft.eShopOnContainers.BuildingBlocks.EventBusServiceBus;
2522
using Microsoft.Azure.ServiceBus;
2623

@@ -66,9 +63,10 @@ public void ConfigureServices(IServiceCollection services)
6663
services.AddSingleton<ConnectionMultiplexer>(sp =>
6764
{
6865
var settings = sp.GetRequiredService<IOptions<BasketSettings>>().Value;
69-
var ips = Dns.GetHostAddressesAsync(settings.ConnectionString).Result;
66+
ConfigurationOptions configuration = ConfigurationOptions.Parse(settings.ConnectionString, true);
67+
configuration.ResolveDns = true;
7068

71-
return ConnectionMultiplexer.Connect(ips.First().ToString());
69+
return ConnectionMultiplexer.Connect(configuration);
7270
});
7371

7472

@@ -79,7 +77,7 @@ public void ConfigureServices(IServiceCollection services)
7977
var settings = sp.GetRequiredService<IOptions<BasketSettings>>().Value;
8078
var logger = sp.GetRequiredService<ILogger<DefaultServiceBusPersisterConnection>>();
8179

82-
var serviceBusConnection = new ServiceBusConnectionStringBuilder(settings.ServiceBusConnectionString);
80+
var serviceBusConnection = new ServiceBusConnectionStringBuilder(settings.EventBusConnection);
8381

8482
return new DefaultServiceBusPersisterConnection(serviceBusConnection, logger);
8583
});

src/Services/Basket/Basket.API/appsettings.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
},
1010
"IdentityUrl": "http://localhost:5105",
1111
"ConnectionString": "127.0.0.1",
12-
"ServiceBusConnectionString": "Endpoint=sb://eshopsbez55a72p6wm62.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=oA6WpfCfCbScZbQa/DBOLfwl6oi5ezPsCYL7QsTb4PY=;EntityPath=eshop_event_bus",
13-
"AzureServiceBusEnabled": "true",
12+
"AzureServiceBusEnabled": false,
1413
"SubscriptionClientName": "Basket"
1514
}

0 commit comments

Comments
 (0)