Exemplo n.º 1
0
        public async Task <IActionResult> GetAll()
        {
            // ambil informasi order
            var listOfOrder = await _repository.GetAll();

            // ambil informasi customer id berdasarkan data order, untuk keperluan request data ke service customer
            var listOfCustomerId = listOfOrder.Select(f => (int)f.CustomerId)
                                   .Distinct().ToArray();

            // request data ke service customer
            var timeout        = TimeSpan.FromSeconds(_rabbitMQSettings.Value.ServiceQueues[1].Timeout);
            var serviceAddress = new Uri($"rabbitmq://{_rabbitMQSettings.Value.Host}/{_rabbitMQSettings.Value.ServiceQueues[1].Name}");

            var client = MassTransitHelper <CustomerRequest, CustomerResponse[]> .CreateRequestClient(serviceAddress, timeout, _bus);

            var listOfCustomer = await client.Request(new CustomerRequest { ArrayOfId = listOfCustomerId });

            // join data order dan customer
            listOfOrder.Join(listOfCustomer, (order) => order.CustomerId, (customer) => customer.Id, (order, customer) =>
            {
                order.CustomerName = customer.Name;
                return(order);
            }).ToList();

            return(Ok(listOfOrder));
        }
Exemplo n.º 2
0
        private async Task <bool> IsValidCustomer(int customerId)
        {
            CustomerResponse customer = null;

            // request data customer ke service customer
            var timeout        = TimeSpan.FromSeconds(_rabbitMQSettings.Value.ServiceQueues[0].Timeout);
            var serviceAddress = new Uri($"rabbitmq://{_rabbitMQSettings.Value.Host}/{_rabbitMQSettings.Value.ServiceQueues[0].Name}");

            try
            {
                var client = MassTransitHelper <CustomerRequest, CustomerResponse> .CreateRequestClient(serviceAddress, timeout, _bus);

                customer = await client.Request(new CustomerRequest { Id = customerId });
            }
            catch
            {
            }

            return(customer != null);
        }