public class DiscoveryClientNameResolver
extends io.grpc.NameResolver
DiscoveryClient. The ports are extracted from the gRPC_port metadata.io.grpc.NameResolver.Args, io.grpc.NameResolver.ConfigOrError, io.grpc.NameResolver.Factory, io.grpc.NameResolver.Listener, io.grpc.NameResolver.Listener2, io.grpc.NameResolver.ResolutionResult, io.grpc.NameResolver.ResolutionResultAttr, io.grpc.NameResolver.ServiceConfigParser| Constructor and Description |
|---|
DiscoveryClientNameResolver(String name,
org.springframework.cloud.client.discovery.DiscoveryClient client,
io.grpc.NameResolver.Args args,
io.grpc.internal.SharedResourceHolder.Resource<Executor> executorResource,
Consumer<DiscoveryClientNameResolver> shutdownHook)
Creates a new DiscoveryClientNameResolver.
|
| Modifier and Type | Method and Description |
|---|---|
protected List<org.springframework.cloud.client.ServiceInstance> |
discoverServers()
Discovers matching service instances.
|
protected io.grpc.Attributes |
getAttributes(org.springframework.cloud.client.ServiceInstance serviceInstance)
Gets the attributes from the service instance for later use in a load balancer.
|
protected int |
getGrpcPort(org.springframework.cloud.client.ServiceInstance instance)
Extracts the gRPC server port from the given service instance.
|
protected String |
getName()
Gets the name of the service to get the instances of.
|
String |
getServiceAuthority() |
protected boolean |
isActive()
Checks whether this resolver is active.
|
protected boolean |
needsToUpdateConnections(List<org.springframework.cloud.client.ServiceInstance> newInstanceList)
Checks whether this instance should update its connections.
|
void |
refresh() |
void |
refreshFromExternal()
Triggers a refresh on the listener from non-grpc threads.
|
void |
shutdown() |
void |
start(io.grpc.NameResolver.Listener2 listener) |
String |
toString() |
public DiscoveryClientNameResolver(String name, org.springframework.cloud.client.discovery.DiscoveryClient client, io.grpc.NameResolver.Args args, io.grpc.internal.SharedResourceHolder.Resource<Executor> executorResource, Consumer<DiscoveryClientNameResolver> shutdownHook)
name - The name of the service to look up.client - The client used to look up the service addresses.args - The name resolver args.executorResource - The executor resource.shutdownHook - The optional cleaner used during shutdown()protected final String getName()
protected final boolean isActive()
#start has been called, but not #shutdown().public final String getServiceAuthority()
getServiceAuthority in class io.grpc.NameResolverpublic void start(io.grpc.NameResolver.Listener2 listener)
start in class io.grpc.NameResolverpublic void refresh()
refresh in class io.grpc.NameResolverpublic void refreshFromExternal()
refresh()protected List<org.springframework.cloud.client.ServiceInstance> discoverServers()
protected int getGrpcPort(org.springframework.cloud.client.ServiceInstance instance)
instance - The instance to extract the port from.IllegalArgumentException - If the specified port definition couldn't be parsed.protected io.grpc.Attributes getAttributes(org.springframework.cloud.client.ServiceInstance serviceInstance)
serviceInstance - The service instance to get them from.protected boolean needsToUpdateConnections(List<org.springframework.cloud.client.ServiceInstance> newInstanceList)
newInstanceList - The new instances that should be compared to the stored ones.public void shutdown()
shutdown in class io.grpc.NameResolver