Java Code Examples for com.alibaba.otter.canal.client.CanalConnector#disconnect()
The following examples show how to use
com.alibaba.otter.canal.client.CanalConnector#disconnect() .
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: MutiCanalFactory.java From database-transform-tool with Apache License 2.0 | 5 votes |
/** * 关闭服务 */ public static void close(){ if(!cache.isEmpty()){ for (CanalConnector connector : cache.values()) { connector.disconnect(); } } }
Example 2
Source File: CaseController.java From skywalking with Apache License 2.0 | 5 votes |
private void wrapCreateConnector(String destination, Consumer<CanalConnector> consumer) { CanalConnector connector = CanalConnectors.newSingleConnector(new InetSocketAddress(address, port), destination, "", ""); connector.connect(); try { consumer.accept(connector); } finally { connector.disconnect(); } }
Example 3
Source File: SimpleCanalClientExample.java From DBus with Apache License 2.0 | 4 votes |
public static void main(String args[]) { //args = new String[]{"vdbus-4", "10000", "mysql_db2"}; args = new String[]{"vdbus-4", "10000", "mysql_db2"}; if (args.length != 3) { System.out.println("args: dbus-n1 11111 testdb"); return; } String ip = args[0]; int port = Integer.parseInt(args[1]); String dbname = args[2]; // 创建链接 CanalConnector connector = null; int batchSize = 1000; int emptyCount = 0; try { connector = CanalConnectors.newSingleConnector(new InetSocketAddress(ip, port), dbname, "", ""); //connector = CanalConnectors.newClusterConnector("vdbus-7:2181/DBus/Canal/mysql_db1", dbname, "", ""); connector.connect(); connector.subscribe(""); connector.rollback(); int totalEmtryCount = 120; 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.print("."); try { Thread.sleep(1000); } catch (InterruptedException e) { } } else { emptyCount = 0; // System.out.printf("message[batchId=%s,size=%s] \n", batchId, size); System.out.println(""); printEntry(message.getEntries(), batchId); } connector.ack(batchId); // 提交确认 // connector.rollback(batchId); // 处理失败, 回滚数据 } System.out.println("empty too many times, exit"); } finally { if (connector != null) { connector.disconnect(); } } }