feat(templateDistributor, BLL): доделал распределение шаблонов. Сохраняет в БД + ставит задания роботам на обновление. MqService - может принимать список объектов для отправки, доработана кодировка отправки сообщений.
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
namespace PARR.BLL.Domain.Mq
|
||||
using PARR.Common.Domain;
|
||||
|
||||
namespace PARR.BLL.Domain.Mq
|
||||
{
|
||||
/// <summary>
|
||||
/// Модель в MQ, распределить шаблоны для JobGroupId (для TemplateDistributor)
|
||||
@@ -6,5 +8,7 @@
|
||||
public class TemplateDistributorMq
|
||||
{
|
||||
public Guid JobGroupId { get; set; }
|
||||
|
||||
public required HistoryInitiator Initiator { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ using PARR.BLL.Services.Interfaces;
|
||||
using RabbitMQ.Client;
|
||||
using RabbitMQ.Client.Events;
|
||||
using System.Text;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace PARR.BLL.Services.Implementations
|
||||
{
|
||||
@@ -17,6 +19,11 @@ namespace PARR.BLL.Services.Implementations
|
||||
|
||||
// реализация для RabbitMQ.Client 7.1.2
|
||||
|
||||
private static readonly JsonSerializerOptions jsonOptions = new JsonSerializerOptions
|
||||
{
|
||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||
};
|
||||
|
||||
public MqServiceV2(ILogger<MqServiceV2> logger)
|
||||
{
|
||||
this.logger = logger;
|
||||
@@ -108,6 +115,12 @@ namespace PARR.BLL.Services.Implementations
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<MqSendResult> SendAsync(IMqSettings mqSettings, List<object> msgObjectList)
|
||||
{
|
||||
var msgStringList = msgObjectList.Select(t => JsonSerializer.Serialize(t, jsonOptions)).ToArray();
|
||||
|
||||
return await SendAsync(mqSettings, msgStringList);
|
||||
}
|
||||
|
||||
public async Task<MqSendResult> SendAsync(IMqSettings mqSettings, string[] msgList)
|
||||
{
|
||||
@@ -136,7 +149,8 @@ namespace PARR.BLL.Services.Implementations
|
||||
props.DeliveryMode = DeliveryModes.Persistent;
|
||||
//время жизни, мс
|
||||
//props.Expiration = "60000";
|
||||
props.ContentType = "text/plain";//"application/json";
|
||||
//props.ContentType = "text/plain";//"application/json";
|
||||
props.ContentType = "text/plain; charset=utf-8";//"application/json";
|
||||
|
||||
channel.BasicReturnAsync += async (sender, ea) =>
|
||||
{
|
||||
|
||||
@@ -8,6 +8,22 @@ namespace PARR.BLL.Services.Interfaces
|
||||
public interface IMqService : IAsyncDisposable // IDisposable
|
||||
{
|
||||
Task<bool> InitConsumerAsync(IMqSettings mqSettings, MqMessageHandlerDelegate messageHandler);
|
||||
|
||||
/// <summary>
|
||||
/// Отправить сообщение в очередь используя список строк
|
||||
/// !!! Избавиться от этого метода, вместо него использовать со списком объектов !!!
|
||||
/// </summary>
|
||||
/// <param name="mqSettings"></param>
|
||||
/// <param name="msgList"></param>
|
||||
/// <returns></returns>
|
||||
Task<MqSendResult> SendAsync(IMqSettings mqSettings, string[] msgList);
|
||||
|
||||
/// <summary>
|
||||
/// Отправить сообщение в очередь используя список объектов
|
||||
/// </summary>
|
||||
/// <param name="mqSettings"></param>
|
||||
/// <param name="msgObjectList"></param>
|
||||
/// <returns></returns>
|
||||
Task<MqSendResult> SendAsync(IMqSettings mqSettings, List<object> msgObjectList);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user