imaffe commented on a change in pull request #555:
URL: https://github.com/apache/rocketmq-externals/pull/555#discussion_r449837535
##########
File path:
rocketmq-connect-jdbc/src/main/java/org/apache/rocketmq/connect/jdbc/common/DBUtils.java
##########
@@ -189,21 +190,21 @@ public static String quoteString(String orig, String
quote) {
}
public static DataSource initDataSource(Config config) throws Exception {
- Map<String, String> map = new HashMap<>();
- map.put("driverClassName", "com.mysql.cj.jdbc.Driver");
- map.put("url",
- "jdbc:mysql://" + config.getDbUrl() + ":" + config.getDbPort()
+
"?useSSL=true&verifyServerCertificate=false&serverTimezone=GMT%2B8&characterEncoding=utf8");
- map.put("username", config.getDbUsername());
- map.put("password", config.getDbPassword());
- map.put("initialSize", "1");
- map.put("maxActive", "2");
- map.put("maxWait", "60000");
- map.put("timeBetweenEvictionRunsMillis", "60000");
- map.put("minEvictableIdleTimeMillis", "300000");
- map.put("validationQuery", "SELECT 1 FROM DUAL");
- map.put("testWhileIdle", "true");
- log.info("{} config read successful", map);
- DataSource dataSource = DruidDataSourceFactory.createDataSource(map);
+ DruidDataSource dataSource = new DruidDataSource();
+ dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
+ dataSource.setUrl("jdbc:mysql://" + config.getDbUrl() + ":" +
config.getDbPort() +
"?useSSL=true&verifyServerCertificate=false&serverTimezone=GMT%2B8&characterEncoding=utf8");
+ dataSource.setUsername(config.getDbUsername());
+ dataSource.setPassword(config.getDbPassword());
+ dataSource.setInitialSize(1);
+ dataSource.setMaxActive(2);
+ dataSource.setMaxWait(60000);
+ dataSource.setTimeBetweenEvictionRunsMillis(60000);
+ dataSource.setConnectionErrorRetryAttempts(2);
+ dataSource.setBreakAfterAcquireFailure(true);
+ dataSource.setMinEvictableIdleTimeMillis(300000);
+ dataSource.setValidationQuery("SELECT 1 FROM DUAL");
+ dataSource.setTestWhileIdle(true);
Review comment:
I feel like using setters instead of passing in a map might be better
##########
File path:
rocketmq-connect-jdbc/src/main/java/org/apache/rocketmq/connect/jdbc/connector/JdbcSinkTask.java
##########
@@ -96,6 +96,7 @@ public void start(KeyValue props) {
log.info("init data source success");
} catch (Exception e) {
log.error("Cannot start Jdbc Sink Task because of configuration
error{}", e);
+
Review comment:
delete the empty line here
##########
File path:
rocketmq-connect-jdbc/src/main/java/org/apache/rocketmq/connect/jdbc/common/DBUtils.java
##########
@@ -189,21 +190,21 @@ public static String quoteString(String orig, String
quote) {
}
public static DataSource initDataSource(Config config) throws Exception {
- Map<String, String> map = new HashMap<>();
- map.put("driverClassName", "com.mysql.cj.jdbc.Driver");
- map.put("url",
- "jdbc:mysql://" + config.getDbUrl() + ":" + config.getDbPort()
+
"?useSSL=true&verifyServerCertificate=false&serverTimezone=GMT%2B8&characterEncoding=utf8");
- map.put("username", config.getDbUsername());
- map.put("password", config.getDbPassword());
- map.put("initialSize", "1");
- map.put("maxActive", "2");
- map.put("maxWait", "60000");
- map.put("timeBetweenEvictionRunsMillis", "60000");
- map.put("minEvictableIdleTimeMillis", "300000");
- map.put("validationQuery", "SELECT 1 FROM DUAL");
- map.put("testWhileIdle", "true");
- log.info("{} config read successful", map);
- DataSource dataSource = DruidDataSourceFactory.createDataSource(map);
+ DruidDataSource dataSource = new DruidDataSource();
+ dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
+ dataSource.setUrl("jdbc:mysql://" + config.getDbUrl() + ":" +
config.getDbPort() +
"?useSSL=true&verifyServerCertificate=false&serverTimezone=GMT%2B8&characterEncoding=utf8");
+ dataSource.setUsername(config.getDbUsername());
+ dataSource.setPassword(config.getDbPassword());
+ dataSource.setInitialSize(1);
+ dataSource.setMaxActive(2);
+ dataSource.setMaxWait(60000);
+ dataSource.setTimeBetweenEvictionRunsMillis(60000);
+ dataSource.setConnectionErrorRetryAttempts(2);
Review comment:
Ideally this parameter should be tunable.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]