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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace PARR.BLL.Services.Interfaces
|
||||
{
|
||||
public delegate void ReceivedHandler(string msg);
|
||||
|
||||
public interface IMqService
|
||||
public interface IMqService : IDisposable
|
||||
{
|
||||
event ReceivedHandler? Received;
|
||||
|
||||
|
||||
@@ -23,17 +23,20 @@ namespace PARR.GeneratorTemplates
|
||||
|
||||
public void Start()
|
||||
{
|
||||
mqService.InitConsumer(mqSettings);
|
||||
|
||||
mqService.Received += (msg) =>
|
||||
{
|
||||
logger.LogInformation($"Привет откуда надо!!! ${msg}");
|
||||
//todo: идем дальеш!
|
||||
};
|
||||
|
||||
mqService.InitConsumer(mqSettings);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
|
||||
mqService.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
]
|
||||
},
|
||||
"MqSettings": {
|
||||
"HostName": "parr-rabbitmq",
|
||||
"HostName": "10.99.253.216",
|
||||
"QueueName": "parr-generate-templates",
|
||||
"User": "generate_templates_worker",
|
||||
"Password": "Dhgdf%d&609sssa"
|
||||
|
||||
Reference in New Issue
Block a user