Conversation
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
|
auggie review |
🤖 Augment PR SummarySummary: 本 PR 为 WxJava 的 MiniApp/MP 多租户 Spring Boot Starter 新增可配置的“共享模式”,在大量租户场景下复用 SDK 的 Changes:
Technical Notes: 共享模式依赖 ThreadLocal 进行租户切换,同一线程内务必在每次调用前完成切换;异步/线程池场景需显式传递必要信息以避免错用租户配置。 🤖 Was this summary useful? React with 👍 or 👎 |
|
|
||
| ## 问题背景 | ||
|
|
||
| 用户在 issue #3909 中提出了一个架构设计问题: |
| return null; | ||
| } | ||
| // 切换到指定租户的配置 | ||
| return sharedWxMaService.switchoverTo(tenantId); |
There was a problem hiding this comment.
这里使用 switchoverTo 在租户不存在时会抛 WxRuntimeException,与现有 WxMaMultiServicesImpl#getWxMaService 未命中时返回 null 的行为不一致,可能破坏“共享/隔离模式 API 一致”的预期。建议明确并统一“tenantId 不存在”时的返回/异常约定(MP 的 shared 实现也同理)。
Other Locations
spring-boot-starters/wx-java-mp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/service/WxMpMultiServicesSharedImpl.java:29
🤖 Was this useful? React with 👍 or 👎
| return null; | ||
| } | ||
| // 切换到指定租户的配置 | ||
| return sharedWxMaService.switchoverTo(tenantId); |
There was a problem hiding this comment.
这里调用 switchoverTo(tenantId) 在 tenantId 未配置/为空字符串时会直接抛 WxRuntimeException,而隔离模式 WxMaMultiServicesImpl#getWxMaService 会返回 null。这会导致两种模式在“租户不存在”场景下的行为不一致(也适用于 WxMpMultiServicesSharedImpl),建议在对外契约/文档中明确该差异以避免兼容性踩坑。
Other Locations
spring-boot-starters/wx-java-mp-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/service/WxMpMultiServicesSharedImpl.java:29
🤖 Was this useful? React with 👍 or 👎
|
|
||
| ## 问题背景 | ||
|
|
||
| 用户在 issue #3909 中提出了一个架构设计问题: |
| ## 相关链接 | ||
|
|
||
| - Issue: [#3909](https://github.com/binarywang/WxJava/issues/3909) | ||
| - Pull Request: [待填写] |
There was a problem hiding this comment.
Pull request overview
本 PR 为 WxJava 的 Spring Boot Starter 多租户实现添加了可配置的共享模式,以优化大规模租户场景下的资源使用。
主要变更
- 新增
MultiTenantMode枚举,提供 ISOLATED(隔离)和 SHARED(共享)两种模式 - 新增共享模式实现类,使用单个 WxService 实例和 configMap 管理多租户配置
- 重构配置类以支持模式选择,同时保持向后兼容(默认使用 ISOLATED 模式)
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| WxMpMultiServicesSharedImpl.java | 新增公众号共享模式实现类,通过单个 WxMpService 实例管理多租户配置 |
| WxMaMultiServicesSharedImpl.java | 新增小程序共享模式实现类,通过单个 WxMaService 实例管理多租户配置 |
| WxMpMultiProperties.java | 添加 MultiTenantMode 枚举和 multi-tenant-mode 配置属性 |
| WxMaMultiProperties.java | 添加 MultiTenantMode 枚举和 multi-tenant-mode 配置属性 |
| AbstractWxMpConfiguration.java | 重构以支持两种多租户模式,提取通用方法以减少代码重复 |
| AbstractWxMaConfiguration.java | 重构以支持两种多租户模式,修正日志消息中的模块名称 |
| MULTI_TENANT_MODE.md | 详细说明小程序多租户模式的使用方法和注意事项 |
| MULTI_TENANT_MODE_IMPROVEMENT.md | 总览性文档,说明多租户模式改进的背景和使用指南 |
spring-boot-starters/wx-java-miniapp-multi-spring-boot-starter/MULTI_TENANT_MODE.md
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
auggie review |
bbc138a to
30914f3
Compare
Spring Boot Starter 的多租户实现为每个租户创建独立的 WxService 实例和 HTTP 客户端,而基础 SDK 类已支持通过
configMap管理多配置。这导致 100 个租户需要 100 个 HTTP 客户端(~500MB)。解决方案
新增可配置的多租户模式,默认保持现有行为:
实现
配置属性:
代码使用(两种模式 API 完全一致):
变更范围
新增类:
WxMaMultiServicesSharedImpl/WxMpMultiServicesSharedImpl新增配置:
MultiTenantMode枚举(ISOLATED, SHARED)multi-tenant-mode配置项重构:
AbstractWxMaConfiguration/AbstractWxMpConfiguration支持模式选择TreeMap保证默认租户选择的确定性支持模块
注意事项
共享模式依赖
ThreadLocal切换配置,异步场景需预先获取配置信息:向后兼容
完全兼容。未配置
multi-tenant-mode时使用 ISOLATED 模式,行为与旧版本一致。Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.