Skip to content

[ISSUE #8427] Complete local uri registration in the opt-in client. - #8500

Open
klT45 wants to merge 2 commits into
apache:masterfrom
klT45:codex/8427-client-uri-registration
Open

klT45 wants to merge 2 commits into
apache:masterfrom
klT45:codex/8427-client-uri-registration

Conversation

@klT45

@klT45 klT45 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #8427

Problem and change

@EnableClientRegister suppresses the legacy MVC listener, but its replacement registers metadata without a local upstream URI. The gateway has no upstream for an otherwise registered backend.

Wire the URI registrar only for exact shenyu.discovery.type=local (also the default). Each eligible namespace/RPC/app/context/host/port identity is queued once after URI-specific processor filtering. HTTP and WebSocket URI payloads carry the configured protocol, with the legacy http:// and ws:// defaults. A default accessor keeps existing custom ClientRegisterConfig implementations compatible. Heartbeat, offline and HTTP failback continue to use the same payload.

A synchronous enqueue failure leaves that identity retryable and allows the remaining namespaces to queue. The registrar uses a typed snapshot of its enqueue key. The subscriber's endpoint key still serves its existing heartbeat bookkeeping and is unchanged.

For HTTP and WebSocket, unresolved 0 and -1 ports skip URI publication for the current refresh without failing startup. Malformed and out-of-range ports still fail before any URI is published. Actual random-port resolution remains #8426 / #8453. General mixed-protocol configuration selection remains #8428.

#8504 owns the global shenyu.register.enabled opt-in guard and its regression test. Merge #8504 first to include that safeguard with URI registration. Both branches apply cleanly together. The separate migration in apache/shenyu-client-java#16 needs to carry the URI behavior over.

IssueSpec

IssueSpec-Mode: full
IssueSpec-Reason: Complete opt-in local URI publication and preserve the existing discovery and endpoint contract.
IssueSpec-Proposal: #8497
IssueSpec-Design: #8498
IssueSpec-Implement: #8499
IssueSpec-Specs: SPEC-8497001
IssueSpec-Tasks: TASK-8499001
IssueSpec-Validation: Java 17 Maven-wrapper verify passed in 25 reactor modules with 254 tests in 43 classes and zero failures, errors or skips. Checkstyle and RAT passed. New-code gate reports zero findings. Implementation gate and durable-spec check passed. Full root clean install and Docker e2e were not run locally.

Verification

Exact affected Maven command (PowerShell, Java 17)
$selectedTests = 'AbstractApiDocRegistrarTest,AnnotatedApiBeanMatcherTest,AnnotatedApiDefinitionMatcherTest,ApiBeanCopyTest,ApiDocRegistrarImplTest,BaseAnnotationApiProcessorTest,EnableClientRegisterUriTest,ExtractorProcessorTest,FailbackRegistryRepositoryTest,FailureRegistryTaskTest,HeartbeatFailureIsolationTest,HttpApiDocRegistrarTest,HttpClientRegisterRepositoryFencingTest,HttpClientRegisterRepositoryTest,MatcherTest,NoHttpApiDocRegistrarTest,OpenApiUtilsTest,PortUtilsTest,RegistrarNamespaceTest,RuntimeUtilsTest,ShenyuClientApiDocExecutorSubscriberTest,ShenyuClientCommonBeanConfigurationTest,ShenyuClientIllegalArgumentExceptionTest,ShenyuClientMetadataExecutorSubscriberTest,ShenyuClientRegisterEventPublisherTest,ShenyuClientRegisterRepositoryFactoryTest,ShenyuClientShutdownHookTest,ShenyuClientURIExecutorSubscriberTest,ShenyuDeleteMappingTest,ShenyuGetMappingTest,ShenyuPatchMappingTest,ShenyuPostMappingTest,ShenyuPutMappingTest,ShenyuRequestMappingTest,ShenyuSpringMvcClientConfigurationTest,SpringMvcApiBeansExtractorTest,SpringMvcApiMetaRegisterTest,SpringMvcClientEventListenerTest,SystemUtilsTest,UriApiRegistrarTest,UriReadinessTimeoutTest,SpringWebSocketClientEventListenerTest,ShenyuSpringWebSocketClientConfigurationTest'
.\mvnw.cmd -pl :shenyu-spring-boot-starter-client-springmvc,:shenyu-spring-boot-starter-client-spring-websocket -am verify "-Dtest=$selectedTests" '-Dsurefire.failIfNoSpecifiedTests=false' '-Dmaven.javadoc.skip=true'

The servlet/HTTP fixture verifies default HTTP and configured HTTPS URI payloads, exact discovery-mode gating, repeated refresh, multiple namespaces, processor exclusion, unresolved and malformed ports, HTTP 503 failback and lifecycle payloads. Core tests verify WebSocket schemes, namespace isolation on an enqueue exception and a later refresh after the port becomes usable. HTTPS/WSS checks assert registration payloads. The real gateway smoke below exercised a plain HTTP backend.

Actual Admin/bootstrap evidence from the initial revision

The initial revision 17c27ed was tested against an isolated Java 17 H2 Admin and a current-source bootstrap with websocket sync. The old source published two APIs but no URI, returning gateway code -119. The fixed local fixture persisted one live upstream and returned HTTP 200 with the backend response. A registry-mode control published two APIs and no local URI. Those live checks predate the review revision. The latest regression run covers the changed paths using the embedded MVC and HTTP transport fixture.

Reproduce with the committed fixture

EnableClientRegisterUriTest.Fixture.main starts a normal application with the actual singleton publisher and HTTP repository; the test-only publisher replacement is installed only by JUnit setup. Start an isolated Admin and bootstrap using the normal project launch instructions and matching websocket URL/token/namespace. After installing this client reactor (test execution can be skipped for this preparation), build the starter's test classpath:

MODULE=shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-springmvc
./mvnw -pl "$MODULE" -am install -DskipTests -Dmaven.javadoc.skip=true
./mvnw -pl "$MODULE" dependency:build-classpath -DincludeScope=test -Dmdep.outputFile=target/uri-fixture-classpath.txt
java -cp "$MODULE/target/test-classes:$MODULE/target/classes:$(cat "$MODULE/target/uri-fixture-classpath.txt")" \
  'org.apache.shenyu.springboot.starter.client.springmvc.EnableClientRegisterUriTest$Fixture' \
  --server.address=127.0.0.1 --server.port=18080 --spring.application.name=uri-fixture \
  --shenyu.register.registerType=http --shenyu.register.serverLists=http://127.0.0.1:9095 \
  --shenyu.register.props.username=admin --shenyu.register.props.password=123456 \
  --shenyu.client.http.props.host=127.0.0.1 --shenyu.client.http.props.port=18080 \
  --shenyu.client.http.props.appName=uri-fixture --shenyu.client.http.props.contextPath=/client \
  --shenyu.namespace=649330b6-c2d7-4edc-be8e-8a54df9eb385 --shenyu.discovery.type=local

Use the isolated Admin's credentials/ports. On Windows the Java classpath separator is ;. Direct GET http://127.0.0.1:18080/api/hello and bootstrap GET /client/api/hello should both return hello. Repeating with --shenyu.discovery.type=nacos and a fresh app/context identity should preserve metadata and leave the local upstream absent.

Make sure that:

  • You have read the contribution guidelines.
  • You submit test cases (unit or integration tests) that back your changes.
  • New production code follows the code quality rules Q1-Q9 in AGENTS.md (no magic numbers, focused methods, reuse of existing utilities).
  • Your local test passed ./mvnw clean install -Dmaven.javadoc.skip=true.

@wy471x wy471x left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the diff at 17c27ed. The wiring itself is right (bean + registry-mode gate + namespace/RPC/app/context/host/port coalescing + existing failback retry), but one field leaves the registration incomplete and one behaviour change deserves a decision.

Blocking

1. Published URIs carry no protocol, so https/wss clients are registered as plain http/ws — UriApiRegistrarImplImpl.registerUri

URIRegisterDTO uri = URIRegisterDTO.builder()
        .namespaceId(namespaceId)
        .contextPath(clientRegisterConfig.getContextPath())
        .appName(clientRegisterConfig.getAppName())
        .eventType(EventType.REGISTER)
        .host(clientRegisterConfig.getHost())
        .port(port)
        .rpcType(rpcType)
        .build();

The legacy pipeline this replaces does set it (SpringMvcClientEventListener: props.getProperty(ShenyuClientConstants.PROTOCOL, ShenyuClientConstants.HTTP) at construction, .protocol(protocol) on the DTO), and URIRegisterDTO.protocol has no default. Downstream, ShenyuClientRegisterDivideServiceImpl.buildDivideUpstreamList maps dto.getProtocol() into the divide upstream, and Upstream.normalizeProtocol turns a blank protocol into DEFAULT_PROTOCOL (http://). Consequences:

  • an opt-in client configured with shenyu.client.http.props.protocol=https (or wss) registers an upstream that the gateway dials as http://host:port, so every request fails, with no error at registration time;
  • legacy rows carry http:// while opt-in rows carry null, and upstream identity comparison in admin uses the canonical protocol, so a client migrating from the listener to @EnableClientRegister does not match its own existing divide upstream and duplicates it.

Suggested change: expose the protocol on ClientRegisterConfig/ClientRegisterConfigImpl (props.getProperty(ShenyuClientConstants.PROTOCOL, ShenyuClientConstants.HTTP), exactly as the legacy listener does) and set .protocol(...) on the DTO. Please also assert it in EnableClientRegisterUriTest, which currently checks rpcType/contextPath/appName/host/port only.

Non-blocking

2. Invalid port aborts application startup. registerUri throws IllegalArgumentException, and it is reached from ClientApiRefreshedEventListener during ContextRefreshedEvent, so SpringApplication.run fails. This matters because ClientRegisterConfigImpl.getPort() falls back to PortUtils.findPort(...), which can be 0 when server.port=0 and the port is not resolved yet (the #8426 / #8453 case). If the port is only temporarily unknown, a warning plus "publish nothing this round" (the actual-port fix then publishes on the next refresh) keeps the application bootable; if a configured port is genuinely invalid, failing fast is fine. Please state which contract you want, and note it in docs/.

3. Per-namespace isolation. PR description says "Keep successful namespace enqueues when another enqueue throws", but the for (String namespaceId : ...) loop has no try/catch, so a synchronous publisher.publishEvent failure skips every remaining namespace until the next refresh. A per-namespace try/catch with a bounded warning (no configuration values) matches the stated behaviour.

4. Discovery predicate. The "shenyu.discovery.type"/local comparison is now the fifth copy (the listeners, the MVC starter and now this registrar). Either move the gate to the wiring (@ConditionalOnProperty on the uriApiRegistrar bean) or extract one helper, so a future change to how local mode is expressed cannot silently desync.

5. Set<List<?>> publishedIdentities. The six-element untyped tuple is rebuilt from the DTO it was just built from, and ShenyuClientURIExecutorSubscriber already defines instance identity differently (namespace + contextPath + host + port). A small record type shared with the subscriber would make the key self-describing and keep the two definitions from drifting. Also note the @ConditionalOnProperty guard on ClientRegisterConfiguration is byte-identical to the one added by #8504 (same author) — please coordinate ownership so only one PR carries it.

@klT45
klT45 force-pushed the codex/8427-client-uri-registration branch from 17c27ed to e0edf7a Compare November 18, 2026 03:13
@klT45
klT45 force-pushed the codex/8427-client-uri-registration branch from e0edf7a to bfe663a Compare November 18, 2026 09:45
@klT45

klT45 commented Nov 19, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @wy471x. The URI payload now preserves the HTTP/WebSocket scheme, enqueue failures are isolated by namespace, and an unresolved port skips publication for that refresh without aborting startup. The global registration guard is now owned by #8504. All required CI checks passed, and the previously timed-out HTTP integration job passed on the latest run. Could you take another look?

@Aias00 Aias00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stream Agent analysis

Review of #8500 (Complete local uri registration in the opt-in client). The full diff was read and all previously raised blocking findings are addressed: URIs now carry the configured/defaulted protocol, enqueue failures are isolated per namespace, pending ports 0/-1 skip safely, and the local-discovery gate moved into wiring. No concrete new HIGH/CRITICAL defect found; CI passed.

Evidence: ["Full diff read via resource_diff: 8 pages, offset 0 to 42930 with has_more=false; 9 changed files (spec, config wiring, protocol accessor, UriApiRegistrarImplImpl, and new/updated tests).","Prior blocking protocol issue fixed: URIRegisterDTO now sets .protocol(clientRegisterConfig.getProtocol()); ClientRegisterConfigImpl.getProtocol() uses ShenyuClientConstants.HTTP/WS (verified http:// and ws://, PROTOCOL="protocol") with a backward-compatible default method on ClientRegisterConfig; protocol asserted in tests.","Prior non-blocking findings addressed: publish() try/catch isolates per-namespace enqueue failures, pending-port 0/-1 skip with warning (contract documented in spec.md), typed UriIdentity record dedup, discovery gate via @conditional(LocalDiscoveryCondition.class) matching isDiscoveryLocalMode; evidence reports CI passed with 38 checks and no failed/pending checks."]

Next steps: ["Coordinate merge ordering with #8504 for the global shenyu.register.enabled opt-in guard, which this PR intentionally leaves to that change."]

Verdict: PASS; publication: COMMENT (DIFF_DELIVERY_INCOMPLETE)

Findings: []

Scope: captured GitHub evidence only; no local tests were executed.

Task: dd071994-5e39-4446-9ab1-02d818d5a0ef Commit: bfe663a0a74773b034c5b2da6632a507d6052b9a

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Task][Java Client] Complete local URI registration in the EnableClientRegister pipeline

3 participants