public void SetAppUp(IEurekaInstanceConfig instanceConfig, EurekaClientConfig config, ILoggerFactory factory) { this._logger.LogDebug("Start registering service instance..."); ApplicationInfoManager aim = this.InitializeApplicationInfoManager(instanceConfig); this.SetAppStatus(InstanceStatus.UP, aim); this._logger.LogDebug($"Service instance was registered (ip: {instanceConfig.IpAddress}, port: {instanceConfig.NonSecurePort}, sec-port: {instanceConfig.SecurePort})"); this._eurekaClient = this.InitializeEurekaClient(instanceConfig, config, factory); for (int i = 0; i < 120; i++) { try { IList <InstanceInfo> infoList = this._eurekaClient.GetInstanceById(instanceConfig.InstanceId); if (infoList != null && infoList.Count > 0) { this._logger.LogDebug("Service instance was online."); return; } Thread.Sleep(1000); } catch (Exception) { Thread.Sleep(1000); } } throw new ThriftyException($"Unable to connect to the eureka server (eureka server: {config.EurekaServerServiceUrls}), please check the swifty server configuration"); }
protected EurekaDiscoveryClientBase(EurekaClientOptions clientOptions, EurekaInstanceOptions instOptions, IEurekaHttpClient httpClient, IApplicationLifetime lifeCycle = null, ILoggerFactory logFactory = null) { if (clientOptions == null) { throw new ArgumentNullException(nameof(clientOptions)); } ClientConfig = clientOptions; InstConfig = instOptions; if (InstConfig == null) { DiscoveryManager.Instance.Initialize(ClientConfig, httpClient, logFactory); } else { ConfigureInstanceIfNeeded(InstConfig); DiscoveryManager.Instance.Initialize(ClientConfig, InstConfig, httpClient, logFactory); } if (lifeCycle != null) { lifeCycle.ApplicationStopping.Register(() => { ShutdownAsync(); }); } Client = DiscoveryManager.Instance.Client; }
//to be able to use by unit tests internal static ApplicationLifecycleController CreateInstance(IEurekaClient eureka) { ApplicationLifecycleController lifecycle = new ApplicationLifecycleController(); lifecycle.AppConfig = KaryonConfig.Current; IMetadataAdapter adapter = null; if (lifecycle.AppConfig.DataCenter == DataCenterType.Amazon) { Trace.TraceInformation("Collecting AWS EC2 instance metadata..."); adapter = new AmazonMetadataAdapter(); } else { Trace.TraceInformation("Using local machine instead of Amazon..."); adapter = new MyOwnMetadataAdapter(); } lifecycle.DataCenterMetadata = Task.Run(() => adapter.Collect()).Result; //setup Eureka client lifecycle.eureka = eureka; eureka.EurekaServiceUrl = lifecycle.AppConfig.EurekaServiceUrls[0]; eureka.ApplicationName = lifecycle.AppConfig.ApplicationName; eureka.ApplicationPort = lifecycle.AppConfig.ApplicationPort; eureka.ApplicationSecurePort = lifecycle.AppConfig.ApplicationSecurePort; return(lifecycle); }
/// <summary> /// 初始化Eureka客户端 /// </summary> /// <param name="instanceConfig">实例配置</param> /// <param name="config">服务发现注册客户端配置</param> /// <param name="loggerFactory">loggerfactory</param> /// <returns>服务发现注册eureka客户端</returns> IEurekaClient InitializeEurekaClient(IEurekaInstanceConfig instanceConfig, EurekaClientConfig config, ILoggerFactory loggerFactory = null) { this._loggerFactory = loggerFactory; if (this._eurekaClient == null) { lock (this) { if (DiscoveryManager.Instance.Client == null) { DiscoveryManager.Instance.Initialize(config, instanceConfig, loggerFactory); } this._eurekaClient = DiscoveryManager.Instance.Client; } } this._logger = loggerFactory?.CreateLogger <ThriftyRegistryService>() ?? (ILogger)NullLogger.Instance; return(this._eurekaClient); }
public static EurekaClientExecutor Wrap(IEurekaClient eurekaClient) { return(new EurekaClientExecutor(eurekaClient)); }
private EurekaClientExecutor(IEurekaClient eurekaClient) { this.EurekaClient = eurekaClient; }
public HeartbeatObserver(IEurekaClient eureka, DataCenterMetadata dcMetadata, IEnumerable <string> eurekaServiceUrls) { this.DataCenterMetadata = dcMetadata; this.eureka = eureka; this.EurekaServiceUrls = eurekaServiceUrls; }