@Singleton public class DiscoveryClient extends java.lang.Object implements EurekaClient
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
URL
s to talk to.These URL
s are typically amazon elastic eips
which do not change. All of the functions defined above fail-over to other
URL
s specified in the list in the case of failure.
Modifier and Type | Class and Description |
---|---|
static class |
DiscoveryClient.DiscoveryClientOptionalArgs |
class |
DiscoveryClient.Stats
Stats is used to track useful attributes of the DiscoveryClient.
|
Modifier and Type | Field and Description |
---|---|
protected EurekaClientConfig |
clientConfig |
static java.lang.String |
HTTP_X_DISCOVERY_ALLOW_REDIRECT |
protected EurekaTransportConfig |
transportConfig |
Constructor and Description |
---|
DiscoveryClient(ApplicationInfoManager applicationInfoManager,
EurekaClientConfig config) |
DiscoveryClient(ApplicationInfoManager applicationInfoManager,
EurekaClientConfig config,
AbstractDiscoveryClientOptionalArgs args) |
DiscoveryClient(ApplicationInfoManager applicationInfoManager,
EurekaClientConfig config,
AbstractDiscoveryClientOptionalArgs args,
EndpointRandomizer randomizer) |
DiscoveryClient(ApplicationInfoManager applicationInfoManager,
EurekaClientConfig config,
DiscoveryClient.DiscoveryClientOptionalArgs args)
Deprecated.
use the version that take
AbstractDiscoveryClientOptionalArgs instead |
DiscoveryClient(InstanceInfo myInfo,
EurekaClientConfig config)
Deprecated.
use constructor that takes ApplicationInfoManager instead of InstanceInfo directly
|
DiscoveryClient(InstanceInfo myInfo,
EurekaClientConfig config,
AbstractDiscoveryClientOptionalArgs args)
Deprecated.
use constructor that takes ApplicationInfoManager instead of InstanceInfo directly
|
DiscoveryClient(InstanceInfo myInfo,
EurekaClientConfig config,
DiscoveryClient.DiscoveryClientOptionalArgs args)
Deprecated.
use constructor that takes ApplicationInfoManager instead of InstanceInfo directly
|
Modifier and Type | Method and Description |
---|---|
protected void |
fireEvent(EurekaEvent event)
Send the given event on the EventBus if one is available
|
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 InstanceInfo s. |
ApplicationInfoManager |
getApplicationInfoManager() |
Applications |
getApplications()
Returns the
Applications object which is basically a container of
all currently registered Application s. |
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)
Deprecated.
see replacement in
EndpointUtils |
static java.util.Set<java.lang.String> |
getEC2DiscoveryUrlsFromZone(java.lang.String dnsName,
EndpointUtils.DiscoveryUrlType type)
Deprecated.
see replacement in
EndpointUtils
Get the list of EC2 URLs given the zone name. |
EurekaClientConfig |
getEurekaClientConfig() |
static java.util.List<java.lang.String> |
getEurekaServiceUrlsFromConfig(java.lang.String instanceZone,
boolean preferSameZone)
Deprecated.
use
getServiceUrlsFromConfig(String, boolean) instead. |
HealthCheckHandler |
getHealthCheckHandler() |
InstanceInfo.InstanceStatus |
getInstanceRemoteStatus() |
java.util.List<InstanceInfo> |
getInstancesById(java.lang.String id)
Returns the
List of InstanceInfo s 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.
|
long |
getLastSuccessfulHeartbeatTimePeriod() |
long |
getLastSuccessfulRegistryFetchTimePeriod() |
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()
Deprecated.
see replacement in
EndpointUtils
Get the region that this particular instance is in. |
java.util.List<java.lang.String> |
getServiceUrlsFromConfig(java.lang.String instanceZone,
boolean preferSameZone)
Deprecated.
see replacement in
EndpointUtils
Get the list of all eureka service urls from properties file for the eureka client to talk to. |
java.util.List<java.lang.String> |
getServiceUrlsFromDNS(java.lang.String instanceZone,
boolean preferSameZone)
Deprecated.
see replacement in
EndpointUtils
Get the list of all eureka service urls from DNS for the eureka client to
talk to. The client picks up the service url from its zone and then fails over to
other zones randomly. If there are multiple servers in the same zone, the client once
again picks one randomly. This way the traffic will be distributed in the case of failures. |
DiscoveryClient.Stats |
getStats()
Gets stats for the DiscoveryClient.
|
static java.lang.String |
getZone(InstanceInfo myInfo)
Deprecated.
see
InstanceInfo.getZone(String[], com.netflix.appinfo.InstanceInfo)
Get the zone that a particular instance is in. |
int |
localRegistrySize() |
protected BackupRegistry |
newBackupRegistryInstance()
Deprecated.
Use injection to provide
BackupRegistry implementation. |
protected void |
onCacheRefreshed()
Invoked every time the local registry cache is refreshed (whether changes have
been detected or not).
|
protected void |
onRemoteStatusChanged(InstanceInfo.InstanceStatus oldStatus,
InstanceInfo.InstanceStatus newStatus)
Invoked when the remote status of this client has changed.
|
void |
registerEventListener(EurekaEventListener eventListener)
Register
EurekaEventListener with the eureka client. |
void |
registerHealthCheck(HealthCheckHandler healthCheckHandler)
Register
HealthCheckHandler with the eureka client. |
void |
registerHealthCheckCallback(HealthCheckCallback callback)
Deprecated.
Use
|
void |
shutdown()
Shuts down Eureka Client.
|
boolean |
unregisterEventListener(EurekaEventListener eventListener)
Unregister a
EurekaEventListener previous registered with EurekaClient.registerEventListener(com.netflix.discovery.EurekaEventListener)
or injected into the constructor of DiscoveryClient |
public static final java.lang.String HTTP_X_DISCOVERY_ALLOW_REDIRECT
protected final EurekaClientConfig clientConfig
protected final EurekaTransportConfig transportConfig
@Deprecated public DiscoveryClient(InstanceInfo myInfo, EurekaClientConfig config)
@Deprecated public DiscoveryClient(InstanceInfo myInfo, EurekaClientConfig config, DiscoveryClient.DiscoveryClientOptionalArgs args)
@Deprecated public DiscoveryClient(InstanceInfo myInfo, EurekaClientConfig config, AbstractDiscoveryClientOptionalArgs args)
public DiscoveryClient(ApplicationInfoManager applicationInfoManager, EurekaClientConfig config)
@Deprecated public DiscoveryClient(ApplicationInfoManager applicationInfoManager, EurekaClientConfig config, DiscoveryClient.DiscoveryClientOptionalArgs args)
AbstractDiscoveryClientOptionalArgs
insteadpublic DiscoveryClient(ApplicationInfoManager applicationInfoManager, EurekaClientConfig config, AbstractDiscoveryClientOptionalArgs args)
public DiscoveryClient(ApplicationInfoManager applicationInfoManager, EurekaClientConfig config, AbstractDiscoveryClientOptionalArgs args, EndpointRandomizer randomizer)
public EurekaClientConfig getEurekaClientConfig()
getEurekaClientConfig
in interface EurekaClient
public ApplicationInfoManager getApplicationInfoManager()
getApplicationInfoManager
in interface EurekaClient
public Application getApplication(java.lang.String appName)
LookupService
Application
object which is basically a
container of all registered appName
InstanceInfo
s.getApplication
in interface LookupService
Application
or null if we couldn't locate any app of
the requested appNamepublic Applications getApplications()
LookupService
Applications
object which is basically a container of
all currently registered Application
s.getApplications
in interface LookupService
Applications
public Applications getApplicationsForARegion(@Nullable java.lang.String region)
getApplicationsForARegion
in interface EurekaClient
region
- the region that the Applications reside inApplications
for the matching region. a Null value
is treated as the local region.public java.util.Set<java.lang.String> getAllKnownRegions()
getAllKnownRegions
in interface EurekaClient
public java.util.List<InstanceInfo> getInstancesById(java.lang.String id)
LookupService
List
of InstanceInfo
s matching the the passed
in id. A single InstanceInfo
can possibly be registered w/ more
than one Application
sgetInstancesById
in interface LookupService
List
of InstanceInfo
s 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()
.registerHealthCheckCallback
in interface EurekaClient
callback
- app specific healthcheck.public void registerHealthCheck(HealthCheckHandler healthCheckHandler)
EurekaClient
HealthCheckHandler
with the eureka client.
Once registered, the eureka client will first make an onDemand update of the
registering instanceInfo by calling the newly registered healthcheck handler,
and subsequently invoke the HealthCheckHandler
in intervals specified
by EurekaClientConfig.getInstanceInfoReplicationIntervalSeconds()
.registerHealthCheck
in interface EurekaClient
healthCheckHandler
- app specific healthcheck handler.public void registerEventListener(EurekaEventListener eventListener)
EurekaClient
EurekaEventListener
with the eureka client.
Once registered, the eureka client will invoke EurekaEventListener.onEvent(com.netflix.discovery.EurekaEvent)
whenever there is a change in eureka client's internal state. Use this instead of
polling the client for changes.
EurekaEventListener.onEvent(com.netflix.discovery.EurekaEvent)
is called from the context of an internal thread
and must therefore return as quickly as possible without blocking.registerEventListener
in interface EurekaClient
public boolean unregisterEventListener(EurekaEventListener eventListener)
EurekaClient
EurekaEventListener
previous registered with EurekaClient.registerEventListener(com.netflix.discovery.EurekaEventListener)
or injected into the constructor of DiscoveryClient
unregisterEventListener
in interface EurekaClient
public java.util.List<InstanceInfo> getInstancesByVipAddress(java.lang.String vipAddress, boolean secure)
getInstancesByVipAddress
in interface EurekaClient
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)
getInstancesByVipAddress
in interface EurekaClient
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)
getInstancesByVipAddressAndAppName
in interface EurekaClient
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 LookupService
virtualHostname
- 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)
getApplications
in interface EurekaClient
serviceUrl
- - The string representation of the service url.@Deprecated public java.util.List<java.lang.String> getServiceUrlsFromConfig(java.lang.String instanceZone, boolean preferSameZone)
EndpointUtils
Get the list of all eureka service urls from properties file for the eureka client to talk to.getServiceUrlsFromConfig
in interface EurekaClient
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()
shutdown
in interface EurekaClient
public InstanceInfo.InstanceStatus getInstanceRemoteStatus()
getInstanceRemoteStatus
in interface EurekaClient
@Deprecated public java.util.List<java.lang.String> getServiceUrlsFromDNS(java.lang.String instanceZone, boolean preferSameZone)
EndpointUtils
Get the list of all eureka service urls from DNS for the eureka client to
talk to. The client picks up the service url from its zone and then fails over to
other zones randomly. If there are multiple servers in the same zone, the client once
again picks one randomly. This way the traffic will be distributed in the case of failures.getServiceUrlsFromDNS
in interface EurekaClient
instanceZone
- The zone in which the client resides.preferSameZone
- true if we have to prefer the same zone as the client, false otherwise.@Deprecated public java.util.List<java.lang.String> getDiscoveryServiceUrls(java.lang.String zone)
EndpointUtils
getDiscoveryServiceUrls
in interface EurekaClient
zone
- the zone in which the client resides@Deprecated public static java.util.Set<java.lang.String> getEC2DiscoveryUrlsFromZone(java.lang.String dnsName, EndpointUtils.DiscoveryUrlType type)
EndpointUtils
Get the list of EC2 URLs given the zone name.dnsName
- The dns name of the zone-specific CNAMEtype
- CNAME or EIP that needs to be retrievedpublic HealthCheckHandler getHealthCheckHandler()
getHealthCheckHandler
in interface EurekaClient
@Deprecated @Nullable protected BackupRegistry newBackupRegistryInstance() throws java.lang.ClassNotFoundException, java.lang.IllegalAccessException, java.lang.InstantiationException
BackupRegistry
implementation.java.lang.ClassNotFoundException
java.lang.IllegalAccessException
java.lang.InstantiationException
protected void onRemoteStatusChanged(InstanceInfo.InstanceStatus oldStatus, InstanceInfo.InstanceStatus newStatus)
oldStatus
- the previous remote InstanceInfo.InstanceStatus
newStatus
- the new remote InstanceInfo.InstanceStatus
protected void onCacheRefreshed()
protected void fireEvent(EurekaEvent event)
event
- the event to send on the eventBus@Deprecated public static java.lang.String getZone(InstanceInfo myInfo)
InstanceInfo.getZone(String[], com.netflix.appinfo.InstanceInfo)
Get the zone that a particular instance is in.myInfo
- - The InstanceInfo object of the instance.@Deprecated public static java.lang.String getRegion()
EndpointUtils
Get the region that this particular instance is in.@Deprecated public static java.util.List<java.lang.String> getEurekaServiceUrlsFromConfig(java.lang.String instanceZone, boolean preferSameZone)
getServiceUrlsFromConfig(String, boolean)
instead.public long getLastSuccessfulHeartbeatTimePeriod()
public long getLastSuccessfulRegistryFetchTimePeriod()
@Monitor(name="eurekaClient.registry.localRegistrySize", description="Count of instances in the local registry", type=GAUGE) public int localRegistrySize()
public DiscoveryClient.Stats getStats()