Browse Source

Remove item connection creation fails

pull/9008/head
liangshiwei 5 years ago
parent
commit
d96a6a6f1d
  1. 11
      framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/ConnectionPool.cs

11
framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/ConnectionPool.cs

@ -25,7 +25,7 @@ namespace Volo.Abp.RabbitMQ
{ {
connectionName ??= RabbitMqConnections.DefaultConnectionName; connectionName ??= RabbitMqConnections.DefaultConnectionName;
return Connections.GetOrAdd( var lazyConnection = Connections.GetOrAdd(
connectionName, () => new Lazy<IConnection>(() => connectionName, () => new Lazy<IConnection>(() =>
{ {
var connection = Options.Connections.GetOrDefault(connectionName); var connection = Options.Connections.GetOrDefault(connectionName);
@ -34,7 +34,14 @@ namespace Volo.Abp.RabbitMQ
return hostnames.Length == 1 ? connection.CreateConnection() : connection.CreateConnection(hostnames); return hostnames.Length == 1 ? connection.CreateConnection() : connection.CreateConnection(hostnames);
}) })
).Value; );
if (!lazyConnection.IsValueCreated)
{
Connections.TryRemove(connectionName, out _);
}
return lazyConnection.Value;
} }
public void Dispose() public void Dispose()

Loading…
Cancel
Save