public async Task <Order> CreateOrderAsync(Guid customerId, IEnumerable <OrderItem> orderItems) { var order = orderService.CreateOrder(customerId, orderItems); var processOrderCommand = new ProcessOrderCommand(order); await bus.EnqueueAsync(processOrderCommand, ProcessOrderCommand.CommandQueueName); return(order); }
public Task Handle(ProcessOrderCommand message, IMessageHandlerContext context) { Data.OrderId = message.OrderId; return(context.Send(new ProcessPaymentCommand { OrderId = Data.OrderId })); }
public Task Handle(ProcessOrderCommand message, IMessageHandlerContext context) { _log.InfoFormat("Processing order {0}", Data.OrderId); return(context.Send(new ProcessPaymentCommand { OrderId = Data.OrderId })); }
public void Handle(ProcessOrderCommand message) { // here we should check the state // and if saga allready done this step => saga repository // ... //var currentState = this._orderSagaRepository.GetSagaState(message.OrderId); var newState = message.State; Console.WriteLine(); Console.WriteLine("-----------------------------------"); Console.WriteLine(DateTime.Now); Console.WriteLine("Processing order '{0}' to AcceptOrderHandler of the website...", message.OrderId); this.Data.OrderId = message.OrderId; this.Data.Customerid = message.CustomerId; this.Data.OrderState = message.State; this.Data.ProductId = message.ProductId; this.Data.ProductPrice = message.ProductPrice; this.Data.OrderState = message.State; Console.WriteLine(); Console.WriteLine(DateTime.Now); Console.WriteLine("Adding new order '{0}' to the db...", message.OrderId); // save the order into the db this.Bus.Send( new AddNewOrderMessage { OrderId = message.OrderId, CustomerId = message.CustomerId, ProductId = message.ProductId, OrderState = message.State }); Console.WriteLine(); Console.WriteLine(DateTime.Now); Console.WriteLine("Processing order '{0}' to the SALES...", message.OrderId); // remote message to sales dept. this.Bus.Publish <OrderSentToSalesEvent>( e => { e.OrderId = message.OrderId; e.ProductId = message.ProductId; e.CustomerId = message.CustomerId; e.State = OrderState.OrderPlaced; }); Console.WriteLine("-----------------------------------"); Console.WriteLine(); // save current saga state this._orderSagaRepository.SaveSagaState(this.Data); }
public async Task Handle(ProcessOrderCommand message, IMessageHandlerContext context) { Logger.InfoFormat("ProcessOrder command received. Starting saga for orderid {0}." , message.OrderId); Data.OrderId = message.OrderId; Data.AddressFrom = message.AddressFrom; Data.AddressTo = message.AddressTo; Data.Price = message.Price; Data.Weight = message.Weight; await context.Send(new PlanOrderCommand { OrderId = Data.OrderId, AddressTo = Data.AddressTo }).ConfigureAwait(false); }
public void Handle(ProcessOrderCommand message) { Logger.InfoFormat("ProcessOrder command received. Starting saga for orderid {0}." , message.OrderId); Data.OrderId = message.OrderId; Data.AddressFrom = message.AddressFrom; Data.AddressTo = message.AddressTo; Data.Price = message.Price; Data.Weight = message.Weight; Bus.Send(new PlanOrderCommand { AddressTo = Data.AddressTo }); }
public async Task <Order> ProcessOrder([FromBody] ProcessOrderCommand command) { Order order = null; var result = await Task.Factory.StartNew(async() => { return(await _mediator.Send(command)); }); order = await result; return(order); }
// GET public async Task <IActionResult> Index() { var processOrderCommand = new ProcessOrderCommand { AddressFrom = "My Home", AddressTo = "Work", Price = 12212, Weight = 12 }; await _endpoint.Send("elcavernas.queue.orders", processOrderCommand).ConfigureAwait(false); return(Content("processOrderCommand Sent!!!")); }
public async Task ProcessOrderAsync(ProcessOrderCommand processOrderCommand) { var commandHandlerSuccess = await orderCommandHandler.HandleAsync(processOrderCommand); var orderProcessedEvent = new OrderProcessedEvent(processOrderCommand.Order); orderProcessedEvent.Success = true; if (!commandHandlerSuccess) { orderProcessedEvent.Success = false; } await bus.EnqueueAsync(orderProcessedEvent, OrderProcessedEvent.EventQueueName); }
public async Task <int> Handle(ProcessOrderCommand command) { Order order = null; using (var tx = await _db.Database.BeginTransactionAsync()) { try { order = CreateOrder(command.Amount); await _db.SaveChangesAsync(); // req/resp model for payment service // http or queues await _paymentClient.Process(order); tx.Commit(); } catch (PaymentServiceException) { order.Status = OrderStatus.PaymentPending; tx.Commit(); throw new Exception("Couldn't process the payment, please check your credit card provider and try again"); } catch (Exception e) { _logger.LogError(e, $"Error processing order {order?.Id}"); tx.Rollback(); // log and bubble up throw; } } // fire and forget to downstream systems // pub/sub model await _mailerClient.SendEmailNotification(order); _logger.LogInformation($"Order {order.Id} processed successfully"); return(order.Id); }
public async Task <Result <Unit> > Handle(ProcessOrderCommand command, CancellationToken cancellationToken) { var order = await _repo.GetOrder(command.OrderId); var user = await _repo.GetUser(command.UserId); bool orderProcessed = order.ProcessOrder(); if (orderProcessed) { user.AddMoney(order.Total); return(Result <Unit> .NoContent()); } return(Result <Unit> .Failure("Order cannot be processed")); }
public async Task ProcessOrderAsync(ProcessOrderCommand processOrderCommand) { var commandHandlerSuccess = await _orderCommandHandler.HandleAsync(processOrderCommand); var orderProcessedEvent = new OrderProcessedEvent(processOrderCommand.Order); orderProcessedEvent.Success = true; if (!commandHandlerSuccess) { Console.WriteLine("Falha no tratamento da mensagem"); orderProcessedEvent.Success = false; } await _bus.EnqueueAsync(orderProcessedEvent, OrderProcessedEvent.EventQueueName); }
public async Task <Order> CreateOrderAsync(Guid customerId, Guid tableId, CreateOrderViewModel orderViewModel) { ICollection <OrderItem> orderItems = new List <OrderItem>(); foreach (var item in orderViewModel.OrderItems) { orderItems.Add(new OrderItem { Id = Guid.NewGuid(), ProductId = item.ProductId, Amount = item.Amount }); } var order = _orderService.CreateOrder(customerId, tableId, orderItems); var processOrderCommand = new ProcessOrderCommand(order); await _bus.EnqueueAsync(processOrderCommand, ProcessOrderCommand.CommandQueueName); return(order); }
public void Handle(ProcessOrderCommand message) { Console.WriteLine(); Console.WriteLine("1) Saga: sending order {0} to Sales ...", message.OrderId); Data.OrderId = message.OrderId; Data.Article = message.Article; Data.Description = message.Description; Data.Count = message.Count; Data.Price = message.Total; Data.Address = "Fernkorngasse, 1100 Wien"; Bus.Send( new AcceptOrderCommand { OrderId = Data.OrderId, Status = OrderStatus.Started }); }
public async Task <IActionResult> Post(ProcessOrderCommand command) { try { var orderId = await _manager.Handle(command); return(Ok(new Response { IsSucessful = orderId > 0, Message = $"Order created with ID {orderId}" })); } catch (Exception e) { return(StatusCode(500, new Response { IsSucessful = false, Message = e.Message })); } }
//Explicite implementation //Task IHandleMessages<ProcessOrderCommand>.Handle(ProcessOrderCommand message, IMessageHandlerContext context) //{ // throw new System.NotImplementedException(); //} //Step 1 : the saga receive ProcessOrderCommand from Originator (RestApi/WebMVC Client) //the saga send Command (PlanOrderCommand) to planner service (see config file for endpoint) //the saga expects to receive IOrderPlannedMessage (see planner service), //see above the received order : IHandleMessages<IOrderPlannedMessage> and then IHandleMessages<IOrderDispatchedMessage> public async Task Handle(ProcessOrderCommand message, IMessageHandlerContext context) { Console.WriteLine($"ProcessOrder command received. Starting saga for orderId {message.OrderId}"); logger.Info(message: $"ProcessOrder command received. Starting saga for orderId {message.OrderId}"); //Copy all the data into the Saga Data.OrderId = message.OrderId; Data.Price = message.Price; Data.AddressFrom = message.AddressFrom; Data.AddressTo = message.AddressTo; Data.Weight = message.Weight; //the saga the PlanOrderCommand routed in the app.config file to the input queue of the planner service (eCommerce.Planner) //the saga only fill the message with the data eCommerce.Planner needs. The planning service is a //commandline application hosting an endpoint, and the saga delegates the planning work (the heavy lifting) to its handler. await context.Send(message : new PlanOrderCommand { OrderId = Data.OrderId, AddressTo = Data.AddressTo }) // prevent the passing in of the controls thread context into the new // thread, which we don't need for sending a message .ConfigureAwait(continueOnCapturedContext: false); }
public static async Task SendEmailToDispatch(ProcessOrderCommand order) { await Task.CompletedTask; }
public ProcessOrder(ProcessOrderCommand command, ILogger logger) { this.command = command; this.logger = logger; }
public static async Task SendEmailToDispatch(ProcessOrderCommand order) { await Task.Delay(3000); }
public static void SendEmailToDispatch(ProcessOrderCommand order) { }
public static async Task SendEmailToDispatch(ProcessOrderCommand message) { }