Class IgnoreListingDiscoveryMode
- All Implemented Interfaces:
CapabilityDiscoveryMode
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final DurationThe period an instance is ignored for when no other period is configured. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs anIgnoreListingDiscoveryModearound the givendelegate, ignoring instances that answer with a client error forDEFAULT_IGNORE_PERIOD.IgnoreListingDiscoveryMode(CapabilityDiscoveryMode delegate, Duration ignorePeriod) Constructs anIgnoreListingDiscoveryModearound the givendelegate, ignoring instances that answer with a client error for the givenignorePeriod.IgnoreListingDiscoveryMode(CapabilityDiscoveryMode delegate, Duration ignorePeriod, Clock clock) Constructs anIgnoreListingDiscoveryModearound the givendelegate, ignoring instances that answer with a client error for the givenignorePeriodas measured by the givenclock. -
Method Summary
Modifier and TypeMethodDescriptiondiscover(org.springframework.cloud.client.ServiceInstance serviceInstance) Discovers which member the givenserviceInstanceis, and what it handles.Returns this application's own capabilities, as last published throughCapabilityDiscoveryMode.updateLocalCapabilities(MemberCapabilities).Returns the identifier of this application, which it reports to other members along with its capabilities.voidretainOnly(Set<ServiceInstanceKey> knownInstances) Signals that the givenknownInstancesare the only instances discovery currently reports, allowing this mode to discard whatever it remembers about instances that have gone away.voidupdateLocalCapabilities(MemberCapabilities capabilities) Publishes the givencapabilitiesas this application's own, replacing whatever was published before.
-
Field Details
-
DEFAULT_IGNORE_PERIOD
The period an instance is ignored for when no other period is configured.
-
-
Constructor Details
-
IgnoreListingDiscoveryMode
Constructs anIgnoreListingDiscoveryModearound the givendelegate, ignoring instances that answer with a client error forDEFAULT_IGNORE_PERIOD.- Parameters:
delegate- the mode to delegate capability discovery to
-
IgnoreListingDiscoveryMode
Constructs anIgnoreListingDiscoveryModearound the givendelegate, ignoring instances that answer with a client error for the givenignorePeriod.- Parameters:
delegate- the mode to delegate capability discovery toignorePeriod- 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 anIgnoreListingDiscoveryModearound the givendelegate, ignoring instances that answer with a client error for the givenignorePeriodas measured by the givenclock.- Parameters:
delegate- the mode to delegate capability discovery toignorePeriod- 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
Description copied from interface:CapabilityDiscoveryModeReturns 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:
localNodeIdin interfaceCapabilityDiscoveryMode- Returns:
- the identifier of this application
-
updateLocalCapabilities
Description copied from interface:CapabilityDiscoveryModePublishes the givencapabilitiesas 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:
updateLocalCapabilitiesin interfaceCapabilityDiscoveryMode- Parameters:
capabilities- the messages this application handles, and the command load it asks for
-
localCapabilities
Description copied from interface:CapabilityDiscoveryModeReturns this application's own capabilities, as last published throughCapabilityDiscoveryMode.updateLocalCapabilities(MemberCapabilities).A mode is told what this application handles so it can publish it; that same knowledge is what
MemberCapabilitiesControllerserves to other members, which is why reading it back is part of this contract rather than of any one implementation.- Specified by:
localCapabilitiesin interfaceCapabilityDiscoveryMode- Returns:
- this application's own capabilities, or
MemberCapabilities.INCAPABLEwhile nothing has been published yet
-
discover
public Optional<MemberAdvertisement> discover(org.springframework.cloud.client.ServiceInstance serviceInstance) Description copied from interface:CapabilityDiscoveryModeDiscovers which member the givenserviceInstanceis, and what it handles.An empty
Optionalmeans 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 carryingMemberCapabilities.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:
discoverin interfaceCapabilityDiscoveryMode- Parameters:
serviceInstance- the instance to discover- Returns:
- the member the given
serviceInstanceis and what it handles, orOptional.empty()when it should not be part of the routing ring
-
retainOnly
Description copied from interface:CapabilityDiscoveryModeSignals that the givenknownInstancesare 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:
retainOnlyin interfaceCapabilityDiscoveryMode- Parameters:
knownInstances- the keys of every instance the current discovery round reported
-