Browse Source

Update ConnectionPool.cs

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

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

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

Loading…
Cancel
Save