本文整理汇总了Java中com.alibaba.otter.canal.client.CanalConnectors.newClusterConnector方法的典型用法代码示例。如果您正苦于以下问题:Java CanalConnectors.newClusterConnector方法的具体用法?Java CanalConnectors.newClusterConnector怎么用?Java CanalConnectors.newClusterConnector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.otter.canal.client.CanalConnectors
的用法示例。
在下文中一共展示了CanalConnectors.newClusterConnector方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initCanalStart
import com.alibaba.otter.canal.client.CanalConnectors; //导入方法依赖的package包/类
public void initCanalStart() {
List<String> destinations = canalProperties.getDestination();
final List<CanalClient> canalClientList = new ArrayList<>();
if (destinations != null && destinations.size() > 0) {
for (String destination : destinations) {
// 基于zookeeper动态获取canal server的地址,建立链接,其中一台server发生crash,可以支持failover
CanalConnector connector = CanalConnectors.newClusterConnector(canalProperties.getZkServers(), destination, "", "");
CanalClient client = new CanalClient(destination, connector);
canalClientList.add(client);
client.start();
}
}
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
try {
logger.info("## stop the canal client");
for (CanalClient canalClient : canalClientList) {
canalClient.stop();
}
} catch (Throwable e) {
logger.warn("##something goes wrong when stopping canal:", e);
} finally {
logger.info("## canal client is down.");
}
}
});
}
示例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 .......");
}
示例3: 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 destination,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(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));
}
connector = CanalConnectors.newClusterConnector(addresses, destination, username, password);
}
connector.connect();
connector.subscribe(CANAL_FILTER_REGEX);
connector.rollback();
} catch (Exception e) {
logger.error("-----Canal Config init Error-----", e);
}
}
示例4: 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();
}
示例5: getCanalConnector
import com.alibaba.otter.canal.client.CanalConnectors; //导入方法依赖的package包/类
@Bean
public CanalConnector getCanalConnector() {
canalConnector = CanalConnectors.newClusterConnector(Lists.newArrayList(new InetSocketAddress(canalHost, Integer.valueOf(canalPort))), canalDestination, canalUsername, canalPassword);
canalConnector.connect();
// 指定filter,格式 {database}.{table},这里不做过滤,过滤操作留给用户
canalConnector.subscribe();
// 回滚寻找上次中断的位置
canalConnector.rollback();
logger.info("canal客户端启动成功");
return canalConnector;
}
示例6: main
import com.alibaba.otter.canal.client.CanalConnectors; //导入方法依赖的package包/类
public static void main(String args[]) {
String destination = "example";
// 基于固定canal server的地址,建立链接,其中一台server发生crash,可以支持failover
// CanalConnector connector = CanalConnectors.newClusterConnector(
// Arrays.asList(new InetSocketAddress(
// AddressUtils.getHostIp(),
// 11111)),
// "stability_test", "", "");
// 基于zookeeper动态获取canal server的地址,建立链接,其中一台server发生crash,可以支持failover
CanalConnector connector = CanalConnectors.newClusterConnector("127.0.0.1:2181", destination, "", "");
final ClusterCanalClientTest clientTest = new ClusterCanalClientTest(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.");
}
}
});
}
示例7: getConnector
import com.alibaba.otter.canal.client.CanalConnectors; //导入方法依赖的package包/类
private CanalConnector getConnector(String zkServers, String destination, String username, String password) {
return CanalConnectors.newClusterConnector(zkServers, destination, username, password);
}
示例8: 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);
}
}
示例9: create
import com.alibaba.otter.canal.client.CanalConnectors; //导入方法依赖的package包/类
@Override
public CanalConnector create(String instanceName) {
return CanalConnectors.newClusterConnector(addresses, instanceName, null, null);
}