canal與kafka的zkclient版本衝突

9553 [main] ERROR c.a.o.c.c.i.r.ClientRunningMonitor - There is an error when execute initRunning method, with destination [example].
java.lang.AbstractMethodError: com.alibaba.otter.canal.common.zookeeper.ZooKeeperx.writeDataReturnStat(Ljava/lang/String;[BI)Lorg/apache/zookeeper/data/Stat;
	at org.I0Itec.zkclient.ZkClient$10.call(ZkClient.java:817) ~[zkclient-0.3.jar:0.3]
	at org.I0Itec.zkclient.ZkClient.retryUntilConnected(ZkClient.java:675) ~[zkclient-0.3.jar:0.3]
	at org.I0Itec.zkclient.ZkClient.writeDataReturnStat(ZkClient.java:813) ~[zkclient-0.3.jar:0.3]
	at org.I0Itec.zkclient.ZkClient.writeData(ZkClient.java:808) ~[zkclient-0.3.jar:0.3]
	at org.I0Itec.zkclient.ZkClient.writeData(ZkClient.java:777) ~[zkclient-0.3.jar:0.3]
	at com.alibaba.otter.canal.client.impl.running.ClientRunningMonitor.processActiveEnter(ClientRunningMonitor.java:215) [canal.client-1.0.22.jar:na]
	at com.alibaba.otter.canal.client.impl.running.ClientRunningMonitor.initRunning(ClientRunningMonitor.java:118) [canal.client-1.0.22.jar:na]
	at com.alibaba.otter.canal.client.impl.running.ClientRunningMonitor.start(ClientRunningMonitor.java:92) [canal.client-1.0.22.jar:na]
	at com.alibaba.otter.canal.client.impl.SimpleCanalConnector.connect(SimpleCanalConnector.java:93) [canal.client-1.0.22.jar:na]
	at com.alibaba.otter.canal.client.impl.ClusterCanalConnector.connect(ClusterCanalConnector.java:63) [canal.client-1.0.22.jar:na]
	at com.alibaba.otter.canal.client.CanalConnector$connect.call(Unknown Source) [canal.client-1.0.22.jar:na]

canal版本:1.0.22;kafka版本:0.8.2.1;客戶端經過CanalConnectors.newClusterConnector(String zkServers, String destination, String username,String password)方法鏈接canal集羣。java

錯誤緣由:canal依賴的zkclient版本爲0.1;kafka依賴的zkclient版本爲0.3;git

0.3版本的zkclient在調用writeData方法時,會調用IZkConnection實現類ZooKeeperx(canal.common包)的writeDataReturnStat方法,而canal.client包由於是依賴0.1版本,ZooKeeperx並無writeDataReturnStat方法。github

因此當classloader加載的是0.3版本,調用writeData時,在ZooKeeperx類找不到writeDataReturnStat方法,報AbstractMethodError錯誤,最終致使鏈接canal服務端失敗。apache

解決步驟:ide

  1. canal父工程zkclient版本升級爲0.3
    <dependency>
        <artifactId>zkclient</artifactId>
        <groupId>com.101tec</groupId>
        <version>0.3</version>
        <!-- 
        <groupId>com.github.sgroschupf</groupId>
        <artifactId>zkclient</artifactId>
        <version>0.1</version>
         -->
    </dependency>

     

  2. ZooKeeperx(com.alibaba.otter.canal.common.zookeeper包下)實現writeDataReturnStat方法。
    @Override
    public Stat writeDataReturnStat(String path, byte[] data, int expectedVersion)
    			throws KeeperException, InterruptedException {
    	_zk.setData(path, data, expectedVersion);
    	return _zk.exists(path, false);
    }

     

  3. 從新打canal.common包。完成,^_^code

相關文章
相關標籤/搜索