private void ValidateConfig(RegistrationCenter center) { ConsulRegistrationCenter consulCenter = center as ConsulRegistrationCenter; if (consulCenter == null) { throw new NullReferenceException("无法使用ConsulRegistrationCenter注册非consul的注册中心"); } if (consulCenter.Clusters == null || consulCenter.Clusters.Count == 0) { throw new Exception("未设置注册中心地址"); } }
/// <summary> /// 服务注册接口 /// </summary> /// <param name="registrationCenter">注册中心信息</param> /// <param name="waitConsulTime">等待consul操作的超时时间</param> public ThriftServiceRegistry(RegistrationCenter registrationCenter, TimeSpan waitConsulTime) { if (registrationCenter == null) { throw new ArgumentNullException(nameof(registrationCenter)); } if (waitConsulTime == TimeSpan.Zero) { throw new ArgumentException("Consul操作时间不能小于等于0"); } ValidateConfig(registrationCenter); _registrationCenter = registrationCenter; _waitConsulTime = waitConsulTime; _client = new ConsulClient(tmp => { tmp.Address = new Uri(_registrationCenter.Clusters.First()); }); }