Class RoundRobinLoadBalancer
Returns service instances in round-robin fashion, optionally using distributed caching for determining the next instance.
Inheritance
Implements
Namespace: Steeltoe.Discovery.HttpClients.LoadBalancers
Assembly: Steeltoe.Discovery.HttpClients.dll
Syntax
public sealed class RoundRobinLoadBalancer : object, ILoadBalancer
Constructors
| Edit this page View SourceRoundRobinLoadBalancer(ServiceInstancesResolver, ILogger<RoundRobinLoadBalancer>)
Initializes a new instance of the RoundRobinLoadBalancer class.
Declaration
public RoundRobinLoadBalancer(ServiceInstancesResolver serviceInstancesResolver, ILogger<RoundRobinLoadBalancer> logger)
Parameters
Type | Name | Description |
---|---|---|
ServiceInstancesResolver | serviceInstancesResolver | Used to retrieve the available service instances. |
ILogger<RoundRobinLoadBalancer> | logger | Used for internal logging. Pass |
RoundRobinLoadBalancer(ServiceInstancesResolver, Nullable<IDistributedCache>, Nullable<DistributedCacheEntryOptions>, ILogger<RoundRobinLoadBalancer>)
Initializes a new instance of the RoundRobinLoadBalancer class.
Declaration
public RoundRobinLoadBalancer(ServiceInstancesResolver serviceInstancesResolver, IDistributedCache? distributedCache, DistributedCacheEntryOptions? cacheEntryOptions, ILogger<RoundRobinLoadBalancer> logger)
Parameters
Type | Name | Description |
---|---|---|
ServiceInstancesResolver | serviceInstancesResolver | Used to retrieve the available service instances. |
System.Nullable<IDistributedCache> | distributedCache | For caching the last-used instance. |
System.Nullable<DistributedCacheEntryOptions> | cacheEntryOptions | Configuration for |
ILogger<RoundRobinLoadBalancer> | logger | Used for internal logging. Pass |
Methods
| Edit this page View SourceResolveServiceInstanceAsync(Uri, CancellationToken)
Evaluates a URI for a hostname that can be resolved into a service instance.
Declaration
public async Task<Uri> ResolveServiceInstanceAsync(Uri requestUri, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
Uri | requestUri | 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
Type | Description |
---|---|
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, Nullable<TimeSpan>, Nullable<Exception>, CancellationToken)
A mechanism for tracking statistics for service instances.
Declaration
public Task UpdateStatisticsAsync(Uri requestUri, Uri serviceInstanceUri, TimeSpan? responseTime, Exception? exception, CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
Uri | requestUri | The original request URI. |
Uri | serviceInstanceUri | The URI resolved by the load balancer. |
System.Nullable<TimeSpan> | responseTime | The amount of time taken for a remote call to complete. |
System.Nullable<Exception> | exception | Any exception thrown during calls to a resolved service instance. |
CancellationToken | cancellationToken | The token to monitor for cancellation requests. |
Returns
Type | Description |
---|---|
Task |