Class IgnoreListingDiscoveryMode

java.lang.Object
io.axoniq.framework.springcloud.discovery.IgnoreListingDiscoveryMode
All Implemented Interfaces:
CapabilityDiscoveryMode

public class IgnoreListingDiscoveryMode extends Object implements CapabilityDiscoveryMode
A CapabilityDiscoveryMode that delegates to another, and stops asking an instance for its MemberCapabilities for a while once that instance answers with a client error.

Spring Cloud Discovery reports every service registered with it, not only the ones running this connector. Asking an unrelated service for its capabilities fails with a client error on every heartbeat for as long as both are deployed — a steady stream of pointless requests and log noise. This mode remembers such instances and skips them until the configured ignorePeriod has passed, after which they are tried once more. That expiry matters: an instance may have answered with a client error because it was still starting up, and a permanent ignore-list would keep it out of the cluster for good.

An ignored instance is reported as Optional.empty(), which leaves it out of the routing ring entirely. That is deliberately different from how the delegate reports an instance it merely could not reach, which stays in the ring as a member handling nothing.

Since:
5.4.0
Author:
Allard Buijze, Steven van Beelen
  • Field Details

    • DEFAULT_IGNORE_PERIOD

      public static final Duration DEFAULT_IGNORE_PERIOD
      The period an instance is ignored for when no other period is configured.
  • Constructor Details

    • IgnoreListingDiscoveryMode

      public IgnoreListingDiscoveryMode(CapabilityDiscoveryMode delegate)
      Constructs an IgnoreListingDiscoveryMode around the given delegate, ignoring instances that answer with a client error for DEFAULT_IGNORE_PERIOD.
      Parameters:
      delegate - the mode to delegate capability discovery to
    • IgnoreListingDiscoveryMode

      public IgnoreListingDiscoveryMode(CapabilityDiscoveryMode delegate, Duration ignorePeriod)
      Constructs an IgnoreListingDiscoveryMode around the given delegate, ignoring instances that answer with a client error for the given ignorePeriod.
      Parameters:
      delegate - the mode to delegate capability discovery to
      ignorePeriod - the period an instance is ignored for after answering with a client error. Must be strictly positive.
    • IgnoreListingDiscoveryMode

      public IgnoreListingDiscoveryMode(CapabilityDiscoveryMode delegate, Duration ignorePeriod, Clock clock)
      Constructs an IgnoreListingDiscoveryMode around the given delegate, ignoring instances that answer with a client error for the given ignorePeriod as measured by the given clock.
      Parameters:
      delegate - the mode to delegate capability discovery to
      ignorePeriod - the period an instance is ignored for after answering with a client error. Must be strictly positive.
      clock - the clock measuring when an ignored instance may be tried again
  • Method Details

    • localNodeId

      public String localNodeId()
      Description copied from interface: CapabilityDiscoveryMode
      Returns the identifier of this application, which it reports to other members along with its capabilities.

      Unique to the running process: an application that restarts is a new member, which matters because it has not seen what the previous process did.

      Specified by:
      localNodeId in interface CapabilityDiscoveryMode
      Returns:
      the identifier of this application
    • updateLocalCapabilities

      public void updateLocalCapabilities(MemberCapabilities capabilities)
      Description copied from interface: CapabilityDiscoveryMode
      Publishes the given capabilities as this application's own, replacing whatever was published before.

      Called whenever a command or query handler is subscribed to, or unsubscribed from, this application's connector.

      Specified by:
      updateLocalCapabilities in interface CapabilityDiscoveryMode
      Parameters:
      capabilities - the messages this application handles, and the command load it asks for
    • localCapabilities

      public MemberCapabilities localCapabilities()
      Description copied from interface: CapabilityDiscoveryMode
      Returns this application's own capabilities, as last published through CapabilityDiscoveryMode.updateLocalCapabilities(MemberCapabilities).

      A mode is told what this application handles so it can publish it; that same knowledge is what MemberCapabilitiesController serves to other members, which is why reading it back is part of this contract rather than of any one implementation.

      Specified by:
      localCapabilities in interface CapabilityDiscoveryMode
      Returns:
      this application's own capabilities, or MemberCapabilities.INCAPABLE while nothing has been published yet
    • discover

      public Optional<MemberAdvertisement> discover(org.springframework.cloud.client.ServiceInstance serviceInstance)
      Description copied from interface: CapabilityDiscoveryMode
      Discovers which member the given serviceInstance is, and what it handles.

      An empty Optional means the instance should be left out of the routing ring entirely — it is not a member of this cluster, or is not currently answering for one. That differs from an advertisement carrying MemberCapabilities.INCAPABLE, which keeps the instance in the ring as a member that handles nothing.

      This application's own instance is discovered like any other, answering with this application's node id.

      Called concurrently, once per discovered instance, for every instance of one discovery round. Implementations must therefore be thread-safe.

      Specified by:
      discover in interface CapabilityDiscoveryMode
      Parameters:
      serviceInstance - the instance to discover
      Returns:
      the member the given serviceInstance is and what it handles, or Optional.empty() when it should not be part of the routing ring
    • retainOnly

      public void retainOnly(Set<ServiceInstanceKey> knownInstances)
      Description copied from interface: CapabilityDiscoveryMode
      Signals that the given knownInstances are the only instances discovery currently reports, allowing this mode to discard whatever it remembers about instances that have gone away.

      Called at the end of each discovery round. Implementations that keep no per-instance state need not do anything, which is what this default implementation does.

      Specified by:
      retainOnly in interface CapabilityDiscoveryMode
      Parameters:
      knownInstances - the keys of every instance the current discovery round reported