MAPREDUCE服务 MRS-建立ClickHouse连接

时间:2024-10-18 17:22:17

建立ClickHouse连接

以下代码片段在“ClickhouseJDBCHaDemo”类的initConnection方法中。在创建连接时传入表1中配置的user和password作为认证凭据,ClickHouse会带着用户名和密码在服务端进行安全认证。

MRS 3.3.0之前版本:

clickHouseProperties.setPassword(userPass);
clickHouseProperties.setUser(userName);
BalancedClickhouseDataSource balancedClickhouseDataSource = new BalancedClickhouseDataSource(JDBC_PREFIX + UriList, clickHouseProperties);

MRS 3.3.0及之后版本:

clickHouseProperties.setProperty(ClickHouseDefaults.USER.getKey(), userName);
clickHouseProperties.setProperty(ClickHouseDefaults.PASSWORD.getKey(), userPass);
try {
    clickHouseProperties.setProperty(ClickHouseClientOption.FAILOVER.getKey(), "21");
    clickHouseProperties.setProperty(ClickHouseClientOption.LOAD_BALANCING_POLICY.getKey(), "roundRobin");
    balancedClickhouseDataSource = new ClickHouseDataSource(JDBC_PREFIX + UriList, clickHouseProperties);
} catch (Exception e) {
     LOG .error("Failed to create balancedClickHouseProperties.");
    throw e;
}
support.huaweicloud.com/devg-lts-mrs/mrs_07_480014.html