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);
}
}
Aggregations