Search in sources :

Example 1 with NamedThreadFactory

use of com.alibaba.otter.canal.common.utils.NamedThreadFactory in project canal by alibaba.

the class CanalPulsarMQProducer method init.

@Override
public void init(Properties properties) {
    // 加载配置
    PulsarMQProducerConfig pulsarMQProducerConfig = new PulsarMQProducerConfig();
    this.mqProperties = pulsarMQProducerConfig;
    super.init(properties);
    loadPulsarMQProperties(properties);
    // 初始化连接客户端
    try {
        client = PulsarClient.builder().serviceUrl(pulsarMQProducerConfig.getServerUrl()).authentication(AuthenticationFactory.token(pulsarMQProducerConfig.getRoleToken())).build();
    } catch (PulsarClientException e) {
        throw new RuntimeException(e);
    }
    // 加载所有生产者 --> topic可能有正则或表名,无法确认所有topic,在使用时再加载
    int parallelPartitionSendThreadSize = mqProperties.getParallelSendThreadSize();
    sendPartitionExecutor = new ThreadPoolExecutor(parallelPartitionSendThreadSize, parallelPartitionSendThreadSize, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<>(parallelPartitionSendThreadSize * 2), new NamedThreadFactory("MQ-Parallel-Sender-Partition"), new ThreadPoolExecutor.CallerRunsPolicy());
}
Also used : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) NamedThreadFactory(com.alibaba.otter.canal.common.utils.NamedThreadFactory) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) PulsarMQProducerConfig(com.alibaba.otter.canal.connector.pulsarmq.config.PulsarMQProducerConfig)

Example 2 with NamedThreadFactory

use of com.alibaba.otter.canal.common.utils.NamedThreadFactory in project canal by alibaba.

the class AbstractMQProducer method init.

@Override
public void init(Properties properties) {
    // parse canal mq properties
    loadCanalMqProperties(properties);
    int parallelBuildThreadSize = mqProperties.getParallelBuildThreadSize();
    buildExecutor = new ThreadPoolExecutor(parallelBuildThreadSize, parallelBuildThreadSize, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<>(parallelBuildThreadSize * 2), new NamedThreadFactory("MQ-Parallel-Builder"), new ThreadPoolExecutor.CallerRunsPolicy());
    int parallelSendThreadSize = mqProperties.getParallelSendThreadSize();
    sendExecutor = new ThreadPoolExecutor(parallelSendThreadSize, parallelSendThreadSize, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<>(parallelSendThreadSize * 2), new NamedThreadFactory("MQ-Parallel-Sender"), new ThreadPoolExecutor.CallerRunsPolicy());
}
Also used : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) NamedThreadFactory(com.alibaba.otter.canal.common.utils.NamedThreadFactory) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 3 with NamedThreadFactory

use of com.alibaba.otter.canal.common.utils.NamedThreadFactory in project canal by alibaba.

the class MysqlMultiStageCoprocessor method start.

@Override
public void start() {
    super.start();
    this.exception = null;
    this.disruptorMsgBuffer = RingBuffer.createSingleProducer(new MessageEventFactory(), ringBufferSize, new BlockingWaitStrategy());
    int tc = parserThreadCount > 0 ? parserThreadCount : 1;
    this.parserExecutor = Executors.newFixedThreadPool(tc, new NamedThreadFactory("MultiStageCoprocessor-Parser-" + destination));
    this.stageExecutor = Executors.newFixedThreadPool(2, new NamedThreadFactory("MultiStageCoprocessor-other-" + destination));
    SequenceBarrier sequenceBarrier = disruptorMsgBuffer.newBarrier();
    ExceptionHandler exceptionHandler = new SimpleFatalExceptionHandler();
    // stage 2
    this.logContext = new LogContext();
    simpleParserStage = new BatchEventProcessor<>(disruptorMsgBuffer, sequenceBarrier, new SimpleParserStage(logContext));
    simpleParserStage.setExceptionHandler(exceptionHandler);
    disruptorMsgBuffer.addGatingSequences(simpleParserStage.getSequence());
    // stage 3
    SequenceBarrier dmlParserSequenceBarrier = disruptorMsgBuffer.newBarrier(simpleParserStage.getSequence());
    WorkHandler<MessageEvent>[] workHandlers = new DmlParserStage[tc];
    for (int i = 0; i < tc; i++) {
        workHandlers[i] = new DmlParserStage();
    }
    workerPool = new WorkerPool<MessageEvent>(disruptorMsgBuffer, dmlParserSequenceBarrier, exceptionHandler, workHandlers);
    Sequence[] sequence = workerPool.getWorkerSequences();
    disruptorMsgBuffer.addGatingSequences(sequence);
    // stage 4
    SequenceBarrier sinkSequenceBarrier = disruptorMsgBuffer.newBarrier(sequence);
    sinkStoreStage = new BatchEventProcessor<>(disruptorMsgBuffer, sinkSequenceBarrier, new SinkStoreStage());
    sinkStoreStage.setExceptionHandler(exceptionHandler);
    disruptorMsgBuffer.addGatingSequences(sinkStoreStage.getSequence());
    // start work
    stageExecutor.submit(simpleParserStage);
    stageExecutor.submit(sinkStoreStage);
    workerPool.start(parserExecutor);
}
Also used : BlockingWaitStrategy(com.lmax.disruptor.BlockingWaitStrategy) NamedThreadFactory(com.alibaba.otter.canal.common.utils.NamedThreadFactory) SequenceBarrier(com.lmax.disruptor.SequenceBarrier) LogContext(com.taobao.tddl.dbsync.binlog.LogContext) Sequence(com.lmax.disruptor.Sequence) ExceptionHandler(com.lmax.disruptor.ExceptionHandler) WorkHandler(com.lmax.disruptor.WorkHandler)

Example 4 with NamedThreadFactory

use of com.alibaba.otter.canal.common.utils.NamedThreadFactory in project canal by alibaba.

the class CanalRocketMQProducer method init.

@Override
public void init(Properties properties) {
    RocketMQProducerConfig rocketMQProperties = new RocketMQProducerConfig();
    this.mqProperties = rocketMQProperties;
    super.init(properties);
    loadRocketMQProperties(properties);
    RPCHook rpcHook = null;
    if (mqProperties.getAliyunAccessKey().length() > 0 && mqProperties.getAliyunSecretKey().length() > 0) {
        SessionCredentials sessionCredentials = new SessionCredentials();
        sessionCredentials.setAccessKey(mqProperties.getAliyunAccessKey());
        sessionCredentials.setSecretKey(mqProperties.getAliyunSecretKey());
        rpcHook = new AclClientRPCHook(sessionCredentials);
    }
    defaultMQProducer = new DefaultMQProducer(rocketMQProperties.getProducerGroup(), rpcHook, rocketMQProperties.isEnableMessageTrace(), rocketMQProperties.getCustomizedTraceTopic());
    if (CLOUD_ACCESS_CHANNEL.equals(rocketMQProperties.getAccessChannel())) {
        defaultMQProducer.setAccessChannel(AccessChannel.CLOUD);
    }
    if (!StringUtils.isEmpty(rocketMQProperties.getNamespace())) {
        defaultMQProducer.setNamespace(rocketMQProperties.getNamespace());
    }
    defaultMQProducer.setNamesrvAddr(rocketMQProperties.getNamesrvAddr());
    defaultMQProducer.setRetryTimesWhenSendFailed(rocketMQProperties.getRetryTimesWhenSendFailed());
    defaultMQProducer.setVipChannelEnabled(rocketMQProperties.isVipChannelEnabled());
    logger.info("##Start RocketMQ producer##");
    try {
        defaultMQProducer.start();
    } catch (MQClientException ex) {
        throw new CanalException("Start RocketMQ producer error", ex);
    }
    int parallelPartitionSendThreadSize = mqProperties.getParallelSendThreadSize();
    sendPartitionExecutor = new ThreadPoolExecutor(parallelPartitionSendThreadSize, parallelPartitionSendThreadSize, 0, TimeUnit.SECONDS, new ArrayBlockingQueue<>(parallelPartitionSendThreadSize * 2), new NamedThreadFactory("MQ-Parallel-Sender-Partition"), new ThreadPoolExecutor.CallerRunsPolicy());
}
Also used : SessionCredentials(org.apache.rocketmq.acl.common.SessionCredentials) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) NamedThreadFactory(com.alibaba.otter.canal.common.utils.NamedThreadFactory) RocketMQProducerConfig(com.alibaba.otter.canal.connector.rocketmq.config.RocketMQProducerConfig) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) RPCHook(org.apache.rocketmq.remoting.RPCHook) AclClientRPCHook(org.apache.rocketmq.acl.common.AclClientRPCHook) DefaultMQProducer(org.apache.rocketmq.client.producer.DefaultMQProducer) AclClientRPCHook(org.apache.rocketmq.acl.common.AclClientRPCHook) MQClientException(org.apache.rocketmq.client.exception.MQClientException) CanalException(com.alibaba.otter.canal.common.CanalException)

Aggregations

NamedThreadFactory (com.alibaba.otter.canal.common.utils.NamedThreadFactory)4 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)3 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)3 CanalException (com.alibaba.otter.canal.common.CanalException)1 PulsarMQProducerConfig (com.alibaba.otter.canal.connector.pulsarmq.config.PulsarMQProducerConfig)1 RocketMQProducerConfig (com.alibaba.otter.canal.connector.rocketmq.config.RocketMQProducerConfig)1 BlockingWaitStrategy (com.lmax.disruptor.BlockingWaitStrategy)1 ExceptionHandler (com.lmax.disruptor.ExceptionHandler)1 Sequence (com.lmax.disruptor.Sequence)1 SequenceBarrier (com.lmax.disruptor.SequenceBarrier)1 WorkHandler (com.lmax.disruptor.WorkHandler)1 LogContext (com.taobao.tddl.dbsync.binlog.LogContext)1 AclClientRPCHook (org.apache.rocketmq.acl.common.AclClientRPCHook)1 SessionCredentials (org.apache.rocketmq.acl.common.SessionCredentials)1 MQClientException (org.apache.rocketmq.client.exception.MQClientException)1 DefaultMQProducer (org.apache.rocketmq.client.producer.DefaultMQProducer)1 RPCHook (org.apache.rocketmq.remoting.RPCHook)1