public class DiscoveryClient extends java.lang.Object implements LookupService
Eureka Client is responsible for a) Registering the instance with Eureka Server b) Renewalof the lease with Eureka Server c) Cancellation of the lease from Eureka Server during shutdown
d) Querying the list of services/instances registered with Eureka Server
Eureka Client needs a configured list of Eureka Server
URLs to talk to.These URLs are typically amazon elastic eips
which do not change. All of the functions defined above fail-over to other
URLs specified in the list in the case of failure.
| Modifier and Type | Class and Description |
|---|---|
static class |
DiscoveryClient.DiscoveryClientOptionalArgs |
static class |
DiscoveryClient.DiscoveryUrlType |
| Modifier and Type | Field and Description |
|---|---|
protected static EurekaClientConfig |
clientConfig |
| Constructor and Description |
|---|
DiscoveryClient(InstanceInfo myInfo,
EurekaClientConfig config) |
DiscoveryClient(InstanceInfo myInfo,
EurekaClientConfig config,
DiscoveryClient.DiscoveryClientOptionalArgs args) |
| Modifier and Type | Method and Description |
|---|---|
java.util.Set<java.lang.String> |
getAllKnownRegions() |
Application |
getApplication(java.lang.String appName)
Returns the corresponding
Application object which is basically a
container of all registered appName InstanceInfos. |
Applications |
getApplications()
Returns the
Applications object which is basically a container of
all currently registered Applications. |
Applications |
getApplications(java.lang.String serviceUrl)
Get all applications registered with a specific eureka service.
|
Applications |
getApplicationsForARegion(java.lang.String region) |
java.util.List<java.lang.String> |
getDiscoveryServiceUrls(java.lang.String zone) |
static java.util.Set<java.lang.String> |
getEC2DiscoveryUrlsFromZone(java.lang.String dnsName,
DiscoveryClient.DiscoveryUrlType type)
Get the list of EC2 URLs given the zone name.
|
static java.util.List<java.lang.String> |
getEurekaServiceUrlsFromConfig(java.lang.String instanceZone,
boolean preferSameZone)
Get the list of all eureka service urls from properties file for the
eureka client to talk to.
|
HealthCheckHandler |
getHealthCheckHandler() |
InstanceInfo.InstanceStatus |
getInstanceRemoteStatus() |
java.util.List<InstanceInfo> |
getInstancesById(java.lang.String id)
Returns the
List of InstanceInfos matching the the passed
in id. |
java.util.List<InstanceInfo> |
getInstancesByVipAddress(java.lang.String vipAddress,
boolean secure)
Gets the list of instances matching the given VIP Address.
|
java.util.List<InstanceInfo> |
getInstancesByVipAddress(java.lang.String vipAddress,
boolean secure,
java.lang.String region)
Gets the list of instances matching the given VIP Address in the passed region.
|
java.util.List<InstanceInfo> |
getInstancesByVipAddressAndAppName(java.lang.String vipAddress,
java.lang.String appName,
boolean secure)
Gets the list of instances matching the given VIP Address and the given
application name if both of them are not null.
|
InstanceInfo |
getNextServerFromEureka(java.lang.String virtualHostname,
boolean secure)
Gets the next possible server to process the requests from the registry
information received from eureka.
|
static java.lang.String |
getRegion()
Get the region that this particular instance is in.
|
java.util.List<java.lang.String> |
getServiceUrlsFromDNS(java.lang.String instanceZone,
boolean preferSameZone)
Get the list of all eureka service urls from DNS for the eureka client to
talk to.
|
static java.lang.String |
getZone(InstanceInfo myInfo)
Get the zone that a particular instance is in.
|
protected BackupRegistry |
newBackupRegistryInstance()
Deprecated.
Use injection to provide
BackupRegistry implementation. |
void |
registerHealthCheck(HealthCheckHandler healthCheckHandler) |
void |
registerHealthCheckCallback(HealthCheckCallback callback)
Deprecated.
Use
|
void |
shutdown()
Shuts down Eureka Client.
|
protected static EurekaClientConfig clientConfig
public DiscoveryClient(InstanceInfo myInfo, EurekaClientConfig config)
public DiscoveryClient(InstanceInfo myInfo, EurekaClientConfig config, DiscoveryClient.DiscoveryClientOptionalArgs args)
public Application getApplication(java.lang.String appName)
LookupServiceApplication object which is basically a
container of all registered appName InstanceInfos.getApplication in interface LookupServiceApplication or null if we couldn't locate any app of
the requested appNamepublic Applications getApplications()
LookupServiceApplications object which is basically a container of
all currently registered Applications.getApplications in interface LookupServiceApplicationspublic Applications getApplicationsForARegion(@Nullable java.lang.String region)
public java.util.Set<java.lang.String> getAllKnownRegions()
public java.util.List<InstanceInfo> getInstancesById(java.lang.String id)
LookupServiceList of InstanceInfos matching the the passed
in id. A single InstanceInfo can possibly be registered w/ more
than one ApplicationsgetInstancesById in interface LookupServiceList of InstanceInfos or
Collections.emptyList()@Deprecated public void registerHealthCheckCallback(HealthCheckCallback callback)
HealthCheckCallback with the eureka client.
Once registered, the eureka client will invoke the
HealthCheckCallback in intervals specified by
EurekaClientConfig.getInstanceInfoReplicationIntervalSeconds().callback - app specific healthcheck.public void registerHealthCheck(HealthCheckHandler healthCheckHandler)
public java.util.List<InstanceInfo> getInstancesByVipAddress(java.lang.String vipAddress, boolean secure)
vipAddress - - The VIP address to match the instances for.secure - - true if it is a secure vip address, false otherwiseInstanceInfo objects matching the criteriapublic java.util.List<InstanceInfo> getInstancesByVipAddress(java.lang.String vipAddress, boolean secure, @Nullable java.lang.String region)
vipAddress - - The VIP address to match the instances for.secure - - true if it is a secure vip address, false otherwiseregion - - region from which the instances are to be fetched. If null then local region is
assumed.InstanceInfo objects matching the criteria, empty list if not instances found.public java.util.List<InstanceInfo> getInstancesByVipAddressAndAppName(java.lang.String vipAddress, java.lang.String appName, boolean secure)
vipAddress - - The VIP address to match the instances for.appName - - The applicationName to match the instances for.secure - - true if it is a secure vip address, false otherwise.InstanceInfo objects matching the criteria.public InstanceInfo getNextServerFromEureka(java.lang.String virtualHostname, boolean secure)
LookupService
The next server is picked on a round-robin fashion.By default, this
method just returns the servers that are currently with
InstanceInfo.InstanceStatus.UP status. This configuration can be controlled by
overriding the EurekaClientConfig.shouldFilterOnlyUpInstances().
Note that in some cases (Eureka emergency mode situation), the instances
that are returned may not be unreachable, it is solely up to the client
at that point to timeout quickly and retry the next server.
getNextServerFromEureka in interface LookupServicevirtualHostname - the virtual host name that is associated to the servers.secure - indicates whether this is a HTTP or a HTTPS request - secure
means HTTPS.InstanceInfo information which contains the public
host name of the next server in line to process the request based
on the round-robin algorithm.public Applications getApplications(java.lang.String serviceUrl)
serviceUrl - - The string representation of the service url.public static java.util.List<java.lang.String> getEurekaServiceUrlsFromConfig(java.lang.String instanceZone,
boolean preferSameZone)
instanceZone - - The zone in which the client residespreferSameZone - - true if we have to prefer the same zone as the client, false
otherwise@PreDestroy public void shutdown()
public InstanceInfo.InstanceStatus getInstanceRemoteStatus()
public java.util.List<java.lang.String> getServiceUrlsFromDNS(java.lang.String instanceZone,
boolean preferSameZone)
instanceZone - - The zone in which the client resides.preferSameZone - - true if we have to prefer the same zone as the client, false
otherwise.public java.util.List<java.lang.String> getDiscoveryServiceUrls(java.lang.String zone)
public static java.lang.String getZone(InstanceInfo myInfo)
myInfo - - The InstanceInfo object of the instance.public static java.lang.String getRegion()
public static java.util.Set<java.lang.String> getEC2DiscoveryUrlsFromZone(java.lang.String dnsName,
DiscoveryClient.DiscoveryUrlType type)
dnsName - - The dns name of the zone-specific CNAMEtype - - CNAME or EIP that needs to be retrievedpublic HealthCheckHandler getHealthCheckHandler()
@Deprecated @Nullable protected BackupRegistry newBackupRegistryInstance() throws java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.InstantiationException
BackupRegistry implementation.java.lang.ClassNotFoundExceptionjava.lang.IllegalAccessExceptionjava.lang.InstantiationException