Пример #1
0
        static HystrixCommandBase()
        {
            int num;

            CommandComponentsCollection = new ConcurrentDictionary <string, CommandComponents>(StringComparer.InvariantCultureIgnoreCase);
            CommandCount                = new AtomicInteger();
            ExecutionSemaphores         = new ConcurrentDictionary <string, IsolationSemaphore>(StringComparer.InvariantCultureIgnoreCase);
            FallbackExecutionSemaphores = new ConcurrentDictionary <string, IsolationSemaphore>(StringComparer.InvariantCultureIgnoreCase);
            TypePredefinedKeyMappings   = new ConcurrentDictionary <Type, string>();
            HystrixAppName              = ConfigurationManager.AppSettings["CHystrix.AppName"];
            if (string.IsNullOrWhiteSpace(HystrixAppName))
            {
                if (string.IsNullOrWhiteSpace(CommonUtils.AppId))
                {
                    string message = "Either CHystrix.AppName Or AppId must be configured.";
                    CommonUtils.Log.Log(LogLevelEnum.Fatal, message, new Dictionary <string, string>().AddLogTagData("FXD303000"));
                    HystrixAppName = "HystrixApp";
                }
                else
                {
                    HystrixAppName = CommonUtils.AppId;
                }
            }
            else
            {
                HystrixAppName = HystrixAppName.Trim();
                if (!HystrixAppName.IsValidHystrixName())
                {
                    string str2 = "HystrixAppName setting is invalid: " + HystrixAppName + @". Name pattern is: ^[a-zA-Z0-9][a-zA-Z0-9\-_.]*[a-zA-Z0-9]$";
                    CommonUtils.Log.Log(LogLevelEnum.Fatal, str2, new Dictionary <string, string>().AddLogTagData("FXD303001"));
                    throw new ArgumentException(str2);
                }
                if (CommonUtils.AppId != null)
                {
                    HystrixAppName = CommonUtils.AppId + "-" + HystrixAppName;
                }
            }
            HystrixVersion = typeof(HystrixCommandBase).Assembly.GetName().Version.ToString();
            if (!int.TryParse(ConfigurationManager.AppSettings["CHystrix.MaxCommandCount"], out num) || (num <= 0))
            {
                num = 0x2710;
            }
            MaxCommandCount  = num;
            ConfigServiceUrl = ConfigurationManager.AppSettings["CHystrix.ConfigServiceUrl"];
            if (string.IsNullOrWhiteSpace(ConfigServiceUrl))
            {
                ConfigServiceUrl = null;
            }
            else
            {
                ConfigServiceUrl = ConfigServiceUrl.Trim();
            }
            RegistryServiceUrl = ConfigurationManager.AppSettings["CHystrix.RegistryServiceUrl"];
            if (string.IsNullOrWhiteSpace(RegistryServiceUrl))
            {
                RegistryServiceUrl = null;
            }
            else
            {
                RegistryServiceUrl = RegistryServiceUrl.Trim();
            }
            if (!string.IsNullOrWhiteSpace(HystrixAppName))
            {
                HystrixConfigSyncManager.Start();
                CommandConfigSyncManager.Start();
                MetricsReporter.Start();
                SelfRegistrationManager.Start();
            }
        }
Пример #2
0
        static HystrixCommandBase()
        {
            HystrixAppName = ConfigurationManager.AppSettings[HystrixAppNameSettingKey];
            if (string.IsNullOrWhiteSpace(HystrixAppName))
            {
                if (string.IsNullOrWhiteSpace(CommonUtils.AppId))
                {
                    string message = "Either CHystrix.AppName Or AppId must be configured.";
                    CommonUtils.Log.Log(LogLevelEnum.Fatal, message, new Dictionary <string, string>().AddLogTagData("FXD303000"));
                    HystrixAppName = DefaultAppName;
                }
                else
                {
                    HystrixAppName = CommonUtils.AppId;
                }
            }
            else
            {
                HystrixAppName = HystrixAppName.Trim();
                if (!HystrixAppName.IsValidHystrixName())
                {
                    string message = "HystrixAppName setting is invalid: " + HystrixAppName + ". Name pattern is: " + CommonUtils.HystrixNamePattern;
                    CommonUtils.Log.Log(LogLevelEnum.Fatal, message, new Dictionary <string, string>().AddLogTagData("FXD303001"));
                    throw new ArgumentException(message);
                }

                if (CommonUtils.AppId != null)
                {
                    HystrixAppName = CommonUtils.AppId + "-" + HystrixAppName;
                }
            }

            HystrixVersion = typeof(HystrixCommandBase).Assembly.GetName().Version.ToString();

            int maxCommandCount;

            if (!int.TryParse(ConfigurationManager.AppSettings[HystrixMaxCommandCountSettingKey], out maxCommandCount) || maxCommandCount <= 0)
            {
                maxCommandCount = DefaultMaxCommandCount;
            }
            MaxCommandCount = maxCommandCount;

            ConfigServiceUrl = ConfigurationManager.AppSettings[HystrixConfigServiceUrlSettingKey];
            if (string.IsNullOrWhiteSpace(ConfigServiceUrl))
            {
                ConfigServiceUrl = null;
            }
            else
            {
                ConfigServiceUrl = ConfigServiceUrl.Trim();
            }

            RegistryServiceUrl = ConfigurationManager.AppSettings[HystrixRegistryServiceUrlSettingKey];
            if (string.IsNullOrWhiteSpace(RegistryServiceUrl))
            {
                RegistryServiceUrl = null;
            }
            else
            {
                RegistryServiceUrl = RegistryServiceUrl.Trim();
            }

            if (!string.IsNullOrWhiteSpace(HystrixAppName))
            {
                HystrixConfigSyncManager.Start();
                CommandConfigSyncManager.Start();
                MetricsReporter.Start();
                SelfRegistrationManager.Start();
            }
        }