public async Task CreateAsync(Order order) { try { await _repository.CreateAsync(order); _bus.Post(new OrderCreated { Order = order }); } catch (Exception e) { _logger.LogError(e, "Error trying to create order"); throw; } }
public async void Consume(OrderCreated message) { try { Thread.Sleep(3000); await _stockChecker.ReserveStockForItemsAsync(message.Order.Items); _systemBus.Post(new OrderConfirmed { OrderId = message.Order.OrderId }); } catch (NotEnoughStockForItemException e) { _logger.LogWarning(e, "Error trying to reserve stock items"); _systemBus.Post(new OrderRefused { OrderId = message.Order.OrderId }); } catch (Exception e) { _logger.LogError(e, "Error trying to reserve stock items"); throw; } }