Skip to content

Commit 6f8cd17

Browse files
Refactoring to better terms
1 parent ab45bb9 commit 6f8cd17

6 files changed

Lines changed: 31 additions & 33 deletions

File tree

src/BuildingBlocks/EventBus/EventBusRabbitMQ/DefaultRabbitMQPersisterConnection.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@
1010

1111
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ
1212
{
13-
public class DefaultRabbitMQPersisterConnection
14-
: IRabbitMQPersisterConnection
13+
public class DefaultRabbitMQPersistentConnection
14+
: IRabbitMQPersistentConnection
1515
{
1616
private readonly IConnectionFactory _connectionFactory;
17-
private readonly ILogger<DefaultRabbitMQPersisterConnection> _logger;
17+
private readonly ILogger<DefaultRabbitMQPersistentConnection> _logger;
1818

1919
IConnection _connection;
2020
bool _disposed;
2121

2222
object sync_root = new object();
2323

24-
public DefaultRabbitMQPersisterConnection(IConnectionFactory connectionFactory,ILogger<DefaultRabbitMQPersisterConnection> logger)
24+
public DefaultRabbitMQPersistentConnection(IConnectionFactory connectionFactory,ILogger<DefaultRabbitMQPersistentConnection> logger)
2525
{
2626
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory));
2727
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
@@ -87,13 +87,13 @@ public bool TryConnect()
8787
_connection.CallbackException += OnCallbackException;
8888
_connection.ConnectionBlocked += OnConnectionBlocked;
8989

90-
_logger.LogInformation($"RabbitMQ persister connection acquire a connection {_connection.Endpoint.HostName} and is subscribed to failure events");
90+
_logger.LogInformation($"RabbitMQ persistent connection acquired a connection {_connection.Endpoint.HostName} and is subscribed to failure events");
9191

9292
return true;
9393
}
9494
else
9595
{
96-
_logger.LogCritical("FATAL ERROR: RabbitMQ connections can't be created and opened");
96+
_logger.LogCritical("FATAL ERROR: RabbitMQ connections could not be created and opened");
9797

9898
return false;
9999
}

src/BuildingBlocks/EventBus/EventBusRabbitMQ/EventBusRabbitMQ.cs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class EventBusRabbitMQ : IEventBus, IDisposable
2121
{
2222
const string BROKER_NAME = "eshop_event_bus";
2323

24-
private readonly IRabbitMQPersisterConnection _persisterConnection;
24+
private readonly IRabbitMQPersistentConnection _persistentConnection;
2525
private readonly ILogger<EventBusRabbitMQ> _logger;
2626

2727
private readonly Dictionary<string, List<IIntegrationEventHandler>> _handlers
@@ -33,20 +33,19 @@ private readonly List<Type> _eventTypes
3333
private IModel _consumerChannel;
3434
private string _queueName;
3535

36-
public EventBusRabbitMQ(IRabbitMQPersisterConnection persisterConnection, ILogger<EventBusRabbitMQ> logger)
36+
public EventBusRabbitMQ(IRabbitMQPersistentConnection persistentConnection, ILogger<EventBusRabbitMQ> logger)
3737
{
38-
_persisterConnection = persisterConnection ?? throw new ArgumentNullException(nameof(persisterConnection));
38+
_persistentConnection = persistentConnection ?? throw new ArgumentNullException(nameof(persistentConnection));
3939
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
4040

4141
_consumerChannel = CreateConsumerChannel();
4242
}
4343

44-
4544
public void Publish(IntegrationEvent @event)
4645
{
47-
if (!_persisterConnection.IsConnected)
46+
if (!_persistentConnection.IsConnected)
4847
{
49-
_persisterConnection.TryConnect();
48+
_persistentConnection.TryConnect();
5049
}
5150

5251
var policy = RetryPolicy.Handle<BrokerUnreachableException>()
@@ -56,7 +55,7 @@ public void Publish(IntegrationEvent @event)
5655
_logger.LogWarning(ex.ToString());
5756
});
5857

59-
using (var channel = _persisterConnection.CreateModel())
58+
using (var channel = _persistentConnection.CreateModel())
6059
{
6160
var eventName = @event.GetType()
6261
.Name;
@@ -87,12 +86,12 @@ public void Subscribe<T>(IIntegrationEventHandler<T> handler) where T : Integrat
8786
}
8887
else
8988
{
90-
if (!_persisterConnection.IsConnected)
89+
if (!_persistentConnection.IsConnected)
9190
{
92-
_persisterConnection.TryConnect();
91+
_persistentConnection.TryConnect();
9392
}
9493

95-
using (var channel = _persisterConnection.CreateModel())
94+
using (var channel = _persistentConnection.CreateModel())
9695
{
9796
channel.QueueBind(queue: _queueName,
9897
exchange: BROKER_NAME,
@@ -125,12 +124,12 @@ public void Unsubscribe<T>(IIntegrationEventHandler<T> handler) where T : Integr
125124
{
126125
_eventTypes.Remove(eventType);
127126

128-
if (!_persisterConnection.IsConnected)
127+
if (!_persistentConnection.IsConnected)
129128
{
130-
_persisterConnection.TryConnect();
129+
_persistentConnection.TryConnect();
131130
}
132131

133-
using (var channel = _persisterConnection.CreateModel())
132+
using (var channel = _persistentConnection.CreateModel())
134133
{
135134
channel.QueueUnbind(queue: _queueName,
136135
exchange: BROKER_NAME,
@@ -160,12 +159,12 @@ public void Dispose()
160159

161160
private IModel CreateConsumerChannel()
162161
{
163-
if (!_persisterConnection.IsConnected)
162+
if (!_persistentConnection.IsConnected)
164163
{
165-
_persisterConnection.TryConnect();
164+
_persistentConnection.TryConnect();
166165
}
167166

168-
var channel = _persisterConnection.CreateModel();
167+
var channel = _persistentConnection.CreateModel();
169168

170169
channel.ExchangeDeclare(exchange: BROKER_NAME,
171170
type: "direct");

src/BuildingBlocks/EventBus/EventBusRabbitMQ/IRabbitMQPersisterConnection.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
namespace Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ
55
{
6-
7-
public interface IRabbitMQPersisterConnection
6+
public interface IRabbitMQPersistentConnection
87
: IDisposable
98
{
109
bool IsConnected { get; }

src/Services/Basket/Basket.API/Startup.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,16 @@ public void ConfigureServices(IServiceCollection services)
6868
});
6969

7070

71-
services.AddSingleton<IRabbitMQPersisterConnection>(sp =>
71+
services.AddSingleton<IRabbitMQPersistentConnection>(sp =>
7272
{
7373
var settings = sp.GetRequiredService<IOptions<BasketSettings>>().Value;
74-
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersisterConnection>>();
74+
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>();
7575
var factory = new ConnectionFactory()
7676
{
7777
HostName = settings.EventBusConnection
7878
};
7979

80-
return new DefaultRabbitMQPersisterConnection(factory, logger);
80+
return new DefaultRabbitMQPersistentConnection(factory, logger);
8181
});
8282

8383
services.AddSingleton<IEventBus, EventBusRabbitMQ>();

src/Services/Catalog/Catalog.API/Startup.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,16 @@ public void ConfigureServices(IServiceCollection services)
103103

104104
services.AddTransient<ICatalogIntegrationEventService, CatalogIntegrationEventService>();
105105

106-
services.AddSingleton<IRabbitMQPersisterConnection>(sp =>
106+
services.AddSingleton<IRabbitMQPersistentConnection>(sp =>
107107
{
108108
var settings = sp.GetRequiredService<IOptions<CatalogSettings>>().Value;
109-
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersisterConnection>>();
109+
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>();
110110
var factory = new ConnectionFactory()
111111
{
112112
HostName = settings.EventBusConnection
113113
};
114114

115-
return new DefaultRabbitMQPersisterConnection(factory, logger);
115+
return new DefaultRabbitMQPersistentConnection(factory, logger);
116116
});
117117

118118
services.AddSingleton<IEventBus, EventBusRabbitMQ>();

src/Services/Ordering/Ordering.API/Startup.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,16 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
107107
var serviceProvider = services.BuildServiceProvider();
108108
services.AddTransient<IOrderingIntegrationEventService, OrderingIntegrationEventService>();
109109

110-
services.AddSingleton<IRabbitMQPersisterConnection>(sp =>
110+
services.AddSingleton<IRabbitMQPersistentConnection>(sp =>
111111
{
112-
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersisterConnection>>();
112+
var logger = sp.GetRequiredService<ILogger<DefaultRabbitMQPersistentConnection>>();
113113

114114
var factory = new ConnectionFactory()
115115
{
116116
HostName = Configuration["EventBusConnection"]
117117
};
118118

119-
return new DefaultRabbitMQPersisterConnection(factory, logger);
119+
return new DefaultRabbitMQPersistentConnection(factory, logger);
120120
});
121121

122122
services.AddSingleton<IEventBus, EventBusRabbitMQ>();

0 commit comments

Comments
 (0)