-
Notifications
You must be signed in to change notification settings - Fork 177
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
Support for Postgresql multi-host failover functionality #120
Comments
Happy to review a pull request on how to make |
Hello, we have a problem with postgresql setting targetServerType. When we use it in our connection string, we get an exception |
This does not exist as of yet. This is a JDBC thing |
Hi, I've just written FailoverConnectionFactoryProvider. It works without any changes in ConnectionUrlParser, ConnectionFactoryOptions, ConnectionFactoryProvider implementation. It also works with any driver (not only postgresql). UPD: fixed several issues in the code.
|
@kotoant What sense in "Create file in resources directory (on classpath): META-INF/services/io.r2dbc.spi.ConnectionFactoryProvider with the following line: * kotoant.FailoverConnectionFactoryProvider"? How does it work? Does it creates bean? |
The internal implementation of the driver supports its extension by Service Provider Interface mechanism in Java. It doesn't create bean in terms of Spring or any other DI framework. It just tries to find name of the class with implementation of the interface io.r2dbc.spi.ConnectionFactoryProvider in the text file META-INF/services/io.r2dbc.spi.ConnectionFactoryProvider, if it exists it tries to create the instance of it and use it for resolving particular providers by name. In my case this name is 'failover'. In my example I use class FailoverConnectionFactoryProvider in package kotoant. If your class is in another package or it has another name, you should specify the correct full class name in file META-INF/services/io.r2dbc.spi.ConnectionFactoryProvider. |
@kotoant thanks, I got it. But if the class We are using Spring. So is it possible to create Currently it is not worked for me:
|
@osya It does not matter where the file (with all required parent directories including META-INF/...) is located, because it should be on classpath in runtime. So you can add it to the classpath via java -cp ... but it works only when you use java with main class - without -jar option. If you use -jar, it means you have some uber-jar. All you need is to check that that uber-jar file contains the file META-INF/services/io.r2dbc.spi.ConnectionFactoryProvider. The easiest way to do that is to unzip the jar file and check that in the root of the file you can see directory META-INF with subdirectory services - with text file io.r2dbc.spi.ConnectionFactoryProvider. As I remember if you use maven-spring-boot plugin for creating the uber-jar file, if you put META-INF/services/io.r2dbc.spi.ConnectionFactoryProvider file in your application module (not library) resources directory - then the directory META-INF with all subdirs and files will be placed in the target jar out-of-the box. If you place the file in some library for reuse - I don't remember exactly - how it works - but you can test it the way I described above. Also I used workaround for other similar tasks - I used maven-shade-plugin for creating uber-jar. This plugin have different resource transformers - for your goal you need https://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html#ServicesResourceTransformer . So if you have different dependency libraries with their own META-INF/services/... the plugin creates one directory with combined file - and everything will work. I used it without any issues. More over similar functionality is very useful if you use spring boot auto-configuration. Because it works via the same mechanism - but it tries to find auto-confifguration classes in file resources/META-INF/spring.factories. So it also very often task to combine different files form different dependency-libs in one file. For that purpose I used https://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html#AppendingTransformer. You can see the examples under the link. As I mentioned above - I'm not sure - whether spring-boot-plugin maven performs all required transformation out of the box (maybe It works - without any issues - you can check and let me and others know), but I'm sure that you can achieve the desired result with maven-shade-plugin. You asked very basic questions. I suggest you to familiarize yourself with key concept of java and spring. If you have any other questions I don't promise that I will answer you. I already told you so much with detailed explanations - so it is surprise for me that you still have issues with such basic questions :) |
@kotoant , thank your for your explanation. |
@mp911de why you guys are not providing this feature in this reactive library. Do not you want your users to have failover cluster facility? Please ease the process and let this feature enabled in your library. |
@harishvashistha we are using this solution not yet in production. Currently it is testing in different our staging areas. But it will be in production I suppose after a month |
Refactor connection creation from composeable ConnectionStrategy into composeable ConnectionFunctions and a parameter-less ConnectionStrategy that holds all connection target details. Refactor SSL fallback into ConnectionFunction as SSL is part of the initial handshake. Move startup options into ConnectionSettings. Simplify sink subscriptions into Flux composition for easier synchronization of closed connections. Add duration style parser. Add license headers and since tags, update documentation. [#120][resolves #474][#203] Signed-off-by: Mark Paluch <mpaluch@vmware.com>
@harishvashistha we are using the solution I provide in production without any issues. |
@kotoant In case of using Spring instead of |
Look at my code: it doesn't depend on any framework. It depends only on r2dbc, reactor and slf4j. So potential clients and users may use it without modifications - even if they don't use spring and whatever-framework. Basically it is one of the main principles do develop client API: do not use extra dependencies. |
@kotoant Will your approach work for a pool of connections, for example for io.r2dbc.pool.ConnectionPool factory? |
@aliakmikh If you need the solution for postgres, the team already provided official solution for the problem. As I remember it works for spi 1.0.0: |
Currently this is unable to support a master-slave scenario for postgresql
basically the equivalent of this:
jdbc:postgresql://postgres_master:5432,postgres_slave:5432/myDb
The text was updated successfully, but these errors were encountered: