Ejemplo n.º 1
0
        /// <summary>
        /// Using the Eureka configuration values provided in <paramref name="configuration"/> contact the Eureka server and
        /// return all the registered services. The Eureka client is shutdown after contacting the server.
        /// </summary>
        /// <param name="configuration">configuration values used for configuring the Eureka client</param>
        /// <param name="logFactory">optional log factory to use for logging</param>
        /// <returns>all registered services</returns>
        public static IList <string> GetServices(IConfiguration configuration, ILoggerFactory logFactory = null)
        {
            EurekaClientOptions config = ConfigureClientOptions(configuration);
            var client = GetLookupClient(config, logFactory);
            var result = client.GetServicesInternal();

            client.ShutdownAsync().GetAwaiter().GetResult();
            return(result);
        }
        internal static EurekaClientOptions ConfigureClientOptions(IConfiguration configuration)
        {
            var clientConfigsection = configuration.GetSection(EurekaClientOptions.EUREKA_CLIENT_CONFIGURATION_PREFIX);

            var clientOptions = new EurekaClientOptions();

            clientConfigsection.Bind(clientOptions);
            clientOptions.ShouldFetchRegistry      = true;
            clientOptions.ShouldRegisterWithEureka = false;
            return(clientOptions);
        }
 /// <summary>
 /// Using the Eureka configuration values provided in <paramref name="configuration"/> contact the Eureka server and
 /// return all the registered services. The Eureka client is shutdown after contacting the server.
 /// </summary>
 /// <param name="configuration">configuration values used for configuring the Eureka client</param>
 /// <param name="logFactory">optional log factory to use for logging</param>
 /// <returns>all registered services</returns>
 public static IList <string> GetServices(IConfiguration configuration, ILoggerFactory logFactory = null)
 {
     return(System.Threading.Tasks.Task.Run(() =>
     {
         EurekaClientOptions config = ConfigureClientOptions(configuration);
         var client = GetLookupClient(config, logFactory);
         var result = client.GetServices();
         client.ShutdownAsync().Wait();
         return result;
     }).Result);
 }
 public EurekaServerConfig(EurekaClientOptions options)
 {
     _options = options;
 }
Ejemplo n.º 5
0
        public static void UpdateConfiguration(IConfiguration config, EurekaServiceInfo si, EurekaClientOptions clientOptions)
        {
            if (clientOptions == null || si == null)
            {
                return;
            }

            var uri = si.Uri;

            if (!uri.EndsWith(EUREKA_URI_SUFFIX))
            {
                uri = uri + EUREKA_URI_SUFFIX;
            }

            clientOptions.EurekaServerServiceUrls = uri;
            clientOptions.AccessTokenUri          = si.TokenUri;
            clientOptions.ClientId     = si.ClientId;
            clientOptions.ClientSecret = si.ClientSecret;
        }
 internal static LookupClient GetLookupClient(EurekaClientOptions config, ILoggerFactory logFactory)
 {
     return(new LookupClient(config, null, logFactory));
 }
Ejemplo n.º 7
0
 public EurekaHealthConfig(EurekaClientOptions options)
 {
     _options = options;
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Update <see cref="EurekaClientOptions"/> with information from the runtime environment
        /// </summary>
        /// <param name="config">Application Configuration</param>
        /// <param name="si"><see cref="EurekaServiceInfo"/> for bound Eureka server(s)</param>
        /// <param name="clientOptions">Eureka client configuration (for interacting with the Eureka Server)</param>
        public static void UpdateConfiguration(IConfiguration config, EurekaServiceInfo si, EurekaClientOptions clientOptions)
        {
            if ((Platform.IsContainerized || Platform.IsCloudHosted) &&
                si == null &&
                clientOptions.EurekaServerServiceUrls.Contains(EurekaClientConfig.Default_ServerServiceUrl.TrimEnd('/')))
            {
                throw new InvalidOperationException($"Eureka URL {EurekaClientConfig.Default_ServerServiceUrl} is not valid in containerized or cloud environments. Please configure Eureka:Client:ServiceUrl with a non-localhost address or add a service binding.");
            }

            if (clientOptions == null || si == null)
            {
                return;
            }

            var uri = si.Uri;

            if (!uri.EndsWith(EUREKA_URI_SUFFIX))
            {
                uri += EUREKA_URI_SUFFIX;
            }

            clientOptions.EurekaServerServiceUrls = uri;
            clientOptions.AccessTokenUri          = si.TokenUri;
            clientOptions.ClientId     = si.ClientId;
            clientOptions.ClientSecret = si.ClientSecret;
        }