zhangjf 330ec6dea9 refactor: 简化多租户路由配置,基于 Nacos 元数据动态匹配
问题:tenant.routing.services 配置在每个服务中重复定义 vip-tenants

解决方案:
1. TenantRoutingProperties 简化
   - 移除 services 映射(vip-tenants 列表)
   - 保留全局配置:enabled, fallback-to-shared, shared-services
   - 路由逻辑改为基于实例元数据动态匹配

2. 配置简化
   - Gateway: 只需全局配置,无需定义各服务的 vip-tenants
   - 服务实例: 只需在 Nacos metadata 中声明 tenant-group
   - 负载均衡器: 从实例 metadata 读取 tenant-group 进行匹配

3. 架构变化
   修改前:配置文件定义 vip-tenants 列表
   修改后:实例注册时声明 tenant-group,负载均衡器动态匹配

示例:
  共享实例 metadata: { tenant-group: "" }
  VIP 实例 metadata: { tenant-group: "TENANT_VIP_001" }
  请求匹配 → 路由到对应实例
2026-02-19 21:18:58 +08:00

94 lines
2.6 KiB
YAML

server:
port: 8100
spring:
application:
name: fund-sys
cloud:
nacos:
discovery:
server-addr: localhost:8848
namespace: fund-platform
group: DEFAULT_GROUP
username: nacos
password: nacos
# 租户元数据(一库一租户模式时配置)
metadata:
tenant-id: ${TENANT_ID:1}
tenant-group: TENANT_${TENANT_ID:DEFAULT}
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/fund_sys?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
username: root
password: zjf@123456
hikari:
# 连接池大小配置
maximum-pool-size: 20 # 最大连接数(建议: CPU核心数*2 + 有效磁盘数)
minimum-idle: 5 # 最小空闲连接数
# 连接超时配置
connection-timeout: 30000 # 连接超时时间(毫秒)
idle-timeout: 600000 # 空闲连接超时时间(10分钟)
max-lifetime: 1800000 # 连接最大存活时间(30分钟)
# 连接验证配置
validation-timeout: 5000 # 连接验证超时时间
leak-detection-threshold: 60000 # 连接泄露检测阈值(60秒)
# 连接池名称
pool-name: FundSysHikariPool
# 连接初始化SQL
connection-init-sql: SELECT 1
# Redis配置
data:
redis:
host: localhost
port: 6379
password: zjf@123456
database: 0
timeout: 10000
lettuce:
pool:
max-active: 8
max-wait: -1
max-idle: 8
min-idle: 0
mybatis-plus:
mapper-locations: classpath*:/mapper/**/*.xml
type-aliases-package: com.fundplatform.sys.data.entity
configuration:
map-underscore-to-camel-case: true
cache-enabled: false
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
global-config:
db-config:
logic-delete-field: deleted
logic-delete-value: 1
logic-not-delete-value: 0
# 租户插件配置(一库多租户模式启用)
tenant:
enabled: false # 启用后自动为 SQL 添加 tenant_id 条件
logging:
level:
com.fundplatform.sys: DEBUG
pattern:
console: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n"
# 多租户路由配置(服务实例只需声明自己的租户组)
tenant:
routing:
enabled: true
tenant-header: X-Tenant-Id
tenant-group-header: X-Tenant-Group
default-tenant-id: "1"
# 共享服务列表
shared-services:
- fund-gateway
- fund-report
- fund-file
# 回退到共享实例
fallback-to-shared: true