Java Code Examples for com.alibaba.otter.canal.common.zookeeper.ZkClientx#getZkClient()

The following examples show how to use com.alibaba.otter.canal.common.zookeeper.ZkClientx#getZkClient() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CanalTCPConsumer.java    From canal with Apache License 2.0 6 votes vote down vote up
@Override
public void init(Properties properties, String destination, String groupId) {
    // load config
    String host = properties.getProperty(TCPConstants.CANAL_TCP_HOST);
    String username = properties.getProperty(TCPConstants.CANAL_TCP_USERNAME);
    String password = properties.getProperty(TCPConstants.CANAL_TCP_PASSWORD);
    String zkHosts = properties.getProperty(TCPConstants.CANAL_TCP_ZK_HOSTS);
    String batchSizePro = properties.getProperty(TCPConstants.CANAL_TCP_BATCH_SIZE);
    if (batchSizePro != null) {
        batchSize = Integer.parseInt(batchSizePro);
    }
    if (host != null) {
        String[] ipPort = host.split(":");
        SocketAddress sa = new InetSocketAddress(ipPort[0], Integer.parseInt(ipPort[1]));
        this.canalConnector = new SimpleCanalConnector(sa, username, password, destination);
    } else {
        this.canalConnector = new ClusterCanalConnector(username,
            password,
            destination,
            new ClusterNodeAccessStrategy(destination, ZkClientx.getZkClient(zkHosts)));
    }
}
 
Example 2
Source File: CanalInstanceWithManager.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
private synchronized ZkClientx getZkclientx() {
    // 做一下排序,保证相同的机器只使用同一个链接
    List<String> zkClusters = new ArrayList<String>(parameters.getZkClusters());
    Collections.sort(zkClusters);

    return ZkClientx.getZkClient(StringUtils.join(zkClusters, ";"));
}
 
Example 3
Source File: CanalConnectors.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
/**
 * 创建带cluster模式的客户端链接,自动完成failover切换,服务器列表自动扫描
 *
 * @param zkServers
 * @param destination
 * @param username
 * @param password
 * @return
 */
public static CanalConnector newClusterConnector(String zkServers, String destination, String username,
                                                 String password) {
    ClusterCanalConnector canalConnector = new ClusterCanalConnector(username,
        password,
        destination,
        new ClusterNodeAccessStrategy(destination, ZkClientx.getZkClient(zkServers)));
    canalConnector.setSoTimeout(60 * 1000);
    canalConnector.setIdleTimeout(60 * 60 * 1000);
    return canalConnector;
}
 
Example 4
Source File: CanalInstanceWithManager.java    From canal with Apache License 2.0 5 votes vote down vote up
private synchronized ZkClientx getZkclientx() {
    // 做一下排序,保证相同的机器只使用同一个链接
    List<String> zkClusters = new ArrayList<String>(parameters.getZkClusters());
    Collections.sort(zkClusters);

    return ZkClientx.getZkClient(StringUtils.join(zkClusters, ";"));
}
 
Example 5
Source File: CanalConnectors.java    From canal with Apache License 2.0 5 votes vote down vote up
/**
 * 创建带cluster模式的客户端链接,自动完成failover切换,服务器列表自动扫描
 *
 * @param zkServers
 * @param destination
 * @param username
 * @param password
 * @return
 */
public static CanalConnector newClusterConnector(String zkServers, String destination, String username,
                                                 String password) {
    ClusterCanalConnector canalConnector = new ClusterCanalConnector(username,
        password,
        destination,
        new ClusterNodeAccessStrategy(destination, ZkClientx.getZkClient(zkServers)));
    canalConnector.setSoTimeout(60 * 1000);
    canalConnector.setIdleTimeout(60 * 60 * 1000);
    return canalConnector;
}