Починил IMqService
This commit is contained in:
@@ -74,7 +74,8 @@ namespace PARR.API.MappingProfiles
|
||||
|
||||
CreateMap<Application, ApplicationResponse>();
|
||||
|
||||
CreateMap<DAL.Models.Host, HostResponse>();
|
||||
CreateMap<DAL.Models.Host, HostResponse>()
|
||||
.ForMember(d => d.Status, o => o.MapFrom(s => s.EkStatus!.Name));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -3,13 +3,11 @@ using PARR.BLL.Domain.Mq;
|
||||
|
||||
namespace PARR.BLL.Services.Interfaces
|
||||
{
|
||||
public delegate void ReceivedHandler(string msg);
|
||||
public delegate Task MqMessageHandlerDelegate(string msg);
|
||||
|
||||
public interface IMqService : IDisposable
|
||||
{
|
||||
event ReceivedHandler? Received;
|
||||
|
||||
bool InitConsumer(IMqSettings mqSettings);
|
||||
bool InitConsumer(IMqSettings mqSettings, MqMessageHandlerDelegate test);
|
||||
MqSendResult Send(IMqSettings mqSettings, string[] msgList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,8 @@ using PARR.BLL.Services.Interfaces;
|
||||
using PARR.DAL.Models;
|
||||
using PARR.GeneratorTemplates.Services;
|
||||
using PARR.GeneratorTemplates.Settings;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace PARR.GeneratorTemplates
|
||||
{
|
||||
@@ -35,34 +37,19 @@ namespace PARR.GeneratorTemplates
|
||||
this.serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
//TODO: метод не async, удалить позже асинк в worker
|
||||
public async Task Start()
|
||||
public void Start()
|
||||
{
|
||||
//mqService.Received += async (msg) =>
|
||||
#region test
|
||||
// string msg = "{\"WorkId\":\"91219bec-e5f7-4a1a-b4c9-c135035d2498\",\"ApplicationId\":\"13044a1f-fa0c-476f-b501-2b8d06bac9f8\",\"Action\":\"create\",\"Ek\":\"ВРТ*ДВС\",\"StatusEk\":0}";
|
||||
// string msg = "{\"WorkId\":\"91219bec-e5f7-4a1a-b4c9-c135035d2498\",\"ApplicationId\":\"13044a1f-fa0c-476f-b501-2b8d06bac9f8\",\"Action\":\"deactivate\",\"Ek\":\"ВРТ*ДВС\",\"StatusEk\":0}";
|
||||
|
||||
//{
|
||||
// logger.LogInformation($"Привет откуда надо!!! ${msg}");
|
||||
// //todo: идем дальеш!
|
||||
|
||||
|
||||
// string msg = "{\"WorkId\":\"91219bec-e5f7-4a1a-b4c9-c135035d2498\",\"ApplicationId\":\"13044a1f-fa0c-476f-b501-2b8d06bac9f8\",\"Action\":\"create\",\"Ek\":\"ВРТ*ДВС\",\"StatusEk\":0}";
|
||||
string msg = "{\"WorkId\":\"91219bec-e5f7-4a1a-b4c9-c135035d2498\",\"ApplicationId\":\"13044a1f-fa0c-476f-b501-2b8d06bac9f8\",\"Action\":\"deactivate\",\"Ek\":\"ВРТ*ДВС\",\"StatusEk\":0}";
|
||||
|
||||
await GenerateTemplates(msg);
|
||||
|
||||
// // проверить как ту дела с асинком
|
||||
// // логгер работает в разных потоках все таки или нет?
|
||||
|
||||
//};
|
||||
|
||||
|
||||
|
||||
//var isConnected = mqService.InitConsumer(mqSettings);
|
||||
|
||||
//if (!isConnected)
|
||||
// throw new Exception("Ошибка при подключении к RabbitMq");
|
||||
// await GenerateTemplates(msg);
|
||||
#endregion
|
||||
|
||||
var isConnected = mqService.InitConsumer(mqSettings, GenerateTemplates);
|
||||
|
||||
if (!isConnected)
|
||||
throw new Exception("Ошибка при подключении к RabbitMq");
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{
|
||||
public interface IGeneratorTemplate
|
||||
{
|
||||
Task Start();
|
||||
void Start();
|
||||
void Stop();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,7 @@ namespace PARR.GeneratorTemplatesWorker
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
// todo: обернуть в таск?
|
||||
await generatorTemplate.Start();
|
||||
generatorTemplate.Start();
|
||||
//while (!stoppingToken.IsCancellationRequested)
|
||||
//{
|
||||
// _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
<ItemGroup>
|
||||
<None Include="docker-compose.aihit-syncher.yml" />
|
||||
<None Include="docker-compose.espp-template-sync.yml" />
|
||||
<None Include="docker-compose.generator-templates.yml" />
|
||||
<None Include="docker-compose.yml" />
|
||||
<None Include=".dockerignore" />
|
||||
<None Include="stack.yml" />
|
||||
|
||||
Reference in New Issue
Block a user