# Register/delete tenant after startup of the application

**URL:** <https://forum.flowable.org/t/register-delete-tenant-after-startup-of-the-application/11850>\
**Category:** Flowable Engine\
**Created:** [October 22, 2024, 8:34am UTC](https://forum.flowable.org/t/register-delete-tenant-after-startup-of-the-application/11850 "2024-10-22T08:34:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![desp.kaz](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@desp.kaz](https://forum.flowable.org/u/desp.kaz)\
**Post date:** [October 22, 2024, 8:34am UTC](https://forum.flowable.org/t/register-delete-tenant-after-startup-of-the-application/11850/1 "2024-10-22T08:34:11Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)\
**Post date:** [October 22, 2024, 9:00am UTC](https://forum.flowable.org/t/register-delete-tenant-after-startup-of-the-application/11850/2 "2024-10-22T09:00:16Z")

</div>

Hey @desp.kaz,

The `MultiSchemaMultiTenantProcessEngineConfiguration` has a public method `registerTenant`, have you tried using that to register a new tenant?

Cheers,  
Filip

---

<div class="post-metadata">

**Author:** ![desp.kaz](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@desp.kaz](https://forum.flowable.org/u/desp.kaz)\
**Post date:** [October 22, 2024, 9:45am UTC](https://forum.flowable.org/t/register-delete-tenant-after-startup-of-the-application/11850/3 "2024-10-22T09:45:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)\
**Post date:** [October 22, 2024, 12:30pm UTC](https://forum.flowable.org/t/register-delete-tenant-after-startup-of-the-application/11850/4 "2024-10-22T12:30:07Z")

</div>

> [@desp.kaz](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![desp.kaz](https://avatars.discourse-cdn.com/v4/letter/d/8491ac/32.png) [@desp.kaz](https://forum.flowable.org/u/desp.kaz)\
**Post date:** [October 24, 2024, 11:39am UTC](https://forum.flowable.org/t/register-delete-tenant-after-startup-of-the-application/11850/5 "2024-10-24T11:39:05Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)\
**Post date:** [October 24, 2024, 12:02pm UTC](https://forum.flowable.org/t/register-delete-tenant-after-startup-of-the-application/11850/6 "2024-10-24T12:02:30Z")

</div>

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.
