Пример #1
0
        public ConfigServiceLocator(HttpUtil httpUtil, IApolloOptions configUtil)
        {
            _httpUtil       = httpUtil;
            _options        = configUtil;
            _configServices = new ThreadSafe.AtomicReference <IList <ServiceDto> >(new List <ServiceDto>());

            _timer = new Timer(SchedulePeriodicRefresh, null, 0, _options.RefreshInterval);
        }
 private static IList <ServiceDto>?GetCustomizedConfigService(IApolloOptions configUtil) =>
 configUtil.ConfigServer?
 .Select(configServiceUrl => new ServiceDto
 {
     HomepageUrl = configServiceUrl.Trim(),
     InstanceId  = configServiceUrl.Trim(),
     AppName     = ConfigConsts.ConfigService
 })
 .ToArray();
        public LocalFileConfigRepository(string @namespace,
                                         IApolloOptions configUtil,
                                         IConfigRepository upstream = null) : base(@namespace)
        {
            _upstream = upstream;
            _options  = configUtil;

            PrepareConfigCacheDir();
        }
    public LocalFileConfigRepository(string @namespace,
                                     IApolloOptions configUtil,
                                     IConfigRepository?upstream = null) : base(@namespace)
    {
        _upstream = upstream;
        _options  = configUtil;

        var ext = Path.GetExtension(@namespace);

        if (ext is { Length : > 1 } && Enum.TryParse(ext.Substring(1), true, out ConfigFileFormat format))
    private readonly ConcurrentDictionary <string, ApolloNotificationMessages> _remoteNotificationMessages; //namespaceName -> watchedKey -> notificationId

    public RemoteConfigLongPollService(ConfigServiceLocator serviceLocator, HttpUtil httpUtil, IApolloOptions configUtil)
    {
        _serviceLocator = serviceLocator;
        _httpUtil       = httpUtil;
        _options        = configUtil;
        _longPollFailSchedulePolicyInSecond = new ExponentialSchedulePolicy(1, 120);    //in second
        _longPollSuccessSchedulePolicyInMs  = new ExponentialSchedulePolicy(100, 1000); //in millisecond
        _longPollNamespaces         = new ConcurrentDictionary <string, ISet <RemoteConfigRepository> >();
        _notifications              = new ConcurrentDictionary <string, long?>();
        _remoteNotificationMessages = new ConcurrentDictionary <string, ApolloNotificationMessages>();
    }
Пример #6
0
        public RemoteConfigRepository(string @namespace,
                                      IApolloOptions configUtil,
                                      HttpUtil httpUtil,
                                      ConfigServiceLocator serviceLocator,
                                      RemoteConfigLongPollService remoteConfigLongPollService) : base(@namespace)
        {
            _options        = configUtil;
            _httpUtil       = httpUtil;
            _serviceLocator = serviceLocator;
            _remoteConfigLongPollService = remoteConfigLongPollService;

            _timer = new Timer(SchedulePeriodicRefresh);
        }
    public ConfigServiceLocator(HttpUtil httpUtil, IApolloOptions configUtil)
    {
        _httpUtil = httpUtil;
        _options  = configUtil;

        var serviceDtos = GetCustomizedConfigService(configUtil);

        if (serviceDtos == null || serviceDtos.Count < 1)
        {
            _timer = new Timer(SchedulePeriodicRefresh, null, 0, _options.RefreshInterval);
        }
        else
        {
            _configServices = serviceDtos;
        }
    }
        public LocalFileConfigRepository(string @namespace,
                                         IApolloOptions configUtil,
                                         IConfigRepository?upstream = null) : base(@namespace)
        {
            _upstream = upstream;
            _options  = configUtil;

            var ext = Path.GetExtension(@namespace);

            if (ext != null && ext.Length > 1 && Enum.TryParse(ext.Substring(1), true, out ConfigFileFormat format))
            {
                Format = format;
            }

            PrepareConfigCacheDir();
        }
Пример #9
0
 public HttpUtil(IApolloOptions options) => _options = options;
Пример #10
0
        public static IApolloConfigurationBuilder AddApollo(this IConfigurationBuilder builder, IApolloOptions options)
        {
            var repositoryFactory = new ConfigRepositoryFactory(options ?? throw new ArgumentNullException(nameof(options)));

#pragma warning disable 618
            ApolloConfigurationManager.SetApolloOptions(repositoryFactory);
#pragma warning restore 618
            return(new ApolloConfigurationBuilder(builder, repositoryFactory));
        }
Пример #11
0
        public HttpUtil(IApolloOptions options)
        {
            _options = options;

            _httpMessageHandler = _options.HttpMessageHandlerFactory == null ? new HttpClientHandler() : _options.HttpMessageHandlerFactory();
        }
        public static IApolloConfigurationBuilder AddApollo(this IConfigurationBuilder builder, IApolloOptions options)
        {
            var repositoryFactory = new ConfigRepositoryFactory(options ?? throw new ArgumentNullException(nameof(options)));

            ApolloConfigurationManagerHelper.SetApolloOptions(repositoryFactory);

            var acb = new ApolloConfigurationBuilder(builder, repositoryFactory);

            if (options is ApolloOptions {
                Namespaces : { }
            } ao)
            {
                foreach (var ns in ao.Namespaces)
                {
                    acb.AddNamespace(ns);
                }
            }

            return(acb);
        }
 public ConfigRepositoryFactory(IApolloOptions options, HttpUtil?httpUtil = null)
 {
     _options  = options;
     _httpUtil = httpUtil ?? new HttpUtil(options);
 }
        public static IApolloConfigurationBuilder AddApollo(this IConfigurationBuilder builder, IApolloOptions options)
        {
            if (options is ApolloOptions ao)
            {
                ao.InitCluster();
            }

            var repositoryFactory = new ConfigRepositoryFactory(options ?? throw new ArgumentNullException(nameof(options)));

            ApolloConfigurationManager.SetApolloOptions(repositoryFactory);

            return(new ApolloConfigurationBuilder(builder, repositoryFactory));
        }
Пример #15
0
 public ConfigRepositoryFactory(IApolloOptions options) => Options = options;