コード例 #1
0
        public async Task Handle(JObject jObject, ILog log, CancellationToken cancellationToken)
        {
            try
            {
                bool   orderIsValid = true;
                string message      = null;

                log.Info("Consume OrderCreatedEvent");

                var dataConsomed = jObject.ToObject <OrderCreatedEvent>();
                //Consume data and validate the data
                var dataIsExist = await _customerQueries.GetCustomer(dataConsomed.CustomerId);

                if (dataIsExist != null)
                {
                    orderIsValid = false;
                    message      = "Customer not found";
                }

                var @event = new OrderValidatedEvent {
                    OrderId = dataConsomed.OrderId, IsValid = orderIsValid, Messages = new List <string> {
                        message
                    }
                };

                await _producer.Send(@event, "PosServices");
            }
            catch (Exception ex)
            {
                log.Error("Error Validating order by customer", ex);
                throw ex;
            }
        }
コード例 #2
0
        public async Task Handle(JObject jObject, ILog log, CancellationToken cancellationToken)
        {
            log.Info("Handled order created event");
            var order = jObject.ToObject <OrderCreatedEvent>();

            var isValidOrder = await _service.IsCreditLimitAvailable(order.CustomerId, order.Amount, cancellationToken);

            var @event = new OrderValidatedEvent {
                OrderId = order.Id, IsValid = isValidOrder
            };
            await _producer.Send(@event, "ReactiveMicroservices");
        }
コード例 #3
0
        public async Task Handle(JObject jObject, ILog log, CancellationToken cancellationToken)
        {
            try
            {
                bool   orderIsValid = true;
                string message      = null;

                log.Info("Consume OrderCreatedEvent");

                var dataConsomed = jObject.ToObject <OrderCreatedEvent>();

                var allProduct = dataConsomed.OrderItems
                                 .Select(x => x.PartNumber)
                                 .ToList();

                //Consume data and validate the data
                allProduct.ForEach(async item =>
                {
                    var dataIsExist = await _productQueries.GetProductByPartNumber(item);
                    if (dataIsExist == null)
                    {
                        orderIsValid = false;
                    }
                });

                if (orderIsValid == false)
                {
                    message = "Customer not found";
                }

                var @event = new OrderValidatedEvent {
                    OrderId = dataConsomed.OrderId, IsValid = orderIsValid, Messages = new List <string> {
                        message
                    }
                };

                await _producer.Send(@event, "PosServices");
            }
            catch (Exception ex)
            {
                log.Error("Error Validating order by product", ex);
                throw ex;
            }
        }