com.alibaba.otter.canal.protocol.CanalEntry.RowChange Java Examples

The following examples show how to use com.alibaba.otter.canal.protocol.CanalEntry.RowChange. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractCanalListener.java    From canal_mysql_elasticsearch_sync with Apache License 2.0 6 votes vote down vote up
@Override
public void onApplicationEvent(EVENT event) {
    Entry entry = event.getEntry();
    String database = entry.getHeader().getSchemaName();
    String table = entry.getHeader().getTableName();
    IndexTypeModel indexTypeModel = mappingService.getIndexType(new DatabaseTableModel(database, table));
    if (indexTypeModel == null) {
        return;
    }
    String index = indexTypeModel.getIndex();
    String type = indexTypeModel.getType();
    RowChange change;
    try {
        change = RowChange.parseFrom(entry.getStoreValue());
    } catch (InvalidProtocolBufferException e) {
        logger.error("canalEntry_parser_error,根据CanalEntry获取RowChange失败!", e);
        return;
    }
    change.getRowDatasList().forEach(rowData -> doSync(database, table, index, type, rowData));
}
 
Example #2
Source File: LogEventConvert.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
private Entry buildQueryEntry(String queryString, LogHeader logHeader, String tableName) {
    Header header = createHeader(logHeader, "", tableName, EventType.QUERY);
    RowChange.Builder rowChangeBuider = RowChange.newBuilder();
    rowChangeBuider.setSql(queryString);
    rowChangeBuider.setEventType(EventType.QUERY);
    return createEntry(header, EntryType.ROWDATA, rowChangeBuider.build().toByteString());
}
 
Example #3
Source File: LogEventConvert.java    From canal-1.1.3 with Apache License 2.0 5 votes vote down vote up
private Entry buildQueryEntry(String queryString, LogHeader logHeader) {
    Header header = createHeader(logHeader, "", "", EventType.QUERY);
    RowChange.Builder rowChangeBuider = RowChange.newBuilder();
    rowChangeBuider.setSql(queryString);
    rowChangeBuider.setEventType(EventType.QUERY);
    return createEntry(header, EntryType.ROWDATA, rowChangeBuider.build().toByteString());
}
 
Example #4
Source File: LogEventConvert.java    From DBus with Apache License 2.0 5 votes vote down vote up
private Entry buildQueryEntry(String queryString, LogHeader logHeader) {
    Header header = createHeader(binlogFileName, logHeader, "", "", EventType.QUERY);
    RowChange.Builder rowChangeBuider = RowChange.newBuilder();
    rowChangeBuider.setSql(queryString);
    rowChangeBuider.setEventType(EventType.QUERY);
    return createEntry(header, EntryType.ROWDATA, rowChangeBuider.build().toByteString());
}
 
Example #5
Source File: LogEventConvert_old.java    From DBus with Apache License 2.0 5 votes vote down vote up
private Entry buildQueryEntry(String queryString, LogHeader logHeader) {
    Header header = createHeader(binlogFileName, logHeader, "", "", EventType.QUERY);
    RowChange.Builder rowChangeBuider = RowChange.newBuilder();
    rowChangeBuider.setSql(queryString);
    rowChangeBuider.setEventType(EventType.QUERY);
    return createEntry(header, EntryType.ROWDATA, rowChangeBuider.build().toByteString());
}
 
Example #6
Source File: LogEventConvert.java    From DBus with Apache License 2.0 5 votes vote down vote up
private Entry buildQueryEntry(String queryString, LogHeader logHeader) {
    Header header = createHeader(binlogFileName, logHeader, "", "", EventType.QUERY);
    RowChange.Builder rowChangeBuider = RowChange.newBuilder();
    rowChangeBuider.setSql(queryString);
    rowChangeBuider.setEventType(EventType.QUERY);
    return createEntry(header, EntryType.ROWDATA, rowChangeBuider.build().toByteString());
}
 
Example #7
Source File: LogEventConvert.java    From canal with Apache License 2.0 5 votes vote down vote up
private Entry buildQueryEntry(String queryString, LogHeader logHeader, String tableName) {
    Header header = createHeader(logHeader, "", tableName, EventType.QUERY);
    RowChange.Builder rowChangeBuider = RowChange.newBuilder();
    rowChangeBuider.setSql(queryString);
    rowChangeBuider.setEventType(EventType.QUERY);
    return createEntry(header, EntryType.ROWDATA, rowChangeBuider.build().toByteString());
}
 
Example #8
Source File: LogEventConvert.java    From canal with Apache License 2.0 5 votes vote down vote up
private Entry buildQueryEntry(String queryString, LogHeader logHeader) {
    Header header = createHeader(logHeader, "", "", EventType.QUERY);
    RowChange.Builder rowChangeBuider = RowChange.newBuilder();
    rowChangeBuider.setSql(queryString);
    rowChangeBuider.setEventType(EventType.QUERY);
    return createEntry(header, EntryType.ROWDATA, rowChangeBuider.build().toByteString());
}
 
Example #9
Source File: CanalReaderMessageParser.java    From DataLink with Apache License 2.0 4 votes vote down vote up
private List<RdbEventRecord> internParse(Entry entry) {
    RowChange rowChange;
    try {
        rowChange = RowChange.parseFrom(entry.getStoreValue());
    } catch (Exception e) {
        throw new DatalinkException("parser of mysql-event has an error , data:" + entry.toString(), e);
    }

    if (rowChange == null) {
        return null;
    }

    EventType eventType = EventType.valueOf(rowChange.getEventType().name());
    if (eventType.isQuery()) {
        return null;
    }

    if (eventType.isDdl()) {
        logger.info("find a ddl event in MessageParser , ddl sql is {}.", rowChange.getSql());

        MediaService mediaService = DataLinkFactory.getObject(MediaService.class);
        MediaSourceInfo mediaSourceInfo = mediaService.getMediaSourceById(readerParameter.getMediaSourceId());

        DbDialect dbDialect = DbDialectFactory.getDbDialect(mediaSourceInfo);
        dbDialect.reloadTable(entry.getHeader().getSchemaName(), entry.getHeader().getTableName());

        if (readerParameter.isDdlSync()) {
            logger.info("The value of the ddl-sync is true , prepare to parse ddl event.");

            RdbEventRecord record = new RdbEventRecord();
            record.setSchemaName(entry.getHeader().getSchemaName());
            record.setTableName(entry.getHeader().getTableName());
            record.setEventType(eventType);
            record.setExecuteTime(entry.getHeader().getExecuteTime());
            record.setSql(rowChange.getSql());
            record.setDdlSchemaName(rowChange.getDdlSchemaName());
            return Arrays.asList(record);
        } else {
            logger.info("The value of the ddl-sync is false , the ddl event is ignored.");
            return null;
        }
    }


    List<RdbEventRecord> eventDatas = new ArrayList<>();
    for (RowData rowData : rowChange.getRowDatasList()) {
        RdbEventRecord eventData = internParse(entry, rowChange, rowData);
        if (eventData != null) {
            eventDatas.add(eventData);
        }
    }

    return eventDatas;
}