protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            _logger.LogInformation("OrderProcessing Service Started");

            while (!stoppingToken.IsCancellationRequested)
            {
                string orderRequest = _consumer.ReadMessage();
                if (!string.IsNullOrWhiteSpace(orderRequest))
                {
                    //Deserilaize
                    OrderRequest order = JsonConvert.DeserializeObject <OrderRequest>(orderRequest);

                    //TODO:: Process Order
                    _logger.LogInformation($"Info: OrderHandler => Processing the order for {order.productname}");
                    order.status = OrderStatus.COMPLETED;

                    //Write to ReadyToShip Queue

                    await _producer.WriteMessage(JsonConvert.SerializeObject(order), "readytoship");
                }
                else
                {
                    await Task.Delay(2000);
                }
            }
        }
示例#2
0
        public async Task <ActionResult> PostAsync([FromBody] OrderRequest value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            //Serialize
            string serializedOrder = JsonConvert.SerializeObject(value);
            await _producer.WriteMessage(serializedOrder, "orderrequests");

            return(Created(new Guid().ToString(), OrderStatus.IN_PROGRESS));
        }