Class RandomLoadBalancer
- Namespace
- Steeltoe.Discovery.HttpClients.LoadBalancers
- Assembly
- Steeltoe.Discovery.HttpClients.dll
Returns random service instances.
public sealed class RandomLoadBalancer : ILoadBalancer
- Inheritance
-
RandomLoadBalancer
- Implements
- Inherited Members
Constructors
RandomLoadBalancer(ServiceInstancesResolver, ILogger<RandomLoadBalancer>)
Initializes a new instance of the RandomLoadBalancer class.
public RandomLoadBalancer(ServiceInstancesResolver serviceInstancesResolver, ILogger<RandomLoadBalancer> logger)
Parameters
serviceInstancesResolverServiceInstancesResolverUsed to retrieve the available service instances.
loggerILogger<RandomLoadBalancer>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
requestUriUriA URI containing a service name that can be resolved into one or more service instances.
cancellationTokenCancellationTokenThe 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
requestUriUriThe original request URI.
serviceInstanceUriUriThe URI resolved by the load balancer.
responseTimeTimeSpan?The amount of time taken for a remote call to complete.
exceptionExceptionAny exception thrown during calls to a resolved service instance.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.