[FA-4] Adds an event bus infrastructure, a RabbitMQ implementation and rewires existing mutations on NovelService to utilize it.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user