Exemple #1
0
        /// <summary>
        /// 发送MQ到指定服务接口
        /// </summary>
        private async Task ProcessEvent(string routingKey, string message)
        {
            using (var scope = _autofac.BeginLifetimeScope(AUTOFAC_SCOPE_NAME))
            {
                //获取绑定该routingKey的服务地址集合
                var subscriptions = await StackRedis.Current.GetAllList(routingKey);

                if (!subscriptions.Any())
                {
                    //如果Redis中不存在 则从数据库中查询 加入Redis中
                    var response = _apiHelperService.PostAsync <QueryRoutingKeyApiUrlResponse>(ServiceAddress.QueryRoutingKeyApiUrlAsync, new QueryRoutingKeyApiUrlRequest {
                        RoutingKey = routingKey
                    });
                    if (response.Result != null && response.Result.ApiUrlList.Any())
                    {
                        subscriptions = response.Result.ApiUrlList;
                        Task.Run(() =>
                        {
                            StackRedis.Current.SetLists(routingKey, response.Result.ApiUrlList);
                        });
                    }
                }
                foreach (var apiUrl in subscriptions)
                {
                    Task.Run(() =>
                    {
                        _logger.LogInformation(message);
                    });

                    await _apiHelperService.PostAsync(apiUrl, message);
                }
            }
        }
Exemple #2
0
        public async Task <ConsumerProcessEventResponse> ConsumerProcessEventAsync([FromBody] ConsumerProcessEventRequest request)
        {
            ConsumerProcessEventResponse response = new ConsumerProcessEventResponse();

            try
            {
                _logger.LogInformation($"MQ准备执行ConsumerProcessEvent方法,RoutingKey:{request.RoutingKey} Message:{request.MQBodyMessage}");
                using (var scope = _autofac.BeginLifetimeScope(AUTOFAC_SCOPE_NAME))
                {
                    //获取绑定该routingKey的服务地址集合
                    var subscriptions = await StackRedis.Current.GetAllList(request.RoutingKey);

                    if (!subscriptions.Any())
                    {
                        //如果Redis中不存在 则从数据库中查询 加入Redis中
                        string url = $"{configuration["ServiceAddress:Service.Monitor"]}{configuration["MehtodName:Monitor.QueryRabbitMq.QueryRoutingKeyApiUrlAsync"]}";
                        var    queryRoutingKeyApiUrlResponse = _apiHelperService.PostAsync <QueryRoutingKeyApiUrlResponse>(url, new QueryRoutingKeyApiUrlRequest {
                            RoutingKey = request.RoutingKey
                        });
                        if (queryRoutingKeyApiUrlResponse.Result != null && queryRoutingKeyApiUrlResponse.Result.ApiUrlList.Any())
                        {
                            subscriptions = queryRoutingKeyApiUrlResponse.Result.ApiUrlList;
                            Task.Run(() =>
                            {
                                StackRedis.Current.SetLists(request.RoutingKey, queryRoutingKeyApiUrlResponse.Result.ApiUrlList);
                            });
                        }
                    }
                    if (subscriptions != null && subscriptions.Any())
                    {
                        foreach (var apiUrl in subscriptions)
                        {
                            Task.Run(() =>
                            {
                                _logger.LogInformation(request.MQBodyMessage);
                            });

                            //这里需要做判断 假如MQ要发送到多个服务接口 其中一个消费失败 应该将其单独记录到数据库 而不影响这个消息的确认
                            await _apiHelperService.PostAsync(apiUrl, request.MQBodyMessage);
                        }
                        _logger.LogInformation($"MQ执行ProcessEvent方法完成,RoutingKey:{request.RoutingKey} Message:{request.MQBodyMessage}");
                    }
                }
            }
            catch (Exception ex)
            {
                response.Successful = false;
                response.Message    = ex.Message;
                _logger.LogError(ex, $"MQ消费失败 RoutingKey:{request.RoutingKey} Message:{request.MQBodyMessage}");
            }

            return(response);
        }
Exemple #3
0
 /// <summary>
 /// 发送MQ到MQ消费服务端
 /// </summary>
 /// <param name="routingKey"></param>
 /// <param name="message"></param>
 public void ProcessEvent(string routingKey, string message)
 {
     try
     {
         _logger.Info($"MQ准备执行ProcessEvent方法,RoutingKey:{routingKey} Message:{message}");
         _apiHelperService.PostAsync <ConsumerProcessEventResponse>(ServiceUrls.ConsumerProcessEvent, new ConsumerProcessEventRequest {
             RoutingKey = routingKey, MQBodyMessage = message
         });
     }
     catch (Exception ex)
     {
         _logger.Error($"MQ发送消费服务端失败 RoutingKey:{routingKey} Message:{message}", ex);
     }
 }
Exemple #4
0
        public IEnumerable <string> Get()
        {
            //var addShopCarRequest = new AddShopCarRequest { ProductID = 8, VersionID = 9 };
            ////string url = "http://localhost:7001/Account/MiUser/Register";
            ////var response = apiHelperService.PostAsync<RegisterResponse>(url, request).Result;
            ////string message = response.Message;

            //_eventBus.Publish("AddShopCar", addShopCarRequest);

            string url = $"{configuration["ServiceAddress:Service.Monitor"]}{configuration["MehtodName:Monitor.QueryRabbitMq.QueryRoutingKeyApiUrlAsync"]}";
            var    queryRoutingKeyApiUrlResponse = apiHelperService.PostAsync <QueryRoutingKeyApiUrlResponse>(url, new QueryRoutingKeyApiUrlRequest {
                RoutingKey = "AddShopCar"
            });

            if (queryRoutingKeyApiUrlResponse.Result != null && queryRoutingKeyApiUrlResponse.Result.ApiUrlList.Any())
            {
            }

            return(new string[] { "value1", "value2" });
        }
        public async Task <QueryStartProductResponse> QueryStartProduct(QueryStartProductRequest request)
        {
            string url = $"{configuration["ServiceAddress:Service.Picture"]}{configuration["MehtodName:Picture.QueryPicture.QueryStartProduct"]}";

            return(await apiHelperService.PostAsync <QueryStartProductResponse>(url, request));
        }
Exemple #6
0
        public async Task <SSOLoginResponse> SSOLogin(SSOLoginRequest request)
        {
            string url = $"{configuration["ServiceAddress:Service.Account"]}{configuration["MehtodName:Account.MiUser.SSOLogin"]}";

            return(await apiHelperService.PostAsync <SSOLoginResponse>(url, request));
        }
        public async Task <QueryRabbitMqRoutingKeyInfoResponse> QueryRabbitMqRoutingKeyInfoAsync(QueryRabbitMqRoutingKeyInfoRequest request)
        {
            string url = $"{configuration["ServiceAddress:Service.Monitor"]}{configuration["MehtodName:Monitor.QueryRabbitMq.QueryRabbitMqRoutingKeyInfoAsync"]}";

            return(await apiHelperService.PostAsync <QueryRabbitMqRoutingKeyInfoResponse>(url, request));
        }
Exemple #8
0
        public GetShopCarByUserNameResponse GetUserInfoByUserNameAsync(GetShopCarByUserNameRequest request)
        {
            string url = $"{configuration["ServiceAddress:Service.Account"]}{configuration["MehtodName:Account.MiUser.GetUserInfoByUserNameAsync"]}";

            return(apiHelperService.PostAsync <GetShopCarByUserNameResponse>(url, request).Result);
        }
        public async Task <GetShopListResponse> GetShopList(GetShopListRequest request)
        {
            string url = $"{configuration["ServiceAddress:Service.ShopCar"]}{configuration["MehtodName:ShopCar.ShopCarOperation.GetShopListAsync"]}";

            return(await apiHelperService.PostAsync <GetShopListResponse>(url, request));
        }