Exemplo n.º 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;
            }
        }
Exemplo n.º 2
0
        public async Task Handle(ShipOrderCommand command, CancellationToken cancellationToken)
        {
            await _repository.ShipOrder(command.Id, cancellationToken);

            await _kafkaProducer.Send(new OrderShippedEvent
            {
                Id = command.Id
            }, "ReactiveMicroservices");
        }
Exemplo n.º 3
0
        public async Task Handle(UpdateCreditLimitCommand command, CancellationToken cancellationToken)
        {
            await _repository.UpdateCreditLimit(command.CustomerId, command.CreditLimit, cancellationToken);

            await _kafkaProducer.Send(new CreditLimitChangedEvent
            {
                CustomerId  = command.CustomerId,
                CreditLimit = command.CreditLimit
            }, "ReactiveMicroservices");
        }
Exemplo n.º 4
0
        public async Task Handle(UpdateProductCommand command, CancellationToken cancellationToken)
        {
            var updatedEvent = _mapper.Map <ProductUpdatedEvent>(command);

            updatedEvent.CreatedAt = DateTime.Now;

            // Insert event to Command Db
            await _eventSources.InserEvent(updatedEvent, cancellationToken);

            await _kafkaProducer.Send(updatedEvent, "PosServices");
        }
Exemplo n.º 5
0
        public async Task Handle(CreateProductCommand command, CancellationToken cancellationToken)
        {
            var createdEvent = _mapper.Map <ProductCreatedEvent>(command);

            createdEvent.CreatedAt = DateTime.Now;

            // Insert event to Command Db
            await _eventSources.InserEvent(createdEvent, cancellationToken);

            await _kafkaProducer.Send(createdEvent, AppGlobalTopic.PosTopic);
        }
        public async Task Handle(JObject jObject, ILog log, CancellationToken cancellationToken)
        {
            var orderValidated = jObject.ToObject <OrderValidatedEvent>();

            if (orderValidated.IsValid)
            {
                var orderShippedEvent = new OrderShippedEvent
                {
                    Id = orderValidated.OrderId
                };
                await _producer.Send(orderShippedEvent, "ReactiveMicroservices");
            }
            else
            {
                var orderCancelledEvent = new OrderCancelledEvent
                {
                    Id = orderValidated.OrderId
                };
                await _producer.Send(orderCancelledEvent, "ReactiveMicroservices");
            }
        }
Exemplo n.º 7
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");
        }
        public async Task Handle(CreateCustomerCommand command, CancellationToken cancellationToken)
        {
            var customer = _mapper.Map <Customer>(command);
            await _repository.New(customer, cancellationToken);

            await _kafkaProducer.Send(new CustomerCreatedEvent
            {
                Id          = customer.Id,
                Name        = customer.Name,
                CreditLimit = customer.CreditLimit
            }, "ReactiveMicroservices");
        }
Exemplo n.º 9
0
        public async Task Handle(CreateOrderCommand command, CancellationToken cancellationToken)
        {
            var order = _mapper.Map <Order>(command);
            await _repository.New(order, cancellationToken);

            await _kafkaProducer.Send(new OrderCreatedEvent
            {
                Id         = order.Id,
                CustomerId = order.CustomerId,
                Amount     = order.Amount,
                Status     = order.Status
            }, "ReactiveMicroservices");
        }
Exemplo n.º 10
0
        public async Task Handle(DeleteProductCategoryCommand command, CancellationToken cancellationToken)
        {
            var DeletedEvent = new ProductCategoryDeletedEvent
            {
                ProductCategoryId = command.PoductCategoryId,
                CreatedAt         = DateTime.Now
            };

            // Insert event to Command Db
            await _eventSources.InserEvent(DeletedEvent, cancellationToken);

            await _kafkaProducer.Send(DeletedEvent, "PosServices");
        }
Exemplo n.º 11
0
        public async Task Handle(DeleteProductCommand command, CancellationToken cancellationToken)
        {
            var DeletedEvent = new ProductDeletedEvent
            {
                ProductId = command.ProductId,
                CreatedAt = DateTime.Now
            };

            // Insert event to Command Db
            await _eventSources.InserEvent(DeletedEvent, cancellationToken);

            await _kafkaProducer.Send(DeletedEvent, AppGlobalTopic.PosTopic);
        }
Exemplo n.º 12
0
        public async Task Handle(CreateUserCommand command, CancellationToken cancellationToken)
        {
            var userCreatedEvent = new UserCreatedEvent
            {
                Name     = command.Name,
                Password = command.Password,
                Username = command.Username,
            };

            await _eventUserRepository.InserEvent(userCreatedEvent, cancellationToken);

            await _kafkaProducer.Send(userCreatedEvent, "SocialMediaServices");
        }
Exemplo n.º 13
0
        public async Task Handle(JObject jObject, ILog log, CancellationToken cancellationToken)
        {
            var orderValidated = jObject.ToObject <OrderValidatedEvent>();

            if (orderValidated.IsValid)
            {
                var orderShippedEvent = new OrderShippedEvent {
                    Data = orderValidated.Data, OrderId = orderValidated.OrderId
                };
                await _shipedEventSources.InserEvent(orderShippedEvent, cancellationToken);

                await _producer.Send(orderShippedEvent, AppGlobalTopic.PosTopic);
            }
            else
            {
                var orderCanceledEvent = new OrderCancelledEvent {
                    Data = orderValidated.Data, OrderId = orderValidated.OrderId
                };
                await _cancelledEventSources.InserEvent(orderCanceledEvent, cancellationToken);

                await _producer.Send(orderCanceledEvent, AppGlobalTopic.PosTopic);
            }
        }
Exemplo n.º 14
0
        public async Task Handle(CreateOrderCommand command, CancellationToken cancellationToken)
        {
            var @event = _mapper.Map <OrderCreatedEvent>(command);
            // Insert event to Command Db
            await _eventSources.InserEvent(@event, cancellationToken);

            await _kafkaProducer.Send(@event, "PosServices");

            //implement choreography saga needed
            var data = _mapper.Map <MstOrder>(command);

            _orderRepository.Insert(data);
            await _uow.CommitAsync();
        }
Exemplo n.º 15
0
        public async Task Handle(CreateCustomerCommand command, CancellationToken cancellationToken)
        {
            var customerCreatedEvent = new CustomerCreatedEvent
            {
                Address   = command.Address,
                Name      = command.Name,
                Phone     = command.Phone,
                CreatedAt = DateTime.Now
            };

            // Insert event to Command Db
            await _eventSources.InserEvent(customerCreatedEvent, cancellationToken);

            await _kafkaProducer.Send(customerCreatedEvent, AppGlobalTopic.PosTopic);
        }
Exemplo n.º 16
0
        public async Task Handle(UpdateCustomerCommand command, CancellationToken cancellationToken)
        {
            var updatedEvent = new CustomerUpdatedEvent
            {
                CustomerId = command.CustomerId,
                Address    = command.Address,
                Name       = command.Name,
                Phone      = command.Phone,
                CreatedAt  = DateTime.Now
            };

            // Insert event to Command Db
            await _eventSources.InserEvent(updatedEvent, cancellationToken);

            await _kafkaProducer.Send(updatedEvent, "PosServices");
        }
Exemplo n.º 17
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;
            }
        }