public async Task Handle(OrderCancelledDomainEvent domainEvent, CancellationToken cancellationToken)
        {
            _logger.LogWithProps(LogLevel.Information,
                                 $"Handling {nameof(OrderCancelledDomainEvent)} domain event",
                                 "OrderId".ToKvp(domainEvent.OrderId));

            var integrationEvent = new OrderCancelledIntegrationEvent
            {
                OrderId       = domainEvent.OrderId,
                OrderItems    = domainEvent.OrderItems,
                PreviousState = domainEvent.PreviousState.Name,
                CurrentState  = domainEvent.CurrentState.Name
            };

            await _eventBus.PublishAsync(integrationEvent);

            _logger.LogWithProps(LogLevel.Information,
                                 $"Integration event {nameof(OrderCancelledIntegrationEvent)} published",
                                 "EventId".ToKvp(integrationEvent.Id),
                                 "PreviousState".ToKvp(integrationEvent.PreviousState),
                                 "CurrentState".ToKvp(integrationEvent.CurrentState),
                                 "OfferIds".ToKvp(string.Join(",", integrationEvent.OrderItems.Select(x => x.OfferId))));

            var notificationIntegrationEvents = PrepareNotificationIntegrationEvents(domainEvent);

            foreach (var notificationIntegrationEvent in notificationIntegrationEvents)
            {
                await _eventBus.PublishAsync(notificationIntegrationEvent);
            }

            _logger.LogWithProps(LogLevel.Information,
                                 $"Published {notificationIntegrationEvents.Count} {nameof(OrderCancelledIntegrationEvent)} integration events",
                                 "PublishedEventIds".ToKvp(string.Join(",", notificationIntegrationEvents.Select(x => x.Id))),
                                 "ReceiverIds".ToKvp(string.Join(",", notificationIntegrationEvents.Select(x => x.UserId))));
        }
        public async Task Handle(OrderCancelledDomainEvent notification, CancellationToken cancellationToken)
        {
            _logger.LogInformation(" [x] OrderCancelledDomainEventHandler: Handling domain event...");

            var integrationEvent = new OrderCancelledIntegrationEvent(orderId: notification.OrderId, reason: notification.CancellationReason);

            _logger.LogInformation(" [x] OrderCancelledDomainEventHandler: Publishing integration event OrderCancelledIntegrationEvent");
            await _orderingIntegrationEventService.PublishEvent(integrationEvent);
        }
Esempio n. 3
0
        /// <summary>
        /// Handler which processes the command when customer executes cancel order from app
        /// </summary>
        public async Task <bool> Handle(CancelOrderCommand command, CancellationToken cancellationToken)
        {
            var orderToUpdate = await _orderRepository.GetAsync(command.OrderNumber);

            orderToUpdate.SetCancelledStatus();
            var orderCancelledEvent = new OrderCancelledIntegrationEvent(command.OrderNumber);
            await _endpoint.Publish(orderCancelledEvent);

            return(await _orderRepository.UnitOfWork.SaveEntitiesAsync());
        }
 public Task Handle(OrderCancelledIntegrationEvent message, IMessageHandlerContext context)
 {
     // Nothing more to do; the saga is over
     MarkAsComplete();
     return(Task.CompletedTask);
 }