消费者cultureInfo 自动处理,消费成功自动设置事件状态
continuous-integration/drone/push Build is passing

This commit is contained in:
hang
2024-10-11 19:43:15 +08:00
parent 79fd83449a
commit f67ebce739
5 changed files with 39 additions and 42 deletions
@@ -0,0 +1,34 @@
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
using IRaCIS.Core.Domain.BaseModel;
using IRaCIS.Core.Domain.Share;
using MassTransit;
using NPOI.SS.Formula.Functions;
public class CultureInfoFilter<T> (IRepository<EventStoreRecord> _eventStoreRecordRepository) : IFilter<ConsumeContext<T>> where T : DomainEvent
{
public async Task Send(ConsumeContext<T> context, IPipe<ConsumeContext<T>> next)
{
var cultureInfoName = context.Message.CultureInfoName;
var eventId = context.Message.EventId;
if (!string.IsNullOrEmpty(cultureInfoName))
{
CultureInfo.CurrentCulture = new CultureInfo(cultureInfoName);
CultureInfo.CurrentUICulture = new CultureInfo(cultureInfoName);
}
await next.Send(context);
await _eventStoreRecordRepository.BatchUpdateNoTrackingAsync(t => t.Id == eventId, u => new EventStoreRecord() { EventState= EventStateEnum.ConsumeSuccessed } );
}
public void Probe(ProbeContext context)
{
context.CreateFilterScope("CultureInfoFilter");
}
}