Search in sources :

Example 1 with GroupEventParser

use of com.alibaba.otter.canal.parse.inbound.group.GroupEventParser 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) {
                // 需要遍历启动
                ((AbstractEventParser) singleEventParser).setEventFilter(aviaterFilter);
            }
        } else {
            ((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 2 with GroupEventParser

use of com.alibaba.otter.canal.parse.inbound.group.GroupEventParser in project canal by alibaba.

the class CanalInstanceWithManager method initEventParser.

protected void initEventParser() {
    logger.info("init eventParser begin...");
    SourcingType type = parameters.getSourcingType();
    List<List<DataSourcing>> groupDbAddresses = parameters.getGroupDbAddresses();
    if (!CollectionUtils.isEmpty(groupDbAddresses)) {
        // 取第一个分组的数量,主备分组的数量必须一致
        int size = groupDbAddresses.get(0).size();
        List<CanalEventParser> eventParsers = new ArrayList<CanalEventParser>();
        for (int i = 0; i < size; i++) {
            List<InetSocketAddress> dbAddress = new ArrayList<InetSocketAddress>();
            SourcingType lastType = null;
            for (List<DataSourcing> groupDbAddress : groupDbAddresses) {
                if (lastType != null && !lastType.equals(groupDbAddress.get(i).getType())) {
                    throw new CanalException(String.format("master/slave Sourcing type is unmatch. %s vs %s", lastType, groupDbAddress.get(i).getType()));
                }
                lastType = groupDbAddress.get(i).getType();
                dbAddress.add(groupDbAddress.get(i).getDbAddress());
            }
            // 初始化其中的一个分组parser
            eventParsers.add(doInitEventParser(lastType, dbAddress));
        }
        if (eventParsers.size() > 1) {
            // 如果存在分组,构造分组的parser
            GroupEventParser groupEventParser = new GroupEventParser();
            groupEventParser.setEventParsers(eventParsers);
            this.eventParser = groupEventParser;
        } else {
            this.eventParser = eventParsers.get(0);
        }
    } else {
        // 创建一个空数据库地址的parser,可能使用了tddl指定地址,启动的时候才会从tddl获取地址
        this.eventParser = doInitEventParser(type, new ArrayList<InetSocketAddress>());
    }
    logger.info("init eventParser end! \n\t load CanalEventParser:{}", eventParser.getClass().getName());
}
Also used : SourcingType(com.alibaba.otter.canal.instance.manager.model.CanalParameter.SourcingType) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) CanalEventParser(com.alibaba.otter.canal.parse.CanalEventParser) GroupEventParser(com.alibaba.otter.canal.parse.inbound.group.GroupEventParser) ArrayList(java.util.ArrayList) List(java.util.List) DataSourcing(com.alibaba.otter.canal.instance.manager.model.CanalParameter.DataSourcing) CanalException(com.alibaba.otter.canal.common.CanalException)

Aggregations

CanalEventParser (com.alibaba.otter.canal.parse.CanalEventParser)2 GroupEventParser (com.alibaba.otter.canal.parse.inbound.group.GroupEventParser)2 CanalException (com.alibaba.otter.canal.common.CanalException)1 AviaterRegexFilter (com.alibaba.otter.canal.filter.aviater.AviaterRegexFilter)1 DataSourcing (com.alibaba.otter.canal.instance.manager.model.CanalParameter.DataSourcing)1 SourcingType (com.alibaba.otter.canal.instance.manager.model.CanalParameter.SourcingType)1 AbstractEventParser (com.alibaba.otter.canal.parse.inbound.AbstractEventParser)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1