-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDefaultServiceBusPersisterConnection.cs
42 lines (33 loc) · 1.39 KB
/
DefaultServiceBusPersisterConnection.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using Microsoft.Azure.ServiceBus;
using Microsoft.Extensions.Logging;
using System;
namespace EventBus.ServiceBus
{
public class DefaultServiceBusPersisterConnection : IServiceBusPersisterConnection
{
private readonly ILogger<DefaultServiceBusPersisterConnection> _logger;
private readonly ServiceBusConnectionStringBuilder _serviceBusConnectionStringBuilder;
private ITopicClient _topicClient;
bool _disposed;
public DefaultServiceBusPersisterConnection(ILogger<DefaultServiceBusPersisterConnection> logger, string eventBusConnection)
{
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_serviceBusConnectionStringBuilder = new ServiceBusConnectionStringBuilder(eventBusConnection);
_topicClient = new TopicClient(_serviceBusConnectionStringBuilder, RetryPolicy.Default);
}
public ServiceBusConnectionStringBuilder ServiceBusConnectionStringBuilder => _serviceBusConnectionStringBuilder;
public ITopicClient CreateModel()
{
if (_topicClient.IsClosedOrClosing)
{
_topicClient = new TopicClient(_serviceBusConnectionStringBuilder, RetryPolicy.Default);
}
return _topicClient;
}
public void Dispose()
{
if (_disposed) return;
_disposed = true;
}
}
}