Skip to content

Commit

Permalink
[ISSUE #554] Update druid version and set ConnectionErrorRetryAttempts
Browse files Browse the repository at this point in the history
  • Loading branch information
imaffe authored Jul 6, 2020
1 parent a1f2ff2 commit 9849db6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.31</version>
<version>1.1.22</version>
</dependency>

</dependencies>
Expand Down
31 changes: 16 additions & 15 deletions src/main/java/org/apache/rocketmq/connect/jdbc/common/DBUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.rocketmq.connect.jdbc.common;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.apache.rocketmq.connect.jdbc.config.Config;
import org.apache.rocketmq.connect.jdbc.connector.JdbcSourceTask;
Expand Down Expand Up @@ -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);

log.info("init data source success");
return dataSource;
}
Expand Down

0 comments on commit 9849db6

Please sign in to comment.