-
Notifications
You must be signed in to change notification settings - Fork 132
Add support for AbstractRoutingConnectionFactory #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
In Reactive Streams, we no longer can use Based on Do you want to have a look at Connection routing isn't currently on our roadmap. If we receive a pull request, then we can include that feature. |
I think when used in conjuction with r2dbc-pool, a tenant-specific connection might not be the ideal solution depending on the implementation of tenant separation. This would make most sense when each tenant resides on his own database. When tenants are identified by schema or column, the same db connection could be used for multiple tenants. |
There's a vast amount of design patterns for multi-tenancy, connection/database/schema per tenant is one of them. From a consistency point of view, it makes a lot of sense to provide a routing |
We now provide an abstract base class for ConnectionFactory routing. Routing keys are typically obtained from a subscriber context. AbstractRoutingConnectionFactory is backed by either a map of string identifiers or connection factories. When using string identifiers, these can map agains e.g. Spring bean names that can be resolved using BeanFactoryConnectionFactoryLookup. class MyRoutingConnectionFactory extends AbstractRoutingConnectionFactory { @OverRide protected Mono<Object> determineCurrentLookupKey() { return Mono.subscriberContext().filter(it -> it.hasKey(ROUTING_KEY)).map(it -> it.get(ROUTING_KEY)); } } @bean public void routingConnectionFactory() { MyRoutingConnectionFactory router = new MyRoutingConnectionFactory(); Map<String, ConnectionFactory> factories = new HashMap<>(); ConnectionFactory myDefault = …; ConnectionFactory primary = …; ConnectionFactory secondary = …; factories.put("primary", primary); factories.put("secondary", secondary); router.setTargetConnectionFactories(factories); router.setDefaultTargetConnectionFactory(myDefault); return router; }
Formatting. Changed generics to avoid unchecked casting. Avoided abbreviated variable name. Simplified handling of absent keys at ConnectionFactory lookup.
We now provide an abstract base class for ConnectionFactory routing. Routing keys are typically obtained from a subscriber context. AbstractRoutingConnectionFactory is backed by either a map of string identifiers or connection factories. When using string identifiers, these can map agains e.g. Spring bean names that can be resolved using BeanFactoryConnectionFactoryLookup. class MyRoutingConnectionFactory extends AbstractRoutingConnectionFactory { @OverRide protected Mono<Object> determineCurrentLookupKey() { return Mono.subscriberContext().filter(it -> it.hasKey(ROUTING_KEY)).map(it -> it.get(ROUTING_KEY)); } } @bean public void routingConnectionFactory() { MyRoutingConnectionFactory router = new MyRoutingConnectionFactory(); Map<String, ConnectionFactory> factories = new HashMap<>(); ConnectionFactory myDefault = …; ConnectionFactory primary = …; ConnectionFactory secondary = …; factories.put("primary", primary); factories.put("secondary", secondary); router.setTargetConnectionFactories(factories); router.setDefaultTargetConnectionFactory(myDefault); return router; } Original pull request: #132.
Formatting. Changed generics to avoid unchecked casting. Avoided abbreviated variable name. Simplified handling of absent keys at ConnectionFactory lookup. Original pull request: #132.
This is resolved by e3aae61 |
In non-reactive spring application, ORM tool like Hibernate provides a way to resolve tenant and thereby make the call to appropriate database or schema. Multi-Tenancy is achieved by implementing
MultiTenantConnectionProvider
andCurrentTenantIdentifierResolver
interfaces.Is there a way to implement multi-tenancy using r2dbc. Is it supported as of now?
If no, what is the roadmap going forward for this feature?
The text was updated successfully, but these errors were encountered: