mq dispose
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user