Search in sources :

Example 11 with CanalException

use of com.alibaba.otter.canal.common.CanalException in project canal by alibaba.

the class CanalRabbitMQProducer method init.

@Override
public void init(Properties properties) {
    RabbitMQProducerConfig rabbitMQProperties = new RabbitMQProducerConfig();
    this.mqProperties = rabbitMQProperties;
    super.init(properties);
    loadRabbitMQProperties(properties);
    ConnectionFactory factory = new ConnectionFactory();
    String servers = rabbitMQProperties.getHost();
    if (servers.contains(":")) {
        String[] serverHostAndPort = servers.split(":");
        factory.setHost(serverHostAndPort[0]);
        factory.setPort(Integer.parseInt(serverHostAndPort[1]));
    } else {
        factory.setHost(servers);
    }
    if (mqProperties.getAliyunAccessKey().length() > 0 && mqProperties.getAliyunSecretKey().length() > 0 && mqProperties.getAliyunUid() > 0) {
        factory.setCredentialsProvider(new AliyunCredentialsProvider(mqProperties.getAliyunAccessKey(), mqProperties.getAliyunSecretKey(), mqProperties.getAliyunUid()));
    } else {
        factory.setUsername(rabbitMQProperties.getUsername());
        factory.setPassword(rabbitMQProperties.getPassword());
    }
    factory.setVirtualHost(rabbitMQProperties.getVirtualHost());
    try {
        connect = factory.newConnection();
        channel = connect.createChannel();
    // channel.exchangeDeclare(mqProperties.getExchange(), "topic");
    } catch (IOException | TimeoutException ex) {
        throw new CanalException("Start RabbitMQ producer error", ex);
    }
}
Also used : RabbitMQProducerConfig(com.alibaba.otter.canal.connector.rabbitmq.config.RabbitMQProducerConfig) ConnectionFactory(com.rabbitmq.client.ConnectionFactory) IOException(java.io.IOException) TimeoutException(java.util.concurrent.TimeoutException) CanalException(com.alibaba.otter.canal.common.CanalException)

Example 12 with CanalException

use of com.alibaba.otter.canal.common.CanalException in project canal by alibaba.

the class CanalRabbitMQProducer method stop.

@Override
public void stop() {
    logger.info("## Stop RabbitMQ producer##");
    try {
        this.channel.close();
        this.connect.close();
        super.stop();
    } catch (AlreadyClosedException ex) {
        logger.error("Connection is already closed", ex);
    } catch (IOException | TimeoutException ex) {
        throw new CanalException("Stop RabbitMQ producer error", ex);
    }
    super.stop();
}
Also used : AlreadyClosedException(com.rabbitmq.client.AlreadyClosedException) IOException(java.io.IOException) TimeoutException(java.util.concurrent.TimeoutException) CanalException(com.alibaba.otter.canal.common.CanalException)

Example 13 with CanalException

use of com.alibaba.otter.canal.common.CanalException in project canal by alibaba.

the class CanalInstanceWithManager method initLogPositionManager.

protected CanalLogPositionManager initLogPositionManager() {
    logger.info("init logPositionPersistManager begin...");
    IndexMode indexMode = parameters.getIndexMode();
    CanalLogPositionManager logPositionManager;
    if (indexMode.isMemory()) {
        logPositionManager = new MemoryLogPositionManager();
    } else if (indexMode.isZookeeper()) {
        logPositionManager = new ZooKeeperLogPositionManager(getZkclientx());
    } else if (indexMode.isMixed()) {
        MemoryLogPositionManager memoryLogPositionManager = new MemoryLogPositionManager();
        ZooKeeperLogPositionManager zooKeeperLogPositionManager = new ZooKeeperLogPositionManager(getZkclientx());
        logPositionManager = new PeriodMixedLogPositionManager(memoryLogPositionManager, zooKeeperLogPositionManager, 1000L);
    } else if (indexMode.isMeta()) {
        logPositionManager = new MetaLogPositionManager(metaManager);
    } else if (indexMode.isMemoryMetaFailback()) {
        MemoryLogPositionManager primary = new MemoryLogPositionManager();
        MetaLogPositionManager secondary = new MetaLogPositionManager(metaManager);
        logPositionManager = new FailbackLogPositionManager(primary, secondary);
    } else {
        throw new CanalException("unsupport indexMode for " + indexMode);
    }
    logger.info("init logPositionManager end! \n\t load CanalLogPositionManager:{}", logPositionManager.getClass().getName());
    return logPositionManager;
}
Also used : MemoryLogPositionManager(com.alibaba.otter.canal.parse.index.MemoryLogPositionManager) FailbackLogPositionManager(com.alibaba.otter.canal.parse.index.FailbackLogPositionManager) CanalLogPositionManager(com.alibaba.otter.canal.parse.index.CanalLogPositionManager) MetaLogPositionManager(com.alibaba.otter.canal.parse.index.MetaLogPositionManager) IndexMode(com.alibaba.otter.canal.instance.manager.model.CanalParameter.IndexMode) ZooKeeperLogPositionManager(com.alibaba.otter.canal.parse.index.ZooKeeperLogPositionManager) PeriodMixedLogPositionManager(com.alibaba.otter.canal.parse.index.PeriodMixedLogPositionManager) CanalException(com.alibaba.otter.canal.common.CanalException)

Example 14 with CanalException

use of com.alibaba.otter.canal.common.CanalException in project canal by alibaba.

the class CanalInstanceWithManager method initHaController.

protected CanalHAController initHaController() {
    logger.info("init haController begin...");
    HAMode haMode = parameters.getHaMode();
    CanalHAController haController = null;
    if (haMode.isHeartBeat()) {
        haController = new HeartBeatHAController();
        ((HeartBeatHAController) haController).setDetectingRetryTimes(parameters.getDetectingRetryTimes());
        ((HeartBeatHAController) haController).setSwitchEnable(parameters.getHeartbeatHaEnable());
    } else {
        throw new CanalException("unsupport HAMode for " + haMode);
    }
    logger.info("init haController end! \n\t load CanalHAController:{}", haController.getClass().getName());
    return haController;
}
Also used : HeartBeatHAController(com.alibaba.otter.canal.parse.ha.HeartBeatHAController) HAMode(com.alibaba.otter.canal.instance.manager.model.CanalParameter.HAMode) CanalHAController(com.alibaba.otter.canal.parse.ha.CanalHAController) CanalException(com.alibaba.otter.canal.common.CanalException)

Example 15 with CanalException

use of com.alibaba.otter.canal.common.CanalException in project canal by alibaba.

the class SpringCanalInstanceGenerator method generate.

public CanalInstance generate(String destination) {
    synchronized (CanalEventParser.class) {
        try {
            // 设置当前正在加载的通道,加载spring查找文件时会用到该变量
            System.setProperty("canal.instance.destination", destination);
            this.beanFactory = getBeanFactory(springXml);
            String beanName = destination;
            if (!beanFactory.containsBean(beanName)) {
                beanName = defaultName;
            }
            return (CanalInstance) beanFactory.getBean(beanName);
        } catch (Throwable e) {
            logger.error("generator instance failed.", e);
            throw new CanalException(e);
        } finally {
            System.setProperty("canal.instance.destination", "");
        }
    }
}
Also used : CanalInstance(com.alibaba.otter.canal.instance.core.CanalInstance) CanalEventParser(com.alibaba.otter.canal.parse.CanalEventParser) CanalException(com.alibaba.otter.canal.common.CanalException)

Aggregations

CanalException (com.alibaba.otter.canal.common.CanalException)15 CanalEventParser (com.alibaba.otter.canal.parse.CanalEventParser)5 CanalInstance (com.alibaba.otter.canal.instance.core.CanalInstance)3 CanalHAController (com.alibaba.otter.canal.parse.ha.CanalHAController)3 Canal (com.alibaba.otter.canal.instance.manager.model.Canal)2 HAMode (com.alibaba.otter.canal.instance.manager.model.CanalParameter.HAMode)2 MysqlEventParser (com.alibaba.otter.canal.parse.inbound.mysql.MysqlEventParser)2 AuthenticationInfo (com.alibaba.otter.canal.parse.support.AuthenticationInfo)2 IOException (java.io.IOException)2 TimeoutException (java.util.concurrent.TimeoutException)2 CanalAlarmHandler (com.alibaba.otter.canal.common.alarm.CanalAlarmHandler)1 LogAlarmHandler (com.alibaba.otter.canal.common.alarm.LogAlarmHandler)1 NamedThreadFactory (com.alibaba.otter.canal.common.utils.NamedThreadFactory)1 RabbitMQProducerConfig (com.alibaba.otter.canal.connector.rabbitmq.config.RabbitMQProducerConfig)1 RocketMQProducerConfig (com.alibaba.otter.canal.connector.rocketmq.config.RocketMQProducerConfig)1 MediaHAController (com.alibaba.otter.canal.extend.ha.MediaHAController)1 AviaterRegexFilter (com.alibaba.otter.canal.filter.aviater.AviaterRegexFilter)1 CanalInstanceGenerator (com.alibaba.otter.canal.instance.core.CanalInstanceGenerator)1 CanalInstanceWithManager (com.alibaba.otter.canal.instance.manager.CanalInstanceWithManager)1 DataSourcing (com.alibaba.otter.canal.instance.manager.model.CanalParameter.DataSourcing)1