开发者社区> 问答> 正文

客户端链接报错:CanalClientException: java.net.ConnectExce

com.alibaba.otter.canal.protocol.exception.CanalClientException: java.net.ConnectException: Connection timed out: connect at com.alibaba.otter.canal.client.impl.SimpleCanalConnector.doConnect(SimpleCanalConnector.java:189) at com.alibaba.otter.canal.client.impl.SimpleCanalConnector.access$000(SimpleCanalConnector.java:50) at com.alibaba.otter.canal.client.impl.SimpleCanalConnector$1.processActiveEnter(SimpleCanalConnector.java:422) at com.alibaba.otter.canal.client.impl.running.ClientRunningMonitor.processActiveEnter(ClientRunningMonitor.java:211) at com.alibaba.otter.canal.client.impl.running.ClientRunningMonitor.initRunning(ClientRunningMonitor.java:122) at com.alibaba.otter.canal.client.impl.running.ClientRunningMonitor.start(ClientRunningMonitor.java:92) at com.alibaba.otter.canal.client.impl.SimpleCanalConnector.connect(SimpleCanalConnector.java:106) at com.alibaba.otter.canal.client.impl.ClusterCanalConnector.connect(ClusterCanalConnector.java:64) at com.syj.test.canal.ClientSample.main(ClientSample.java:28) Caused by: java.net.ConnectException: Connection timed out: connect at sun.nio.ch.Net.connect0(Native Method) at sun.nio.ch.Net.connect(Net.java:458) at sun.nio.ch.Net.connect(Net.java:450) at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:648) at com.alibaba.otter.canal.client.impl.SimpleCanalConnector.doConnect(SimpleCanalConnector.java:148) ... 8 common frames omitted

配置信息:

canal server版本1.1.1,client版本1.1.1 运行canal的机器: 11.182.61.18 , 10.182.61.51 zookeeper地址为:11.182.29.191:2181 问题描述:在canal HA模式下,canal server服务端在机器A上,启动OK,在机器A上启动client也OK,但是在机器B上启动client就报如上错误! 💥 为什么机器B connect失败??? 💥

机器A 能ping 通,端口11111也开放 get /otter/canal/destinations/example/running --> {"active":true,"address":"11.182.61.18:11111","cid":1} 客户端代码如下:

public static void main(String args[]) { // 创建链接 CanalConnector connector = CanalConnectors.newClusterConnector("11.182.29.191:2181", "example", "", ""); int batchSize = 1000; int emptyCount = 0; try { connector.connect(); connector.subscribe(".\.."); connector.rollback(); int totalEmtryCount = 1200; while (emptyCount < totalEmtryCount) { Message message = connector.getWithoutAck(batchSize); // 获取指定数量的数据 long batchId = message.getId(); int size = message.getEntries().size(); if (batchId == -1 || size == 0) { emptyCount++; System.out.println("empty count : " + emptyCount); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } else { emptyCount = 0; // System.out.printf("message[batchId=%s,size=%s] \n", batchId, size); printEntry(message.getEntries()); }

            connector.ack(batchId); // 提交确认
            // connector.rollback(batchId); // 处理失败, 回滚数据
        }

        System.out.println("empty too many times, exit");
    } finally {
        connector.disconnect();
    }
}

原提问者GitHub用户yjshi2015

展开
收起
Java工程师 2023-05-08 17:43:53 134 0
1 条回答
写回答
取消 提交回答
  • java.net.ConnectException: Connection timed out: connect

    这个我建议先查网络问题

    原回答者GitHub用户agapple

    2023-05-09 18:40:36
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Spring Cloud Alibaba - 重新定义 Java Cloud-Native 立即下载
The Reactive Cloud Native Arch 立即下载
JAVA开发手册1.5.0 立即下载