开发者社区> 问答> 正文

canal 1.1.0 不打印数据rowdata信息

提问327.png

类信息参考 https://github.com/alibaba/canal/blob/master/example/src/main/java/com/alibaba/otter/canal/example/AbstractCanalClientTest.java 写的

` protected void printEntry(List entrys) { for (Entry entry : entrys) { long executeTime = entry.getHeader().getExecuteTime(); long delayTime = System.currentTimeMillis() - executeTime; Date date = new Date(entry.getHeader().getExecuteTime()); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    if (entry.getEntryType() == EntryType.TRANSACTIONBEGIN || entry.getEntryType() == EntryType.TRANSACTIONEND) {
        if (entry.getEntryType() == EntryType.TRANSACTIONBEGIN) {
            TransactionBegin begin = null;
            try {
                begin = TransactionBegin.parseFrom(entry.getStoreValue());
            } catch (InvalidProtocolBufferException e) {
                throw new RuntimeException("parse event has an error , data:" + entry.toString(), e);
            }
            // 打印事务头信息,执行的线程id,事务耗时
            logger.info(transaction_format,
                    new Object[] { entry.getHeader().getLogfileName(),
                            String.valueOf(entry.getHeader().getLogfileOffset()),
                            String.valueOf(entry.getHeader().getExecuteTime()), simpleDateFormat.format(date),
                            entry.getHeader().getGtid(), String.valueOf(delayTime) });
            logger.info(" BEGIN ----> Thread id: {}", begin.getThreadId());
            printXAInfo(begin.getPropsList());
        } else if (entry.getEntryType() == EntryType.TRANSACTIONEND) {
            TransactionEnd end = null;
            try {
                end = TransactionEnd.parseFrom(entry.getStoreValue());
            } catch (InvalidProtocolBufferException e) {
                throw new RuntimeException("parse event has an error , data:" + entry.toString(), e);
            }
            // 打印事务提交信息,事务id
            logger.info("----------------\n");
            logger.info(" END ----> transaction id: {}", end.getTransactionId());
            printXAInfo(end.getPropsList());
            logger.info(transaction_format,
                    new Object[] { entry.getHeader().getLogfileName(),
                            String.valueOf(entry.getHeader().getLogfileOffset()),
                            String.valueOf(entry.getHeader().getExecuteTime()), simpleDateFormat.format(date),
                            entry.getHeader().getGtid(), String.valueOf(delayTime) });
        }

        continue;
    }

    if (entry.getEntryType() == EntryType.ROWDATA) {
        RowChange rowChage = null;
        try {
            rowChage = RowChange.parseFrom(entry.getStoreValue());
        } catch (Exception e) {
            throw new RuntimeException("parse event has an error , data:" + entry.toString(), e);
        }

        EventType eventType = rowChage.getEventType();
        String tableName = entry.getHeader().getTableName();

        for (CanalEntry.RowData rowData : rowChage.getRowDatasList()) {
            Map map = new HashMap<>();
            map.put("tableName",tableName);
            map.put("eventType",eventType);
            map.put("eventDate", org.apache.http.client.utils.DateUtils.formatDate(new Date(),"yyyy-MM-dd"));
            if (eventType == CanalEntry.EventType.DELETE) {
                printColumn(map,rowData.getBeforeColumnsList());
                //发送删除命令
            } else if (eventType == CanalEntry.EventType.INSERT) {
                //发送插入命令
                printColumn(map,rowData.getAfterColumnsList());
            } else {
                //发送修改命令
                printColumn(map,rowData.getAfterColumnsList());
            }
        }
        if (eventType == EventType.QUERY || rowChage.getIsDdl()) {
            logger.info(" sql ----> " + rowChage.getSql() + SEP);
            continue;
        }

// printXAInfo(rowChage.getPropsList());

    }
}

}

原提问者GitHub用户funnystack

展开
收起
Java工程师 2023-05-08 19:10:32 102 0
1 条回答
写回答
取消 提交回答
  • 检查过滤条件

    原回答者GitHub用户agapple

    2023-05-09 19:07:16
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载