Table of Contents

Class ConfigurationDiscoveryClient

Namespace
Steeltoe.Discovery.Configuration
Assembly
Steeltoe.Discovery.Configuration.dll

A discovery client that reads service instances from app configuration.

public sealed class ConfigurationDiscoveryClient : IDiscoveryClient, IDisposable
Inheritance
ConfigurationDiscoveryClient
Implements
Inherited Members

Constructors

ConfigurationDiscoveryClient(IOptionsMonitor<ConfigurationDiscoveryOptions>)

public ConfigurationDiscoveryClient(IOptionsMonitor<ConfigurationDiscoveryOptions> optionsMonitor)

Parameters

optionsMonitor IOptionsMonitor<ConfigurationDiscoveryOptions>

Properties

Description

Gets a human-readable description of this discovery client.

public string Description { get; }

Property Value

string

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

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

InstancesFetched

Occurs when the configuration of service instances has been reloaded.

public event EventHandler<DiscoveryInstancesFetchedEventArgs>? InstancesFetched

Event Type

EventHandler<DiscoveryInstancesFetchedEventArgs>