Table of Contents

Class EurekaDiscoveryClient

Namespace
Steeltoe.Discovery.Eureka
Assembly
Steeltoe.Discovery.Eureka.dll

A discovery client for Spring Cloud Eureka .

public sealed class EurekaDiscoveryClient : IDiscoveryClient
Inheritance
EurekaDiscoveryClient
Implements
Inherited Members

Constructors

EurekaDiscoveryClient(EurekaApplicationInfoManager, EurekaClient, IOptionsMonitor<EurekaClientOptions>, HealthCheckHandlerProvider, TimeProvider, ILogger<EurekaDiscoveryClient>)

public EurekaDiscoveryClient(EurekaApplicationInfoManager appInfoManager, EurekaClient eurekaClient, IOptionsMonitor<EurekaClientOptions> clientOptionsMonitor, HealthCheckHandlerProvider healthCheckHandlerProvider, TimeProvider timeProvider, ILogger<EurekaDiscoveryClient> logger)

Parameters

appInfoManager EurekaApplicationInfoManager
eurekaClient EurekaClient
clientOptionsMonitor IOptionsMonitor<EurekaClientOptions>
healthCheckHandlerProvider HealthCheckHandlerProvider
timeProvider TimeProvider
logger ILogger<EurekaDiscoveryClient>

Properties

Description

Gets a human-readable description of this discovery client.

public string Description { get; }

Property Value

string

Methods

GetInstancesAsync(string, CancellationToken)

Gets all service instances associated with the specified service ID from the discovery server.

public Task<IList<IServiceInstance>> GetInstancesAsync(string serviceId, CancellationToken cancellationToken)

Parameters

serviceId string

The ID of the service to lookup.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<IList<IServiceInstance>>

The list of remote service instances.

GetLocalServiceInstance()

Gets information used to register the local service instance (this app) to the discovery server.

public IServiceInstance GetLocalServiceInstance()

Returns

IServiceInstance

The service instance that represents this app, or null when unavailable.

GetServiceIdsAsync(CancellationToken)

Gets all registered service IDs from the discovery server.

public Task<ISet<string>> GetServiceIdsAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<ISet<string>>

The list of service IDs.

ShutdownAsync(CancellationToken)

Deregisters the local service (this app) from the discovery server.

public Task ShutdownAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task

Remarks

This method exists for two reasons, instead of just reusing IAsyncDisposable. The first reason is that this method enables cancellation. The second reason is more complicated. Deregistration typically requires to send an HTTP request to the discovery server. When using IHttpClientFactory, it requires the IoC container to obtain an HttpClient. But that fails when the container is being disposed. Deregistration must be performed earlier. That's why implementations should register DiscoveryClientHostedService in the IoC container, which is a hosted service that performs deregistration (by calling this method) when the app is terminating. At that time, the IoC container is still accessible.

Events

ApplicationsFetched

Occurs after applications have been fetched from Eureka.

public event EventHandler<ApplicationsFetchedEventArgs>? ApplicationsFetched

Event Type

EventHandler<ApplicationsFetchedEventArgs>