Multitenant starter
Purpose
This starter is used to manage multitenancy context.
Configuration
For default behaviour, only available for test purpose :
# Static list of tenants
regards.tenants=tenant1,tenant2
# Static request tenant
regards.tenant=tenant1
To manage a list of tenant at bootstrap from static configuration :
# Static bootstrap tenants (comma separated)
regards.bootstrap-tenants=
Autoconfiguration
Starter autoconfigures beans :
ITenantResolver
to retrieve list of tenants,
@FunctionalInterface
public interface ITenantResolver {
/**
* @return all tenants regardless its configuration
*/
Set<String> getAllTenants();
/**
* @return all tenants fully configured
*/
Set<String> getAllActiveTenants();
}
IRuntimeTenantResolver
to retrieve request tenant at runtime.
public interface IRuntimeTenantResolver {
/**
* @return runtime tenant
*/
String getTenant();
/**
* Does the current tenant is instance
* @return true|false
*/
boolean isInstance();
/**
* Force runtime tenant to a specific value on current thread.<br/>
* We recommend to use {@link IRuntimeTenantResolver#clearTenant()} to clean the thread in a finally clause.<br/>
* It is mostly recommended for server threads as they are reused.
* @param tenant tenant
*/
void forceTenant(String tenant);
/**
* Clear forced tenant on current thread
*/
void clearTenant();
}
danger
In production, the implementation of IRuntimeTenantResolver
must be thread safe.
How to
How to use
Just inject beans in your component.
How to override default behaviour
Create your own ITenantResolver
bean to implement your own tenant retrieval.
Create your own IRuntimeTenantResolver
bean to implement your own runtime tenant retrieval.
How to handle bootstrap tenants
Just autowired following property class to access bootstrap tenants.
@Autowired
private MultitenantBootstrapProperties bootstrapProperties;