/
afanasevn
/
MaxSystems
Обзор
Документация
Войти
/
afanasevn
/
MaxSystems
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/MaxSystems.Infrastructure/Integration/IntegrationEventPublisher.cs
54 строки
2 KB
IBS\NAfanasev
CRON Maintenance events
22 июн 2026, 18:24
22 июн 2026, 18:24
3913607
Код
Авторство
О чём код?
using MaxSystems.Application.Abstractions; using MaxSystems.Application.Integration; using MaxSystems.Domain.Entities; using MaxSystems.Domain.Enums; using MaxSystems.Infrastructure.Data; using Wolverine; namespace MaxSystems.Infrastructure.Integration; /// <summary>Публикация интеграционных событий через outbox Wolverine и журнал доставки.</summary> public sealed class IntegrationEventPublisher( AppDbContext db, IMessageBus bus) : IIntegrationEventPublisher { /// <inheritdoc /> public async Task EnqueueAsync<T>( T message, string eventType, string routingKey, IReadOnlyList<string> targetQueues, Guid? workId = null, Guid? equipmentId = null, Guid? maintenanceRegulationId = null, string? payloadSummary = null, CancellationToken ct = default) { var messageId = Guid.NewGuid(); var now = DateTime.UtcNow; foreach (var queueName in targetQueues) { db.IntegrationDeliveryLogs.Add(new IntegrationDeliveryLog { Id = Guid.NewGuid(), EventType = eventType, RoutingKey = routingKey, QueueName = queueName, WorkId = workId, EquipmentId = equipmentId, MaintenanceRegulationId = maintenanceRegulationId, Status = IntegrationDeliveryStatus.Pending, MessageId = messageId, PayloadSummary = payloadSummary, CreatedAt = now, UpdatedAt = now, }); } await bus.PublishAsync( message, new DeliveryOptions { CorrelationId = messageId.ToString() } .WithHeader(IntegrationMessageHeaders.MessageId, messageId.ToString())); } }