diff --git a/src/01/KSocietyBaseEventBus/KSociety.Base.EventBusRabbitMQ/DefaultRabbitMqPersistentConnection.cs b/src/01/KSocietyBaseEventBus/KSociety.Base.EventBusRabbitMQ/DefaultRabbitMqPersistentConnection.cs index e4e1e7fb..5cafcf57 100644 --- a/src/01/KSocietyBaseEventBus/KSociety.Base.EventBusRabbitMQ/DefaultRabbitMqPersistentConnection.cs +++ b/src/01/KSocietyBaseEventBus/KSociety.Base.EventBusRabbitMQ/DefaultRabbitMqPersistentConnection.cs @@ -94,40 +94,40 @@ public bool TryConnect() //try //{ - var policy = Policy.Handle() - .Or() - .Or() - .WaitAndRetryForever(retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), - (ex, time) => - { - this._logger?.LogWarning(ex, "TryConnect: "); - }); + var policy = Policy.Handle() + .Or() + .Or() + .WaitAndRetryForever(retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), + (ex, time) => + { + this._logger?.LogWarning(ex, "TryConnect: "); + }); - policy.Execute(this.CreateConnection); + policy.Execute(this.CreateConnection); - if (this.IsConnected) + if (this.IsConnected) + { + if (this._connection != null) { - if (this._connection != null) - { - this._connection.ConnectionShutdown += this.OnConnectionShutdown; - this._connection.CallbackException += this.OnCallbackException; - this._connection.ConnectionBlocked += this.OnConnectionBlocked; - - //this._logger?.LogInformation($"RabbitMQ persistent connection acquired a connection {this._connection.Endpoint.HostName} and is subscribed to failure events"); - output = true; - } - else - { - output = false; - } + this._connection.ConnectionShutdown += this.OnConnectionShutdown; + this._connection.CallbackException += this.OnCallbackException; + this._connection.ConnectionBlocked += this.OnConnectionBlocked; + + //this._logger?.LogInformation($"RabbitMQ persistent connection acquired a connection {this._connection.Endpoint.HostName} and is subscribed to failure events"); + output = true; } else { - this._logger?.LogCritical("FATAL ERROR: RabbitMQ connections could not be created and opened"); - output = false; } + } + else + { + this._logger?.LogCritical("FATAL ERROR: RabbitMQ connections could not be created and opened"); + + output = false; + } //} //finally //{ @@ -144,45 +144,45 @@ public async ValueTask TryConnectAsync() //try //{ - var policy = Policy.Handle() - .Or() - .Or() - .WaitAndRetryForeverAsync(retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), - (ex, time) => - { - this._logger?.LogWarning(ex, "TryConnectAsync: "); - }); + var policy = Policy.Handle() + .Or() + .Or() + .WaitAndRetryForeverAsync(retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), + (ex, time) => + { + this._logger?.LogWarning(ex, "TryConnectAsync: "); + }); - await policy.ExecuteAsync(async () => - { - await this.CreateConnection().ConfigureAwait(false); - //await Task.Run(this.CreateConnection, this._closeToken).ConfigureAwait(false); - //this._closeToken; - }).ConfigureAwait(false); + await policy.ExecuteAsync(async () => + { + await this.CreateConnection().ConfigureAwait(false); + //await Task.Run(this.CreateConnection, this._closeToken).ConfigureAwait(false); + //this._closeToken; + }).ConfigureAwait(false); - if (this.IsConnected) + if (this.IsConnected) + { + if (this._connection != null) { - if (this._connection != null) - { - this._connection.ConnectionShutdown += this.OnConnectionShutdownAsync; - this._connection.CallbackException += this.OnCallbackExceptionAsync; - this._connection.ConnectionBlocked += this.OnConnectionBlockedAsync; - - //this._logger?.LogInformation($"RabbitMQ persistent connection acquired a connection {this._connection.Endpoint.HostName} and is subscribed to failure events"); - output = true; - } - else - { - output = false; - } + this._connection.ConnectionShutdown += this.OnConnectionShutdownAsync; + this._connection.CallbackException += this.OnCallbackExceptionAsync; + this._connection.ConnectionBlocked += this.OnConnectionBlockedAsync; + + //this._logger?.LogInformation($"RabbitMQ persistent connection acquired a connection {this._connection.Endpoint.HostName} and is subscribed to failure events"); + output = true; } else { - this._logger?.LogCritical("FATAL ERROR: RabbitMQ connections could not be created and opened"); - output = false; } + } + else + { + this._logger?.LogCritical("FATAL ERROR: RabbitMQ connections could not be created and opened"); + + output = false; + } //} //finally //{ @@ -205,6 +205,7 @@ private async ValueTask CreateConnection() catch (Exception ex) { this._logger?.LogError(ex, "CreateConnection: "); + throw; } finally {