Browse Source

Merge pull request #9008 from abpframework/liangshiwei/patch-1

Remove item if connection creation fails
pull/9011/head
maliming 5 years ago
committed by GitHub
parent
commit
da6dff41ce
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      framework/src/Volo.Abp.RabbitMQ/Volo/Abp/RabbitMQ/ConnectionPool.cs

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

@ -25,16 +25,26 @@ namespace Volo.Abp.RabbitMQ
{ {
connectionName ??= RabbitMqConnections.DefaultConnectionName; connectionName ??= RabbitMqConnections.DefaultConnectionName;
return 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);
})
);
}) return lazyConnection.Value;
).Value; }
catch (Exception)
{
Connections.TryRemove(connectionName, out _);
throw;
}
} }
public void Dispose() public void Dispose()

Loading…
Cancel
Save