Починил IMqService
This commit is contained in:
@@ -8,6 +8,7 @@ using System.Text;
|
||||
|
||||
namespace PARR.BLL.Services.Implementations
|
||||
{
|
||||
|
||||
internal class MqService : IMqService
|
||||
{
|
||||
private readonly ILogger<MqService> logger;
|
||||
@@ -15,8 +16,6 @@ namespace PARR.BLL.Services.Implementations
|
||||
private IConnection? connection;
|
||||
private IModel? channel;
|
||||
|
||||
public event ReceivedHandler? Received;
|
||||
|
||||
public MqService(ILogger<MqService> logger)
|
||||
{
|
||||
this.logger = logger;
|
||||
@@ -90,8 +89,7 @@ namespace PARR.BLL.Services.Implementations
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool InitConsumer(IMqSettings mqSettings)
|
||||
public bool InitConsumer(IMqSettings mqSettings, MqMessageHandlerDelegate messageHandler)
|
||||
{
|
||||
logger.LogInformation($"Устанавливаю соединение с RabbitMQ: {mqSettings.HostName}, {mqSettings.QueueName}");
|
||||
|
||||
@@ -131,14 +129,13 @@ namespace PARR.BLL.Services.Implementations
|
||||
var content = Encoding.UTF8.GetString(ea.Body.ToArray());
|
||||
logger.LogDebug($"Получено сообщение: {content}");
|
||||
|
||||
//https://metanit.com/sharp/tutorial/3.14.php
|
||||
Received?.Invoke(content);
|
||||
await messageHandler.Invoke(content);
|
||||
|
||||
channel.BasicAck(ea.DeliveryTag, false);
|
||||
await Task.Yield();
|
||||
};
|
||||
|
||||
channel.BasicConsume(mqSettings.QueueName, false, consumer);
|
||||
string consumerTag = channel.BasicConsume(mqSettings.QueueName, false, consumer);
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user