Search in sources :

Example 1 with ClusterNodeAccessStrategy

use of com.alibaba.otter.canal.client.impl.ClusterNodeAccessStrategy in project canal by alibaba.

the class CanalConnectors method newClusterConnector.

/**
 * 创建带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;
}
Also used : ClusterNodeAccessStrategy(com.alibaba.otter.canal.client.impl.ClusterNodeAccessStrategy) ClusterCanalConnector(com.alibaba.otter.canal.client.impl.ClusterCanalConnector)

Example 2 with ClusterNodeAccessStrategy

use of com.alibaba.otter.canal.client.impl.ClusterNodeAccessStrategy in project canal by alibaba.

the class CanalTCPConsumer method init.

@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 (StringUtils.isNotBlank(host)) {
        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)));
    }
}
Also used : ClusterNodeAccessStrategy(com.alibaba.otter.canal.client.impl.ClusterNodeAccessStrategy) InetSocketAddress(java.net.InetSocketAddress) ClusterCanalConnector(com.alibaba.otter.canal.client.impl.ClusterCanalConnector) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) SimpleCanalConnector(com.alibaba.otter.canal.client.impl.SimpleCanalConnector)

Aggregations

ClusterCanalConnector (com.alibaba.otter.canal.client.impl.ClusterCanalConnector)2 ClusterNodeAccessStrategy (com.alibaba.otter.canal.client.impl.ClusterNodeAccessStrategy)2 SimpleCanalConnector (com.alibaba.otter.canal.client.impl.SimpleCanalConnector)1 InetSocketAddress (java.net.InetSocketAddress)1 SocketAddress (java.net.SocketAddress)1