You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Enable ReactiveRedisTemplate for multi-tenancy usage #2145
I would like to use ReactiveRedisTemplate in multitenant environment. In short, the option to use single ReactiveRedisTemplate which can connect to multiple Redis instances based on tenant values passed in reactive context.
Unfortunately, I can not connect the reactive context with the connection factory so I can create different connections (or using different connection pool) based on tenant value in the context.
One option is to override doInConnection, but it has private modifier. Changing it will allow me to provide custom logic about connection creation.
changed the title [-]Change visibility of doInConnection method in ReactiveRedisTemplate[/-][+]Enable `ReactiveRedisTemplate` for multi-tenancy usage[/+]on Aug 23, 2021
doInConnection is an internal method that handles resource allocation. What we should look for is how to enable ReactiveRedisTemplate for multi-tenancy usage. The first part of resource allocation is having a Mono emitting ReactiveRedisConnection. We could introduce a Mono<ReactiveRedisConnection> getConnection() method as extension point.
Yes, exactly. A protected method that can be overridden by subclasses. Right now, the calls to obtain a connection return plain ReactiveConnection on the connection factory and are not suitable to access the reactor context. So solving the issue within the template would create the least impact.
Mono.fromSupplier() is sufficient. One calling getConnection() that returns a Mono would expect deferred resource allocation. Otherwise, you already have a connection allocated and the only way to dispose it is by subscribing to the mono. Retaining fromSupplier(…) avoids such leaks in the first place.
protectedMono<ReactiveRedisConnection> getConnection(booleanexposeConnection) {
returnMono.deferContextual(contextView -> {
// Something that returns Mono<ReactiveRedisConnection> based on the value in the context
}
)
Activity
[-]Change visibility of doInConnection method in ReactiveRedisTemplate[/-][+]Enable `ReactiveRedisTemplate` for multi-tenancy usage[/+]mp911de commentedon Aug 23, 2021
doInConnectionis an internal method that handles resource allocation. What we should look for is how to enableReactiveRedisTemplatefor multi-tenancy usage. The first part of resource allocation is having aMonoemittingReactiveRedisConnection. We could introduce aMono<ReactiveRedisConnection> getConnection()method as extension point.petromir commentedon Aug 24, 2021
Thanks a lot. When do you plan to tackle this?
mp911de commentedon Aug 24, 2021
Having a pull request would improve things in terms of timing so we could integrate it faster.
petromir commentedon Aug 24, 2021
I knew you gonna say that 😄
petromir commentedon Aug 24, 2021
I assume you mean in having this in
ReactiveRedisTemplate?mp911de commentedon Aug 24, 2021
Yes, exactly. A
protectedmethod that can be overridden by subclasses. Right now, the calls to obtain a connection return plainReactiveConnectionon the connection factory and are not suitable to access the reactor context. So solving the issue within the template would create the least impact.petromir commentedon Aug 24, 2021
Something like
mp911de commentedon Aug 24, 2021
Mono.fromSupplier()is sufficient. One callinggetConnection()that returns aMonowould expect deferred resource allocation. Otherwise, you already have a connection allocated and the only way to dispose it is by subscribing to the mono. RetainingfromSupplier(…)avoids such leaks in the first place.petromir commentedon Aug 27, 2021
Then how I will be able to pass the context to
getConnection()?mp911de commentedon Aug 27, 2021
Since the method returns a
Monoalready, you can override the method by callingMono.deferContextual(…)in your override.petromir commentedon Sep 8, 2021
You mean
Then in my overriding class
mp911de commentedon Sep 8, 2021
Yes, exactly.
petromir commentedon Sep 10, 2021
@mp911de Please review my PR and let me know if I have to do some changes
mp911de commentedon Sep 13, 2021
Thanks, we're going to take this PR from here.
Extract connection creation into ReactiveRedisTemplate.getConnection(…
Polishing.
Polishing.