admin/src/Oms.Application/Messaging/OrderBatchJobEventHandler.cs
2026-10-10 16:41:28 +08:00

38 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Fake.DependencyInjection;
using Fake.EventBus;
using Fake.UnitOfWork;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Oms.Application.Services.Orders.Batch;
namespace Oms.Application.Messaging;
/// <summary>
/// 订单批量集成事件处理器。
/// 正常返回 Ack;抛异常由 Fake.EventBus.RabbitMQ 重试后 Nack 进 DLX。
/// </summary>
public sealed class OrderBatchJobEventHandler(
OrderBatchJobProcessor processor,
IUnitOfWorkManager unitOfWorkManager,
IOptions<OrderBatchRabbitMqOptions> options,
ILogger<OrderBatchJobEventHandler> logger)
: IEventHandler<OrderBatchJobIntegrationEvent>, ITransientDependency
{
public async Task HandleAsync(OrderBatchJobIntegrationEvent @event, CancellationToken cancellationToken)
{
if (!options.Value.Enabled)
{
logger.LogDebug(
"Order batch messaging disabled, skip event {EventId} action={Action}",
@event.Id,
@event.Action);
return;
}
// ForecastBilling 成功后继续写轨迹/面单/自动触发 Outbox,须事务性 UoW
using var unitOfWork = unitOfWorkManager.Begin(OmsOutboxUnitOfWork.Transactional());
await processor.ProcessAsync(@event.ToMessage(), cancellationToken);
await unitOfWork.CompleteAsync(cancellationToken);
}
}