Search in sources :

Example 1 with MySqlJdbcContext

use of io.debezium.connector.mysql.MySqlJdbcContext in project eventuate-local by eventuate-local.

the class DebeziumCdcStartupValidator method validateDatasourceConnection.

private void validateDatasourceConnection() {
    logger.info("About to validate DataSource connection");
    Map<String, String> connectorConfig = new HashMap<>();
    connectorConfig.put(MySqlConnectorConfig.HOSTNAME.name(), jdbcUrl.getHost());
    connectorConfig.put(MySqlConnectorConfig.PORT.name(), String.valueOf(jdbcUrl.getPort()));
    connectorConfig.put(MySqlConnectorConfig.USER.name(), dbUser);
    connectorConfig.put(MySqlConnectorConfig.PASSWORD.name(), dbPassword);
    Configuration config = Configuration.from(connectorConfig);
    try (MySqlJdbcContext jdbcContext = new MySqlJdbcContext(config)) {
        jdbcContext.start();
        JdbcConnection mysql = jdbcContext.jdbc();
        int i = mySqlValidationMaxAttempts;
        SQLException lastException = null;
        while (i > 0) {
            try {
                mysql.execute("SELECT version()");
                logger.info("Successfully tested connection for {}:{} with user '{}'", jdbcContext.hostname(), jdbcContext.port(), mysql.username());
                return;
            } catch (SQLException e) {
                lastException = e;
                logger.info("Failed testing connection for {}:{} with user '{}'", jdbcContext.hostname(), jdbcContext.port(), mysql.username());
                i--;
                try {
                    Thread.sleep(mySqlValidationTimeoutMillis);
                } catch (InterruptedException ie) {
                    throw new RuntimeException("MySql validation had been interrupted!", ie);
                }
            }
        }
        jdbcContext.shutdown();
        throw new RuntimeException(lastException);
    }
}
Also used : Configuration(io.debezium.config.Configuration) HashMap(java.util.HashMap) MySqlJdbcContext(io.debezium.connector.mysql.MySqlJdbcContext) SQLException(java.sql.SQLException) JdbcConnection(io.debezium.jdbc.JdbcConnection)

Aggregations

Configuration (io.debezium.config.Configuration)1 MySqlJdbcContext (io.debezium.connector.mysql.MySqlJdbcContext)1 JdbcConnection (io.debezium.jdbc.JdbcConnection)1 SQLException (java.sql.SQLException)1 HashMap (java.util.HashMap)1