35 lines
911 B
C#
35 lines
911 B
C#
using RabbitMQ.Client;
|
|
|
|
namespace FictionArchive.Service.Shared.Services.EventBus.Implementations;
|
|
|
|
public class RabbitMQConnectionProvider
|
|
{
|
|
private readonly IConnectionFactory _connectionFactory;
|
|
|
|
private IConnection Connection { get; set; }
|
|
private IChannel DefaultChannel { get; set; }
|
|
|
|
public RabbitMQConnectionProvider(IConnectionFactory connectionFactory)
|
|
{
|
|
_connectionFactory = connectionFactory;
|
|
}
|
|
|
|
public async Task<IConnection> GetConnectionAsync()
|
|
{
|
|
if (Connection == null)
|
|
{
|
|
Connection = await _connectionFactory.CreateConnectionAsync();
|
|
}
|
|
|
|
return Connection;
|
|
}
|
|
|
|
public async Task<IChannel> GetDefaultChannelAsync()
|
|
{
|
|
if (DefaultChannel == null)
|
|
{
|
|
DefaultChannel = await (await GetConnectionAsync()).CreateChannelAsync();
|
|
}
|
|
return DefaultChannel;
|
|
}
|
|
} |