Search in sources :

Example 6 with CanalEventParser

use of com.alibaba.otter.canal.parse.CanalEventParser in project canal by alibaba.

the class AbstractCanalInstance method subscribeChange.

@Override
public boolean subscribeChange(ClientIdentity identity) {
    if (StringUtils.isNotEmpty(identity.getFilter())) {
        logger.info("subscribe filter change to " + identity.getFilter());
        AviaterRegexFilter aviaterFilter = new AviaterRegexFilter(identity.getFilter());
        boolean isGroup = (eventParser instanceof GroupEventParser);
        if (isGroup) {
            // 处理group的模式
            List<CanalEventParser> eventParsers = ((GroupEventParser) eventParser).getEventParsers();
            for (CanalEventParser singleEventParser : eventParsers) {
                // 需要遍历启动
                if (singleEventParser instanceof AbstractEventParser) {
                    ((AbstractEventParser) singleEventParser).setEventFilter(aviaterFilter);
                }
            }
        } else {
            if (eventParser instanceof AbstractEventParser) {
                ((AbstractEventParser) eventParser).setEventFilter(aviaterFilter);
            }
        }
    }
    // 后续内存版的一对多分发,可以考虑
    return true;
}
Also used : AviaterRegexFilter(com.alibaba.otter.canal.filter.aviater.AviaterRegexFilter) CanalEventParser(com.alibaba.otter.canal.parse.CanalEventParser) AbstractEventParser(com.alibaba.otter.canal.parse.inbound.AbstractEventParser) GroupEventParser(com.alibaba.otter.canal.parse.inbound.group.GroupEventParser)

Example 7 with CanalEventParser

use of com.alibaba.otter.canal.parse.CanalEventParser in project canal by alibaba.

the class ParserCollector method groupHolder.

private GroupParserMetricsHolder groupHolder(String destination, GroupEventParser group) {
    List<CanalEventParser> parsers = group.getEventParsers();
    GroupParserMetricsHolder groupHolder = new GroupParserMetricsHolder();
    int num = parsers.size();
    for (int i = 0; i < num; i++) {
        CanalEventParser parser = parsers.get(i);
        if (parser instanceof AbstractMysqlEventParser) {
            ParserMetricsHolder single = singleHolder(destination, (AbstractMysqlEventParser) parser, Integer.toString(i + 1));
            groupHolder.holders.add(single);
        } else {
            logger.warn("Null or non AbstractMysqlEventParser, ignore.");
        }
    }
    return groupHolder;
}
Also used : AbstractMysqlEventParser(com.alibaba.otter.canal.parse.inbound.mysql.AbstractMysqlEventParser) CanalEventParser(com.alibaba.otter.canal.parse.CanalEventParser)

Example 8 with CanalEventParser

use of com.alibaba.otter.canal.parse.CanalEventParser in project canal by alibaba.

the class BaseCanalServerWithEmbededTest method testSwitch.

// @Test
public void testSwitch() {
    int maxEmptyCount = 10;
    int emptyCount = 0;
    int totalCount = 0;
    int thresold = 50;
    int batchSize = 11;
    server.subscribe(clientIdentity);
    while (emptyCount < maxEmptyCount) {
        Message message = server.get(clientIdentity, batchSize);
        if (CollectionUtils.isEmpty(message.getEntries())) {
            emptyCount++;
            try {
                Thread.sleep(emptyCount * 300L);
            } catch (InterruptedException e) {
                Assert.fail();
            }
            System.out.println("empty count : " + emptyCount);
        } else {
            emptyCount = 0;
            totalCount += message.getEntries().size();
            if ((totalCount + 1) % 100 >= thresold && (totalCount + 1) % 100 <= thresold + batchSize) {
                CanalEventParser eventParser = server.getCanalInstances().get(DESTINATION).getEventParser();
                if (eventParser instanceof CanalHASwitchable) {
                    // 执行切换
                    ((CanalHASwitchable) eventParser).doSwitch();
                    try {
                        // 等待parser启动
                        Thread.sleep(5 * 1000);
                    } catch (InterruptedException e) {
                        Assert.fail();
                    }
                }
            }
        }
    }
    System.out.println("!!!!!! testGet totalCount : " + totalCount);
    server.unsubscribe(clientIdentity);
}
Also used : Message(com.alibaba.otter.canal.protocol.Message) CanalEventParser(com.alibaba.otter.canal.parse.CanalEventParser) CanalHASwitchable(com.alibaba.otter.canal.parse.CanalHASwitchable)

Aggregations

CanalEventParser (com.alibaba.otter.canal.parse.CanalEventParser)8 CanalException (com.alibaba.otter.canal.common.CanalException)3 GroupEventParser (com.alibaba.otter.canal.parse.inbound.group.GroupEventParser)3 AviaterRegexFilter (com.alibaba.otter.canal.filter.aviater.AviaterRegexFilter)2 CanalHASwitchable (com.alibaba.otter.canal.parse.CanalHASwitchable)2 CanalHAController (com.alibaba.otter.canal.parse.ha.CanalHAController)2 AbstractEventParser (com.alibaba.otter.canal.parse.inbound.AbstractEventParser)2 AbstractMysqlEventParser (com.alibaba.otter.canal.parse.inbound.mysql.AbstractMysqlEventParser)2 MysqlEventParser (com.alibaba.otter.canal.parse.inbound.mysql.MysqlEventParser)2 AuthenticationInfo (com.alibaba.otter.canal.parse.support.AuthenticationInfo)2 Message (com.alibaba.otter.canal.protocol.Message)2 MediaHAController (com.alibaba.otter.canal.extend.ha.MediaHAController)1 CanalInstance (com.alibaba.otter.canal.instance.core.CanalInstance)1 CanalInstanceGenerator (com.alibaba.otter.canal.instance.core.CanalInstanceGenerator)1 CanalInstanceWithManager (com.alibaba.otter.canal.instance.manager.CanalInstanceWithManager)1 Canal (com.alibaba.otter.canal.instance.manager.model.Canal)1 DataSourcing (com.alibaba.otter.canal.instance.manager.model.CanalParameter.DataSourcing)1 HAMode (com.alibaba.otter.canal.instance.manager.model.CanalParameter.HAMode)1 SourcingType (com.alibaba.otter.canal.instance.manager.model.CanalParameter.SourcingType)1 LocalBinlogEventParser (com.alibaba.otter.canal.parse.inbound.mysql.LocalBinlogEventParser)1