Починил IMqService
This commit is contained in:
@@ -74,7 +74,8 @@ namespace PARR.API.MappingProfiles
|
|||||||
|
|
||||||
CreateMap<Application, ApplicationResponse>();
|
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
|
namespace PARR.BLL.Services.Implementations
|
||||||
{
|
{
|
||||||
|
|
||||||
internal class MqService : IMqService
|
internal class MqService : IMqService
|
||||||
{
|
{
|
||||||
private readonly ILogger<MqService> logger;
|
private readonly ILogger<MqService> logger;
|
||||||
@@ -15,8 +16,6 @@ namespace PARR.BLL.Services.Implementations
|
|||||||
private IConnection? connection;
|
private IConnection? connection;
|
||||||
private IModel? channel;
|
private IModel? channel;
|
||||||
|
|
||||||
public event ReceivedHandler? Received;
|
|
||||||
|
|
||||||
public MqService(ILogger<MqService> logger)
|
public MqService(ILogger<MqService> logger)
|
||||||
{
|
{
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
@@ -90,8 +89,7 @@ namespace PARR.BLL.Services.Implementations
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool InitConsumer(IMqSettings mqSettings, MqMessageHandlerDelegate messageHandler)
|
||||||
public bool InitConsumer(IMqSettings mqSettings)
|
|
||||||
{
|
{
|
||||||
logger.LogInformation($"Устанавливаю соединение с RabbitMQ: {mqSettings.HostName}, {mqSettings.QueueName}");
|
logger.LogInformation($"Устанавливаю соединение с RabbitMQ: {mqSettings.HostName}, {mqSettings.QueueName}");
|
||||||
|
|
||||||
@@ -131,14 +129,13 @@ namespace PARR.BLL.Services.Implementations
|
|||||||
var content = Encoding.UTF8.GetString(ea.Body.ToArray());
|
var content = Encoding.UTF8.GetString(ea.Body.ToArray());
|
||||||
logger.LogDebug($"Получено сообщение: {content}");
|
logger.LogDebug($"Получено сообщение: {content}");
|
||||||
|
|
||||||
//https://metanit.com/sharp/tutorial/3.14.php
|
await messageHandler.Invoke(content);
|
||||||
Received?.Invoke(content);
|
|
||||||
|
|
||||||
channel.BasicAck(ea.DeliveryTag, false);
|
channel.BasicAck(ea.DeliveryTag, false);
|
||||||
await Task.Yield();
|
await Task.Yield();
|
||||||
};
|
};
|
||||||
|
|
||||||
channel.BasicConsume(mqSettings.QueueName, false, consumer);
|
string consumerTag = channel.BasicConsume(mqSettings.QueueName, false, consumer);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|||||||
@@ -3,13 +3,11 @@ using PARR.BLL.Domain.Mq;
|
|||||||
|
|
||||||
namespace PARR.BLL.Services.Interfaces
|
namespace PARR.BLL.Services.Interfaces
|
||||||
{
|
{
|
||||||
public delegate void ReceivedHandler(string msg);
|
public delegate Task MqMessageHandlerDelegate(string msg);
|
||||||
|
|
||||||
public interface IMqService : IDisposable
|
public interface IMqService : IDisposable
|
||||||
{
|
{
|
||||||
event ReceivedHandler? Received;
|
bool InitConsumer(IMqSettings mqSettings, MqMessageHandlerDelegate test);
|
||||||
|
|
||||||
bool InitConsumer(IMqSettings mqSettings);
|
|
||||||
MqSendResult Send(IMqSettings mqSettings, string[] msgList);
|
MqSendResult Send(IMqSettings mqSettings, string[] msgList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ using PARR.BLL.Services.Interfaces;
|
|||||||
using PARR.DAL.Models;
|
using PARR.DAL.Models;
|
||||||
using PARR.GeneratorTemplates.Services;
|
using PARR.GeneratorTemplates.Services;
|
||||||
using PARR.GeneratorTemplates.Settings;
|
using PARR.GeneratorTemplates.Settings;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace PARR.GeneratorTemplates
|
namespace PARR.GeneratorTemplates
|
||||||
{
|
{
|
||||||
@@ -35,34 +37,19 @@ namespace PARR.GeneratorTemplates
|
|||||||
this.serviceProvider = serviceProvider;
|
this.serviceProvider = serviceProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: метод не async, удалить позже асинк в worker
|
public void Start()
|
||||||
public async Task 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}";
|
||||||
|
|
||||||
//{
|
// await GenerateTemplates(msg);
|
||||||
// logger.LogInformation($"Привет откуда надо!!! ${msg}");
|
#endregion
|
||||||
// //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");
|
|
||||||
|
|
||||||
|
var isConnected = mqService.InitConsumer(mqSettings, GenerateTemplates);
|
||||||
|
|
||||||
|
if (!isConnected)
|
||||||
|
throw new Exception("Ошибка при подключении к RabbitMq");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Stop()
|
public void Stop()
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
{
|
{
|
||||||
public interface IGeneratorTemplate
|
public interface IGeneratorTemplate
|
||||||
{
|
{
|
||||||
Task Start();
|
void Start();
|
||||||
void Stop();
|
void Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,7 @@ namespace PARR.GeneratorTemplatesWorker
|
|||||||
|
|
||||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
{
|
{
|
||||||
// todo: обернуть в таск?
|
generatorTemplate.Start();
|
||||||
await generatorTemplate.Start();
|
|
||||||
//while (!stoppingToken.IsCancellationRequested)
|
//while (!stoppingToken.IsCancellationRequested)
|
||||||
//{
|
//{
|
||||||
// _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
// _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="docker-compose.aihit-syncher.yml" />
|
<None Include="docker-compose.aihit-syncher.yml" />
|
||||||
<None Include="docker-compose.espp-template-sync.yml" />
|
<None Include="docker-compose.espp-template-sync.yml" />
|
||||||
|
<None Include="docker-compose.generator-templates.yml" />
|
||||||
<None Include="docker-compose.yml" />
|
<None Include="docker-compose.yml" />
|
||||||
<None Include=".dockerignore" />
|
<None Include=".dockerignore" />
|
||||||
<None Include="stack.yml" />
|
<None Include="stack.yml" />
|
||||||
|
|||||||
Reference in New Issue
Block a user