WxJava icon indicating copy to clipboard operation
WxJava copied to clipboard

使用 MybatisPlus 多租户插件疑问

Open qichhhhh opened this issue 1 year ago • 5 comments

现在项目中是根据 APPID 在数据库中查询出 tenant_id,WxMpMessageRouter 的第一个 rule 是

        router.rule()
                .async(false)
                .handler(preMessageHandler)
                .next();

image 将查出的 tenant_id 存入 context 和 TenantHolder 中,MybatisPlus 的多租户插件通过 TenantHolder.get() 取到租户id,并且在后续的查询中拼接 SQL,并且配置了全局拦截器进行 holder.remove()。 遇到的问题是,TenantHolder 中的值可以被同步 handler 取到,但是有一些 handler 是异步的,我在 context 中存入后在异步 handler 中进行同样的 TenantHolder.set(),是不是每个 async handler 都得用 try - finally 包起来并且在 finally 中执行 remove(),以保证 TenantHolder 能被释放?

qichhhhh avatar Jun 04 '24 16:06 qichhhhh