Multitenancy Flowable engine in Spring Reactive app

Hi, I’m trying to setup the Shared Engine / Multi-schema option for allowing multitenancy in our product.
This product is based on Spring Webflux: multitenancy is managed using a “tenant” claim into the Reactor Context for each request. Based on JWT, each request is forwarded to the correct MongoDB instance, or Redis instance (this for database and cache access).
Now I would like to obtain the same result for Flowable: the same engine (managed in our Spring mircoservice) will manage the requests from all the tenants, each with its own Postgres database instance: each tenant has its own deployments, process definitions, process instances and so on in a dedicated database.
But I’m not finding a way to make this work: I tryied a TenantInfoHolder implementation:

public String getCurrentTenantId() {
		return AuthenticationUtils.getTenantIdFromContext().block();
	}

I can’t figure out what to implement for setCurrentTenantId and clearCurrentTenantId methods because the tenant remains the same for each request.
I also implemented the MultiSchemaMultiTenantProcessEngineConfiguration, but I get a nullpointer exception at startup time (at startup time there is no logged user, so no tenant) if I don’t put a null tenant.

@Override
public ProcessEngine buildProcessEngine() {
	log.info("buildProcessEngine");
		
this.setDatabaseType(MultiSchemaMultiTenantProcessEngineConfiguration.DATABASE_TYPE_POSTGRES);
this.setDatabaseSchemaUpdate(MultiSchemaMultiTenantProcessEngineConfiguration.DB_SCHEMA_UPDATE_DROP_CREATE);
this.setAsyncExecutorActivate(true);
this.setDisableIdmEngine(true);
this.setDisableEventRegistry(true);
this.setAsyncExecutor(new SharedExecutorServiceAsyncExecutor(tenantInfoHolder));

registerTenant(null, createDataSource("jdbc:postgresql://localhost:5432/flowable", "flowable", "flowable"));
registerTenant("one-realm", createDataSource("jdbc:postgresql://localhost:5432/flowable", "flowable", "flowable"));
registerTenant("two-realm", createDataSource("jdbc:postgresql://localhost:5432/flowable-two", "flowable-two", "flowable-two"));

I get the application running, but all requests are to the one-realm tenant.
A request of a user logged into two-realm tenant will access to one-realm flowable data.

Could somehone help me, please?

If your setup looks like that, you’re using Flowable effectively in single-tenant mode. The code you’ve pasted is to work in a single database with multiple tenants and different schema’s.

In your use case, it looks like you want to use a single engine per tenant, but still set the tenantId in the data? To do that, you need to pass the tenantId to all relevant calls (e.g. start process instance, etc.). That’s not automatic.

Thanks for the reply.
I wrote that code following the example I found for “Shared Engine / Multi-schema” approach. So it’s totally wrong? What’s the correct way to manage distinct tenant with separate databases?
I this case I don’t need to pass the tenant id to all the calls, right?