Repository navigation
Conversation
…to the instance serving state ServingStateLifecycleBridge (opt-in, shenyu.register.lifecycle-bridge.enabled=true) listens to ApplicationReadyEvent and AvailabilityChangeEvent and emits repository ready/notReady at real state transitions only: repeated Spring events are idempotent, REFUSING_TRAFFIC refuses new work while staying alive and never degrades into an offline, and ACCEPTING_TRAFFIC releases a previous refusal. At context close — which precedes the web server's graceful shutdown and the JVM hooks — the bridge stops heartbeat renewal first, then requests draining for exactly the URIs the registration flow registered, passed through unchanged so namespace/protocol/identity binding stays intact; a failing update is logged without blocking shutdown, draining is terminal, and repositories without the capability keep their default no-ops while heartbeats can never clear a drain (the Admin-side apache#8042 markers are untouched). Client-side changes are two read-only seams (a registered-URI snapshot and a publisher accessor), keeping the whole thing a thin adapter over the accepted contract. Tests drive ready/not-ready/ready sequences, idempotency, context close while the JVM stays alive, failure tolerance, identity pass-through and the opt-in gating, red against a subscriber that cannot expose identities.
…pository bean The bridge's @ConditionalOnBean(ShenyuClientRegisterRepository) relied on the implicit order of the imports file; the after clause makes the dependency explicit.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #8429.
The Java client's registration is asynchronous and its serving-state SPI (
ready/notReady/drainingfrom the accepted #8042 contract) has zero callers on the client side: URI registration gates only on a TCP connect — not application readiness — and the first serving-state signal at shutdown is the JVM-hook offline, so a Spring application that temporarily refuses traffic or starts a graceful shutdown never tells the gateways anything until the process exits. This PR adds the bridge as a thin, opt-in adapter over that existing contract; it redefines neither readiness propagation nor drain semantics.What changed
ServingStateLifecycleBridge(in the common client starter) listens to Spring readiness and emits the repository calls at real state transitions only:ApplicationReadyEvent/ACCEPTING_TRAFFICemitsready(releasing a previous refusal),REFUSING_TRAFFICemitsnotReady— refusing new work while staying alive, never degrading into an offline — and repeated identical Spring events emit nothing (an explicit INIT → READY → NOT_READY → READY → DRAINING state machine guards idempotency). At context close — which fires before the web server's graceful shutdown and the JVM hooks — the bridge stops heartbeat renewal first so no renewal races the drain, then requestsdrainingfor exactly the URIs the registration flow registered; draining is terminal, in-flight request draining and the final offline stay with the web server lifecycle and the existing JVM hooks, and heartbeats can never clear a drain because the Admin-side props markers from #8042 are untouched. Updates pass the registeredURIRegisterDTOs through unchanged so namespace/protocol/identity binding stays intact, per-identity failures are logged without blocking shutdown and never become an offline, and repositories without the capability keep their default no-ops.The client-side change is deliberately tiny: the URI subscriber exposes a read-only snapshot of its registered identities and the publisher exposes the subscriber accessor. The bridge is opt-in via
shenyu.register.lifecycle-bridge.enabled=true(registered through@AutoConfigurationwith@ConditionalOnBean(ShenyuClientRegisterRepository.class)), so shipped behavior changes nothing by default and a missing property or repository leaves no bridge bean behind.Tests
ServingStateLifecycleBridgeTestdrives the state machine against a mock repository: ready emits for every registered identity, REFUSING_TRAFFIC emits not-ready and never offline, ACCEPTING_TRAFFIC again releases the refusal, repeated ready events are idempotent, not-ready before any readiness emits nothing, context close stops renewal exactly once and then drains while the JVM stays alive (draining is terminal and later readiness changes emit nothing), repeated close events drain exactly once, a failing draining never blocks shutdown or becomes an offline, identity fields pass through unchanged, and the opt-in configuration registers the bridge only when both the property and a repository exist. The subscriber snapshot test pins the read-only, registration-independent view. All lifecycle assertions are red against a subscriber that cannot expose identities. Module results on the current master baseline:shenyu-client-core106 (was 102) andshenyu-spring-boot-starter-client-common14 (was 4) — all green; checkstyle clean.