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

Remove item if connection creation fails
pull/9011/head
maliming 4 years ago committed by GitHub
commit da6dff41ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

Loading…
Cancel
Save