com.alibaba.otter.canal.client.impl.ClusterNodeAccessStrategy Java Examples

The following examples show how to use com.alibaba.otter.canal.client.impl.ClusterNodeAccessStrategy. 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: 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 #3
Source File: ClusterNodeConstructInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {

    String clusterPath = ZookeeperPathUtils.getDestinationClusterRoot(allArguments[0].toString());
    ZkClientx zkClientx = ((ClusterNodeAccessStrategy) objInst).getZkClient();
    ContextManager.getRuntimeContext().put("currentAddress", getCurrentAddress(zkClientx.getChildren(clusterPath)));

}
 
Example #4
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;
}