Class DiscoveryClient

  • All Implemented Interfaces:
    EurekaClient, LookupService

    @Singleton
    public class DiscoveryClient
    extends java.lang.Object
    implements EurekaClient
    The class that is instrumental for interactions with Eureka Server.

    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.

    • Method Detail

      • getApplicationsForARegion

        public Applications getApplicationsForARegion​(@Nullable
                                                      java.lang.String region)
        Specified by:
        getApplicationsForARegion in interface EurekaClient
        Parameters:
        region - the region that the Applications reside in
        Returns:
        an Applications for the matching region. a Null value is treated as the local region.
      • getAllKnownRegions

        public java.util.Set<java.lang.String> getAllKnownRegions()
        Specified by:
        getAllKnownRegions in interface EurekaClient
        Returns:
        in String form all regions (local + remote) that can be accessed by this client
      • getInstancesByVipAddress

        public java.util.List<InstanceInfo> getInstancesByVipAddress​(java.lang.String vipAddress,
                                                                     boolean secure)
        Gets the list of instances matching the given VIP Address.
        Specified by:
        getInstancesByVipAddress in interface EurekaClient
        Parameters:
        vipAddress - - The VIP address to match the instances for.
        secure - - true if it is a secure vip address, false otherwise
        Returns:
        - The list of InstanceInfo objects matching the criteria
      • getInstancesByVipAddress

        public java.util.List<InstanceInfo> getInstancesByVipAddress​(java.lang.String vipAddress,
                                                                     boolean secure,
                                                                     @Nullable
                                                                     java.lang.String region)
        Gets the list of instances matching the given VIP Address in the passed region.
        Specified by:
        getInstancesByVipAddress in interface EurekaClient
        Parameters:
        vipAddress - - The VIP address to match the instances for.
        secure - - true if it is a secure vip address, false otherwise
        region - - region from which the instances are to be fetched. If null then local region is assumed.
        Returns:
        - The list of InstanceInfo objects matching the criteria, empty list if not instances found.
      • getInstancesByVipAddressAndAppName

        public 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. If one of them is null, then that criterion is completely ignored for matching instances.
        Specified by:
        getInstancesByVipAddressAndAppName in interface EurekaClient
        Parameters:
        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.
        Returns:
        - The list of InstanceInfo objects matching the criteria.
      • getNextServerFromEureka

        public InstanceInfo getNextServerFromEureka​(java.lang.String virtualHostname,
                                                    boolean secure)
        Description copied from interface: LookupService
        Gets the next possible server to process the requests from the registry information received from eureka.

        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.

        Specified by:
        getNextServerFromEureka in interface LookupService
        Parameters:
        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.
        Returns:
        the InstanceInfo information which contains the public host name of the next server in line to process the request based on the round-robin algorithm.
      • getApplications

        public Applications getApplications​(java.lang.String serviceUrl)
        Get all applications registered with a specific eureka service.
        Specified by:
        getApplications in interface EurekaClient
        Parameters:
        serviceUrl - - The string representation of the service url.
        Returns:
        - The registry information containing all applications.
      • getServiceUrlsFromConfig

        @Deprecated
        public 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.
        Specified by:
        getServiceUrlsFromConfig in interface EurekaClient
        Parameters:
        instanceZone - The zone in which the client resides
        preferSameZone - true if we have to prefer the same zone as the client, false otherwise
        Returns:
        The list of all eureka service urls for the eureka client to talk to
      • shutdown

        @PreDestroy
        public void shutdown()
        Shuts down Eureka Client. Also sends a deregistration request to the eureka server.
        Specified by:
        shutdown in interface EurekaClient
      • getServiceUrlsFromDNS

        @Deprecated
        public 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.
        Specified by:
        getServiceUrlsFromDNS in interface EurekaClient
        Parameters:
        instanceZone - The zone in which the client resides.
        preferSameZone - true if we have to prefer the same zone as the client, false otherwise.
        Returns:
        The list of all eureka service urls for the eureka client to talk to.
      • getDiscoveryServiceUrls

        @Deprecated
        public java.util.List<java.lang.String> getDiscoveryServiceUrls​(java.lang.String zone)
        Deprecated.
        see replacement in EndpointUtils
        Specified by:
        getDiscoveryServiceUrls in interface EurekaClient
        Parameters:
        zone - the zone in which the client resides
        Returns:
        The list of all eureka service urls for the eureka client to talk to.
      • getEC2DiscoveryUrlsFromZone

        @Deprecated
        public 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.
        Parameters:
        dnsName - The dns name of the zone-specific CNAME
        type - CNAME or EIP that needs to be retrieved
        Returns:
        The list of EC2 URLs associated with the dns name
      • newBackupRegistryInstance

        @Deprecated
        @Nullable
        protected BackupRegistry newBackupRegistryInstance()
                                                    throws java.lang.ClassNotFoundException,
                                                           java.lang.IllegalAccessException,
                                                           java.lang.InstantiationException
        Deprecated.
        Use injection to provide BackupRegistry implementation.
        Throws:
        java.lang.ClassNotFoundException
        java.lang.IllegalAccessException
        java.lang.InstantiationException
      • onCacheRefreshed

        protected void onCacheRefreshed()
        Invoked every time the local registry cache is refreshed (whether changes have been detected or not). Subclasses may override this method to implement custom behavior if needed.
      • fireEvent

        protected void fireEvent​(EurekaEvent event)
        Send the given event on the EventBus if one is available
        Parameters:
        event - the event to send on the eventBus
      • getRegion

        @Deprecated
        public static java.lang.String getRegion()
        Deprecated.
        see replacement in EndpointUtils Get the region that this particular instance is in.
        Returns:
        - The region in which the particular instance belongs to.
      • getEurekaServiceUrlsFromConfig

        @Deprecated
        public static java.util.List<java.lang.String> getEurekaServiceUrlsFromConfig​(java.lang.String instanceZone,
                                                                                      boolean preferSameZone)
      • getLastSuccessfulHeartbeatTimePeriod

        public long getLastSuccessfulHeartbeatTimePeriod()
      • getLastSuccessfulRegistryFetchTimePeriod

        public long getLastSuccessfulRegistryFetchTimePeriod()
      • getStats

        public DiscoveryClient.Stats getStats()
        Gets stats for the DiscoveryClient.
        Returns:
        The DiscoveryClientStats instance.