Skip to content

feature: add registry port config#8017

Open
ban-xiu wants to merge 7 commits intoapache:2.xfrom
ban-xiu:feat-add-registry-port
Open

feature: add registry port config#8017
ban-xiu wants to merge 7 commits intoapache:2.xfrom
ban-xiu:feat-add-registry-port

Conversation

@ban-xiu
Copy link

@ban-xiu ban-xiu commented Mar 10, 2026

Problem Background

In Docker deployment scenarios using port mapping (e.g., -p 21908:8091), the Seata Server listens on port 8091 inside the container. However, clients need to access it through the host's port 21908. Currently, both SEATA_PORT and seata.server.service-port simultaneously control both the listening port and the registration port, making separation impossible. Although SEATA_IP already supports overriding the registered IP, there is no corresponding mechanism for the port.

Solution

Introduce a new optional configuration seata.server.registry-port (environment variable SEATA_REGISTRY_PORT) that overrides only the port registered to the service discovery center (Nacos, etc.), without affecting the actual listening port of Netty. Behavior remains completely unchanged if not configured.

Main Changes

  1. Extracted the original port resolution logic into resolveServicePort() and added a new resolveRegistryPort().
  2. The resolution priority is: SEATA_REGISTRY_PORT environment variable > seata.server.registry-port YAML configuration.
  3. Port replacement occurs only at the two entry points in the registration chain:
    • NettyServerBootstrap.start()
    • VGroupMappingStoreManager.notifyMapping()
  4. The change takes effect uniformly for all registry centers (Nacos, Eureka, etc.), eliminating the need for individual adaptations in each registry implementation.

问题背景

在 Docker 部署场景中,使用端口映射(如 -p 21908:8091)时,Seata Server 在容器内监听 8091 端口。然而,客户端需要通过主机的 21908 端口访问。目前,SEATA_PORT 和 seata.server.service-port 同时控制监听端口和注册端口,无法实现分离。虽然 SEATA_IP 已支持覆盖注册 IP,但没有对应的端口机制。

解决方案

引入一个新的可选配置项 seata.server.registry-port(环境变量 SEATA_REGISTRY_PORT),它仅覆盖注册到服务发现中心(Nacos 等)的端口,而不影响 Netty 的实际监听端口。如果不配置该参数,行为将完全保持不变。

主要变更

  1. 将原有的端口解析逻辑提取到 resolveServicePort() 中,并新增 resolveRegistryPort() 方法。
  2. 端口解析优先级为:SEATA_REGISTRY_PORT 环境变量 > seata.server.registry-port YAML 配置。
  3. 端口替换仅在注册链的两个入口点生效:
    • NettyServerBootstrap.start()
    • VGroupMappingStoreManager.notifyMapping()
  4. 此变更对所有注册中心(Nacos、Eureka 等)统一生效,无需在每个注册中心实现中单独适配。

@ban-xiu ban-xiu changed the title Add registry port config feature: add registry port config Mar 13, 2026
@ban-xiu
Copy link
Author

ban-xiu commented Mar 13, 2026

@lokidundun @funky-eyes Could you please help review this PR when you have a moment? Thanks a lot!

@codecov
Copy link

codecov bot commented Mar 14, 2026

Codecov Report

❌ Patch coverage is 37.50000% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.26%. Comparing base (a63866f) to head (34cfe3a).

Files with missing lines Patch % Lines
...ver/spring/listener/ServerApplicationListener.java 35.29% 9 Missing and 2 partials ⚠️
.../seata/server/store/VGroupMappingStoreManager.java 0.00% 8 Missing ⚠️
...che/seata/core/rpc/netty/NettyServerBootstrap.java 54.54% 3 Missing and 2 partials ⚠️
...a/org/apache/seata/server/env/ContainerHelper.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##                2.x    #8017      +/-   ##
============================================
+ Coverage     72.24%   72.26%   +0.01%     
  Complexity      876      876              
============================================
  Files          1310     1310              
  Lines         49977    50015      +38     
  Branches       5945     5950       +5     
============================================
+ Hits          36107    36143      +36     
- Misses        10917    10923       +6     
+ Partials       2953     2949       -4     
Files with missing lines Coverage Δ
...ava/org/apache/seata/common/ConfigurationKeys.java 0.00% <ø> (ø)
...oconfigure/properties/server/ServerProperties.java 100.00% <100.00%> (ø)
...a/org/apache/seata/server/env/ContainerHelper.java 77.77% <0.00%> (-9.73%) ⬇️
...che/seata/core/rpc/netty/NettyServerBootstrap.java 73.83% <54.54%> (-2.46%) ⬇️
.../seata/server/store/VGroupMappingStoreManager.java 0.00% <0.00%> (ø)
...ver/spring/listener/ServerApplicationListener.java 50.00% <35.29%> (-5.32%) ⬇️

... and 9 files with indirect coverage changes

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ban-xiu
Copy link
Author

ban-xiu commented Mar 14, 2026

Sorry, I just ran the spotless

@ban-xiu
Copy link
Author

ban-xiu commented Mar 16, 2026

@funky-eyes This appears to be an issue with Maven itself, not due to newly added code.

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.

2 participants