mq dispose

This commit is contained in:
Mikhail Trubnikov
2023-09-21 16:38:38 +10:00
parent 109ac9d70b
commit cff93be36a
4 changed files with 24 additions and 8 deletions

View File

@@ -12,6 +12,9 @@ namespace PARR.BLL.Services.Implementations
{
private readonly ILogger<MqService> logger;
private IConnection? connection;
private IModel? channel;
public event ReceivedHandler? Received;
public MqService(ILogger<MqService> logger)
@@ -88,7 +91,6 @@ namespace PARR.BLL.Services.Implementations
}
//TODO: rename ListenQueue
public void InitConsumer(IMqSettings mqSettings)
{
logger.LogInformation($"Устанавливаю соединение с RabbitMQ: {mqSettings.HostName}, {mqSettings.QueueName}");
@@ -104,8 +106,11 @@ namespace PARR.BLL.Services.Implementations
try
{
using var connection = facory.CreateConnection();
using var channel = connection.CreateModel();
//using var connection = facory.CreateConnection();
//using var channel = connection.CreateModel();
connection = facory.CreateConnection();
channel = connection.CreateModel();
var args = new Dictionary<string, object> { { "x-queue-mode", "lazy" } };
@@ -142,5 +147,13 @@ namespace PARR.BLL.Services.Implementations
}
}
public void Dispose()
{
channel?.Close();
connection?.Close();
channel?.Dispose();
connection?.Dispose();
}
}
}