【问题标题】:SpringBoot Multi-tenant app with scheduled tasks带有计划任务的 SpringBoot 多租户应用程序
【发布时间】:2020-08-14 18:32:54
【问题描述】:

我有一个多租户应用程序,我们的客户在其中提交他们的订单(JSON 有效负载),必须离线处理。我们正在使用每个租户的数据库策略,并且配置工作正常。然而,对于本例中的异步处理,我们陷入了困境。当客户提交有效负载时,它会保存到一个表中。我们想运行一个计划任务,它可以读取这个表并处理他们的订单。

我们尝试了类似的方法:

@Scheduled(fixedRate = 60000)
    public void doSomething() {
        TenantDataSource tenantDataSource = context.getBean(TenantDataSource.class);
        Set<String> tenants = tenantDataSource.getAll().keySet();
        tenants.forEach(tenant -> {
            MDC.setContext(new CallContext().setTenantId(tenant));
            context.getBean(JobService.class).listJobs();
        });
    }

但这仍然在 master 数据库中而不是在特定于租户的数据库中查找作业。

任何指针?

【问题讨论】:

  • 你的 CurrentTenantIdentifierResolver 是什么样的?

标签: spring hibernate spring-boot jpa multi-tenant


【解决方案1】:

确保 doSomething() 方法不是事务性的,因为 transactional 会创建自己的拦截器,而不是查看您的解析器。

【讨论】:

    猜你喜欢
    • 2018-06-04
    • 2011-08-31
    • 1970-01-01
    • 1970-01-01
    • 2020-05-08
    • 2015-02-26
    • 2020-12-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多