Hello,
I have a spring boot application that uses MultiSchemaMultiTenantProcessEngineConfiguration for multi-tenancy. I load some of my tenants on startup when creating my configuration bean.
Can I add/delete a tenant after the startup (e.g. when I receive a message from a queue) without the need to restart my server?
Hey @desp.kaz,
The MultiSchemaMultiTenantProcessEngineConfiguration
has a public method registerTenant
, have you tried using that to register a new tenant?
Cheers,
Filip
Yes, I’ve just noticed the following comment at the class that says that it can be done after the startup:
Add a new DataSource for a tenant, identified by the provided tenantId, to the engine. This can be done after the engine has booted up. Note that the tenant identifier must have been added to the TenantInfoHolder prior to calling this method.
so I will add this at my listener.
For the deletion, I am wondering if it would be enough to do something like:
((TenantAwareDataSource) super.getDataSource()).removeDataSource(tenantId);
and remove the tenant from TenantInfoHolder list of tenants
I don’t think so, because the register boots up an async executor and similar things like that. I would advise you to look into what the register does and do the opposite for unregistering.
Thanks a lot @filiphr!
I’ve noticed that at registerTenant method there is a method postProcessEngineInitialisation() that is called but as far as I understand this shouldn’t be called at the deletion of the tenant. Is that true?
Yes indeed, this method should not be called in the delete. I think the main thing is to call TenantAwareAsyncExecutor#removeTenantAsyncExecutor
so that the async executor for that tenant stops.