Code re-factorings and formatting in EventBus.RabbitMQ project

This commit is contained in:
Rafsanul Hasan 2018-09-09 05:17:16 +06:00
parent 086302f5f1
commit db13fa6091
No known key found for this signature in database
GPG Key ID: FC57FD2D87BE60DD
3 changed files with 290 additions and 285 deletions

View File

@ -18,8 +18,7 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ
private readonly int _retryCount;
IConnection _connection;
bool _disposed;
object sync_root = new object();
readonly object sync_root = new object();
public DefaultRabbitMQPersistentConnection(IConnectionFactory connectionFactory, ILogger<DefaultRabbitMQPersistentConnection> logger, int retryCount = 5)
{
@ -28,13 +27,7 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ
_retryCount = retryCount;
}
public bool IsConnected
{
get
{
return _connection != null && _connection.IsOpen && !_disposed;
}
}
public bool IsConnected => _connection != null && _connection.IsOpen && !_disposed;
public IModel CreateModel()
{
@ -48,7 +41,10 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ
public void Dispose()
{
if (_disposed) return;
if (_disposed)
{
return;
}
_disposed = true;
@ -103,7 +99,10 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ
private void OnConnectionBlocked(object sender, ConnectionBlockedEventArgs e)
{
if (_disposed) return;
if (_disposed)
{
return;
}
_logger.LogWarning("A RabbitMQ connection is shutdown. Trying to re-connect...");
@ -112,7 +111,10 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ
void OnCallbackException(object sender, CallbackExceptionEventArgs e)
{
if (_disposed) return;
if (_disposed)
{
return;
}
_logger.LogWarning("A RabbitMQ connection throw exception. Trying to re-connect...");
@ -121,7 +123,10 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ
void OnConnectionShutdown(object sender, ShutdownEventArgs reason)
{
if (_disposed) return;
if (_disposed)
{
return;
}
_logger.LogWarning("A RabbitMQ connection is on shutdown. Trying to re-connect...");

View File

@ -72,7 +72,7 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ
_persistentConnection.TryConnect();
}
var policy = RetryPolicy.Handle<BrokerUnreachableException>()
var policy = Policy.Handle<BrokerUnreachableException>()
.Or<SocketException>()
.WaitAndRetry(_retryCount, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (ex, time) =>
{
@ -97,7 +97,7 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ
channel.BasicPublish(exchange: BROKER_NAME,
routingKey: eventName,
mandatory:true,
mandatory: true,
basicProperties: properties,
body: body);
});
@ -189,7 +189,7 @@ namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ
await ProcessEvent(eventName, message);
channel.BasicAck(ea.DeliveryTag,multiple:false);
channel.BasicAck(ea.DeliveryTag, multiple: false);
};
channel.BasicConsume(queue: _queueName,