Ejemplo n.º 1
0
        /// <summary>
        /// 长轮询通知任务
        /// </summary>
        /// <param name="apolloConfig"></param>
        /// <param name="serviceConfigs"></param>
        public LongPollingTask(ApolloConfig apolloConfig, ServiceConfigs serviceConfigs)
        {
            _apolloConfig = apolloConfig;

            _serviceConfigs = serviceConfigs;

            _httpHelper = new HttpHelper(_apolloConfig.Timeout, _apolloConfig.ReadTimeout);

            _getConfigTask = new ApolloServiceConfigTask(apolloConfig);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 开始
        /// </summary>
        public void Start()
        {
            try
            {
                if (_longPollingTask == null)
                {
                    _configConfirmTask = new ConfigConfirmTask(Config);

                    var serviceConfigs = _configConfirmTask.GetServices();

                    if (serviceConfigs != null && serviceConfigs.Any())
                    {
                        _apolloServiceConfigTask = new ApolloServiceConfigTask(Config);

                        foreach (var serviceConfig in serviceConfigs)
                        {
                            _apolloServiceConfigTask.GetConfig(_appIDs, serviceConfig, _cluster);
                        }
                    }
                    else
                    {
                        throw new Exception("获取配置服务 is Null or Empty!");
                    }

                    _longPollingTask          = new LongPollingTask(Config, serviceConfigs);
                    _longPollingTask.OnError += _longPollingTask_OnError;

                    _longPollingTask.Start(_appIDs, _cluster);
                }
            }
            catch (Exception ex)
            {
                OnError?.Invoke(new ApolloConfigException("Wenli.Config.ApolloClient 长轮询过程中出现异常,正在等待重试!", ex));

                Thread.Sleep(10 * 1000);

                Start();
            }
        }