Skip to content
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

Spring Boot 2 vs. Spring Boot 3 - r2dbc spi incompatibility #132

Open
kwonglau opened this issue Jan 11, 2023 · 9 comments
Open

Spring Boot 2 vs. Spring Boot 3 - r2dbc spi incompatibility #132

kwonglau opened this issue Jan 11, 2023 · 9 comments

Comments

@kwonglau
Copy link

Spring Boot 2 is using R2DBC SPI 0.8.x
Spring Boot 3 is using 1.0.0.RELEASE

r2dbc has change the return type for insert row count from int to long. when using spring boot 3, we need to update the code and at least re-compile.

https://github.com/mirromutth/r2dbc-mysql
the mysql r2dbc driver is not compatible with spring boot 3 and I mange to use the mariadb r2dbc driver (1.1.2) connecting to mysql server 8.0.31 and it is working well. when using 1.1.3, it throw exception, but 1.1.3 version can connect to mariadb 10.10.2 without any error.

However, the code need to be update like the following.

@Configuration
public class EventuateCommonReactiveMysqlConfiguration {

  @Bean
  @ConditionalOnProperty(name = "eventuate.reactive.db.driver", havingValue = MYSQL)
  public ConnectionFactory mysqlConnectionFactory(EventuateCommonReactiveDatabaseProperties eventuateCommonReactiveDatabaseProperties) {
//    ConnectionFactoryOptions options = ConnectionFactoryOptions.builder()
//        .option(DRIVER, eventuateCommonReactiveDatabaseProperties.getDriver())
//        .option(HOST, eventuateCommonReactiveDatabaseProperties.getHost())
//        .option(USER, eventuateCommonReactiveDatabaseProperties.getUsername())
//        .option(PORT, eventuateCommonReactiveDatabaseProperties.getPort())
//        .option(PASSWORD, eventuateCommonReactiveDatabaseProperties.getPassword())
//        .option(DATABASE, eventuateCommonReactiveDatabaseProperties.getDatabase())
//        .option(Option.valueOf("tcpKeepAlive"), true)
//        .build();
//        
//    return ConnectionFactories.get(options);

    MariadbConnectionConfiguration conf = MariadbConnectionConfiguration.builder()
        .host(eventuateCommonReactiveDatabaseProperties.getHost())
        .port(eventuateCommonReactiveDatabaseProperties.getPort())
        .username(eventuateCommonReactiveDatabaseProperties.getUsername())
        .password(eventuateCommonReactiveDatabaseProperties.getPassword())
        .database(eventuateCommonReactiveDatabaseProperties.getDatabase())
        .tcpKeepAlive(true)
        .allowPublicKeyRetrieval(true)
        .build();

    return new MariadbConnectionFactory(conf);
  }

}
@cer
Copy link
Contributor

cer commented Jan 11, 2023

Perhaps the solution is for mysqlConnectionFactory() to use a plugin mechanism, e.g. Java SPI, i.e. find/load a Spring Boot version specific factory class for ConnectionFactory.

@kwonglau
Copy link
Author

because of the SPI version different. We need to use different version of the r2dbc version when using different spring boot version
e.g.

Postgres 1.0.0.RELEASE for SB3 and 0.9.3.RELEASE for SB2
Mariadb 1.1.2.RELEASE for SB3 and 1.0.2 for SB2

how do we deal with different version of the dependencies ?

@cer
Copy link
Contributor

cer commented Jan 11, 2023

how do we deal with different version of the dependencies ?

I don't know the details but I'm guessing something like this:

  • A Spring Boot application would depend on the appropriate eventuate-common-spring-<bootversion>-reactive... and/or r2dbc library
  • Eventuate common would contain different modules for R2DBC for Spring Boot 2/3 - eventuate-common-spring-<bootversion>-reactive...
  • Hopefully, there's some portable eventuate-common-spring-reactive-... modules too, ie. code that uses SPIs that can be compiled with the older version but can run with the newer version.

@cer
Copy link
Contributor

cer commented Jan 11, 2023

MariadbConnectionConfiguration conf = MariadbConnectionConfiguration.builder()

@kwonglau Why is a MariaDB specific API needed instead of a generic ConnectionFactoryOptions?

@kwonglau
Copy link
Author

thanks for the idea. I'll try and see if this approach works.

@cer
Copy link
Contributor

cer commented Jan 11, 2023

r2dbc has change the return type for insert row count from int to long. when using spring boot 3, we need to update the code and at least re-compile.

@kwonglau Where does this change need to be made?

@kwonglau
Copy link
Author

kwonglau commented Jan 11, 2023

because .option(Option.valueOf("allowPublicKeyRetrieval"), true) doesn't work since allowPublicKeyRetrieval is not a configuration param for mariadb. it can only be configured using the api explicitly.

@cer
Copy link
Contributor

cer commented Jan 11, 2023

thanks for the idea. I'll try and see if this approach works.

BTW My preference would be to get the non-reactive Eventuate working with a Spring Boot 3 application before worrying about the reactive APIs. See comment about how the Eventuate libraries should be built/tested with Spring Boot 2 but work in a Spring Boot application.

@kwonglau
Copy link
Author

will do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants