Update ConnectionPool.cs

pull/9008/head
liangshiwei 4 years ago
parent d96a6a6f1d
commit e354496e35

@ -25,23 +25,26 @@ namespace Volo.Abp.RabbitMQ
{
connectionName ??= RabbitMqConnections.DefaultConnectionName;
var lazyConnection = Connections.GetOrAdd(
connectionName, () => new Lazy<IConnection>(() =>
{
var connection = Options.Connections.GetOrDefault(connectionName);
var hostnames = connection.HostName.TrimEnd(';').Split(';');
// Handle Rabbit MQ Cluster.
return hostnames.Length == 1 ? connection.CreateConnection() : connection.CreateConnection(hostnames);
try
{
var lazyConnection = Connections.GetOrAdd(
connectionName, () => new Lazy<IConnection>(() =>
{
var connection = Options.Connections.GetOrDefault(connectionName);
var hostnames = connection.HostName.TrimEnd(';').Split(';');
// Handle Rabbit MQ Cluster.
return hostnames.Length == 1 ? connection.CreateConnection() : connection.CreateConnection(hostnames);
})
);
})
);
if (!lazyConnection.IsValueCreated)
return lazyConnection.Value;
}
catch (Exception)
{
Connections.TryRemove(connectionName, out _);
throw;
}
return lazyConnection.Value;
}
public void Dispose()

Loading…
Cancel
Save