Table of Contents

Class RoundRobinLoadBalancer

Namespace
Steeltoe.Discovery.HttpClients.LoadBalancers
Assembly
Steeltoe.Discovery.HttpClients.dll

Returns service instances in round-robin fashion, optionally using distributed caching for determining the next instance.

public sealed class RoundRobinLoadBalancer : ILoadBalancer
Inheritance
RoundRobinLoadBalancer
Implements
Inherited Members

Constructors

RoundRobinLoadBalancer(ServiceInstancesResolver, IDistributedCache?, DistributedCacheEntryOptions?, ILogger<RoundRobinLoadBalancer>)

Initializes a new instance of the RoundRobinLoadBalancer class.

public RoundRobinLoadBalancer(ServiceInstancesResolver serviceInstancesResolver, IDistributedCache? distributedCache, DistributedCacheEntryOptions? cacheEntryOptions, ILogger<RoundRobinLoadBalancer> logger)

Parameters

serviceInstancesResolver ServiceInstancesResolver

Used to retrieve the available service instances.

distributedCache IDistributedCache

For caching the last-used instance.

cacheEntryOptions DistributedCacheEntryOptions

Configuration for distributedCache.

logger ILogger<RoundRobinLoadBalancer>

Used for internal logging. Pass Instance to disable logging.

RoundRobinLoadBalancer(ServiceInstancesResolver, ILogger<RoundRobinLoadBalancer>)

Initializes a new instance of the RoundRobinLoadBalancer class.

public RoundRobinLoadBalancer(ServiceInstancesResolver serviceInstancesResolver, ILogger<RoundRobinLoadBalancer> logger)

Parameters

serviceInstancesResolver ServiceInstancesResolver

Used to retrieve the available service instances.

logger ILogger<RoundRobinLoadBalancer>

Used for internal logging. Pass Instance to disable logging.

Methods

ResolveServiceInstanceAsync(Uri, CancellationToken)

Evaluates a URI for a hostname that can be resolved into a service instance.

public Task<Uri> ResolveServiceInstanceAsync(Uri requestUri, CancellationToken cancellationToken)

Parameters

requestUri Uri

A URI containing a service name that can be resolved into one or more service instances.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<Uri>

The original URI, with the scheme and service name replaced by the scheme, host and port of a service instance.

UpdateStatisticsAsync(Uri, Uri, TimeSpan?, Exception?, CancellationToken)

A mechanism for tracking statistics for service instances.

public Task UpdateStatisticsAsync(Uri requestUri, Uri serviceInstanceUri, TimeSpan? responseTime, Exception? exception, CancellationToken cancellationToken)

Parameters

requestUri Uri

The original request URI.

serviceInstanceUri Uri

The URI resolved by the load balancer.

responseTime TimeSpan?

The amount of time taken for a remote call to complete.

exception Exception

Any exception thrown during calls to a resolved service instance.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task