当前位置: 首页>>代码示例>>Java>>正文


Java CanalConnectors.newSingleConnector方法代码示例

本文整理汇总了Java中com.alibaba.otter.canal.client.CanalConnectors.newSingleConnector方法的典型用法代码示例。如果您正苦于以下问题:Java CanalConnectors.newSingleConnector方法的具体用法?Java CanalConnectors.newSingleConnector怎么用?Java CanalConnectors.newSingleConnector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.alibaba.otter.canal.client.CanalConnectors的用法示例。


在下文中一共展示了CanalConnectors.newSingleConnector方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import com.alibaba.otter.canal.client.CanalConnectors; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException {

        CanalConnector connector = CanalConnectors.newSingleConnector(new InetSocketAddress("127.0.0.1", 11111),
                "totoro",
                "",
                "");

        connector.connect();
        connector.subscribe();
        int emptyTimes = 0;

        while (running) {
            Message message = connector.getWithoutAck(5 * 1024);

            if (message == null || message.getId() == -1L) {
                applyWait(emptyTimes++);
            } else {
                //logger.info(message.toString());
                long messageId = message.getId();
                System.out.println("消息id:" + messageId);
                Thread.sleep(1000);

                connector.rollback();
            }


        }

    }
 
开发者ID:zhongchengxcr,项目名称:canal-elasticsearch,代码行数:30,代码来源:LockTest.java

示例2: CanalEmbedSelector

import com.alibaba.otter.canal.client.CanalConnectors; //导入方法依赖的package包/类
public CanalEmbedSelector(CanalConf conf) {

        logger.info("TotoroSelector init start  , conf :{}", conf.toString());

        this.mode = conf.getMode();
        this.destination = conf.getDestination();
        this.filterPatten = conf.getFilterPatten();

        String userName = conf.getUserName();
        String passWord = conf.getPassWord();

        if (Mode.SIGN.equals(mode)) {
            String address = conf.getAddress();

            String[] hostPort = address.split(":");

            String ip = hostPort[0];
            Integer port = Integer.valueOf(hostPort[1]);

            SocketAddress socketAddress = new InetSocketAddress(ip, port);

            connector = CanalConnectors.newSingleConnector(socketAddress,
                    destination,
                    userName,
                    passWord);

        } else if (Mode.CLUSTER.equals(mode)) {
            String zkAddress = conf.getZkAddress();
            connector = CanalConnectors.newClusterConnector(zkAddress, destination, userName, passWord);
        } else {
            throw new TotoroException("Invalid mode");
        }
        logger.info("TotoroSelector init complete .......");
    }
 
开发者ID:zhongchengxcr,项目名称:canal-elasticsearch,代码行数:35,代码来源:CanalEmbedSelector.java

示例3: initConector

import com.alibaba.otter.canal.client.CanalConnectors; //导入方法依赖的package包/类
public void initConector() {
    if (canalConfig == null) {
        throw new IllegalArgumentException("CustomSimpleCanalClient canalConfig property is empty!");
    }
    if ((invokeMap == null || invokeMap.isEmpty())&& this.globalInvoke==null) {
        throw new IllegalArgumentException("CustomSimpleCanalClient invokeMap property is empty!");
    }
    if (canalConfig instanceof SingleCanalConfig) {
        String socketStr = ((SingleCanalConfig) canalConfig).getSocketAddress();
        logger.info("canal will connection to {}.", socketStr);
        connector = CanalConnectors.newSingleConnector(this.getSocketAddressByString(socketStr),
                canalConfig.getDestination(), canalConfig.getUsername(), canalConfig.getPassword());
    } else if (canalConfig instanceof SocketsClusterCanalConfig) {
        List<SocketAddress> socketAddressList = new ArrayList<SocketAddress>();
        for (String sok : ((SocketsClusterCanalConfig) canalConfig).getSocketAddress()) {
            logger.info("canal will connection to {}.", sok);
            socketAddressList.add(this.getSocketAddressByString(sok));
        }
        connector = CanalConnectors.newClusterConnector(socketAddressList,
                canalConfig.getDestination(), canalConfig.getUsername(), canalConfig.getPassword());
    } else if (canalConfig instanceof ZkClusterCanalConfig) {
        String zkAddress = ((ZkClusterCanalConfig) canalConfig).getZkAddress();
        logger.info("canal will connection to {}.", zkAddress);
        connector = CanalConnectors.newClusterConnector(zkAddress,
                canalConfig.getDestination(), canalConfig.getUsername(), canalConfig.getPassword());
    }
    connector.connect();
    connector.subscribe(canalConfig.getSubscribeChannel());
    connector.rollback();
}
 
开发者ID:fanqinghui,项目名称:canal-client,代码行数:31,代码来源:CustomSimpleCanalClient.java

示例4: main

import com.alibaba.otter.canal.client.CanalConnectors; //导入方法依赖的package包/类
public static void main(String args[]) {
    // 根据ip,直接创建链接,无HA的功能
    String destination = "example";
    String ip = AddressUtils.getHostIp();
    CanalConnector connector = CanalConnectors.newSingleConnector(new InetSocketAddress(ip, 11111),
        destination,
        "",
        "");

    final SimpleCanalClientTest clientTest = new SimpleCanalClientTest(destination);
    clientTest.setConnector(connector);
    clientTest.start();
    Runtime.getRuntime().addShutdownHook(new Thread() {

        public void run() {
            try {
                logger.info("## stop the canal client");
                clientTest.stop();
            } catch (Throwable e) {
                logger.warn("##something goes wrong when stopping canal:", e);
            } finally {
                logger.info("## canal client is down.");
            }
        }

    });
}
 
开发者ID:alibaba,项目名称:canal,代码行数:28,代码来源:SimpleCanalClientTest.java

示例5: init

import com.alibaba.otter.canal.client.CanalConnectors; //导入方法依赖的package包/类
/**
 * @description Canal服务配置
 * @author yi.zhang
 * @time 2017年4月19日 上午10:38:42
 * @throws Exception
 */
public void init(String destinations,String servers,String username,String password,String filter_regex,boolean isZookeeper,Integer batch_size){
	try {
		if(filter_regex!=null){
			CANAL_FILTER_REGEX = filter_regex;
		}
		if(batch_size!=null){
			BATCH_SIZE = batch_size;
		}
		if(servers==null||"".equals(servers)){
			return;
		}
		if(destinations!=null&&!"".equals(destinations)){
			for(String destination:destinations.split(",")){
				if(destination==null||"".equals(destination)){
					continue;
				}
				CanalConnector connector = null;
				if(isZookeeper){
					connector = CanalConnectors.newClusterConnector(servers, destination, username, password);
				}else{
					List<SocketAddress> addresses = new ArrayList<SocketAddress>();
					for(String address : servers.split(",")){
						String[] ips = address.split(":");
						String ip = ips[0];
						int port=11111;
						if(ips.length>1){
							port = Integer.valueOf(ips[1]);
						}
						addresses.add(new InetSocketAddress(ip, port));
					}
					if(addresses!=null&&addresses.size()==1){
						connector = CanalConnectors.newSingleConnector(addresses.get(0), destination, username, password);
					}else{
						connector = CanalConnectors.newClusterConnector(addresses, destination, username, password);
					}
				}
				connector.connect();
		        connector.subscribe(CANAL_FILTER_REGEX);
		        connector.rollback();
		        cache.put(destination, connector);
			}
		}
	} catch (Exception e) {
		logger.error("-----Muti Canal Config init Error-----", e);
	}
}
 
开发者ID:dev-share,项目名称:database-transform-tool,代码行数:53,代码来源:MutiCanalFactory.java

示例6: create

import com.alibaba.otter.canal.client.CanalConnectors; //导入方法依赖的package包/类
@Override
public CanalConnector create(String instanceName) {
    return CanalConnectors.newSingleConnector(address, instanceName, null, null);
}
 
开发者ID:wxingyl,项目名称:search-commons,代码行数:5,代码来源:Schemas.java


注:本文中的com.alibaba.otter.canal.client.CanalConnectors.newSingleConnector方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。