Java Code Examples for com.github.shyiko.mysql.binlog.event.deserialization.EventDeserializer

The following examples show how to use com.github.shyiko.mysql.binlog.event.deserialization.EventDeserializer. These examples are extracted from open source projects. 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 Project: replicator   Source File: BinaryLogSupplier.java    License: Apache License 2.0 6 votes vote down vote up
private BinaryLogClient getClient(String hostname) {

        // TODO: Implement status variable parser: https://github.com/shyiko/mysql-binlog-connector-java/issues/174
        BinaryLogClient client = new BinaryLogClient(
                hostname,
                this.port,
                this.schema,
                this.username,
                this.password
        );
        client.setHeartbeatInterval(TimeUnit.MILLISECONDS.toMillis(1000));

        EventDeserializer eventDeserializer = new EventDeserializer();
        eventDeserializer.setCompatibilityMode(
                EventDeserializer.CompatibilityMode.CHAR_AND_BINARY_AS_BYTE_ARRAY,
                EventDeserializer.CompatibilityMode.DATE_AND_TIME_AS_LONG);
        client.setEventDeserializer(eventDeserializer);

        return client;
    }
 
Example 2
Source Project: light-eventuate-4j   Source File: MySqlBinaryLogClient.java    License: Apache License 2.0 6 votes vote down vote up
private EventDeserializer getEventDeserializer() {
  EventDeserializer eventDeserializer = new EventDeserializer();

  // do not deserialize binlog events except the EXT_WRITE_ROWS and TABLE_MAP
  Arrays.stream(EventType.values()).forEach(eventType -> {
    if (eventType != EventType.EXT_WRITE_ROWS &&
            eventType != EventType.TABLE_MAP &&
            eventType != EventType.ROTATE) {
      eventDeserializer.setEventDataDeserializer(eventType,
              new NullEventDataDeserializer());
    }
  });

  eventDeserializer.setEventDataDeserializer(EventType.EXT_WRITE_ROWS,
          new WriteRowsEventDataDeserializer(
                  tableMapEventByTableId).setMayContainExtraInformation(true));
  return eventDeserializer;
}
 
Example 3
Source Project: openmessaging-connect-odar   Source File: EventProcessor.java    License: Apache License 2.0 4 votes vote down vote up
public void start() throws Exception {

        initDataSource();

        binlogPositionManager = new BinlogPositionManager(config, dataSource);
        binlogPositionManager.initBeginPosition();

        schema = new Schema(dataSource);
        String whiteDataBases = config.getWhiteDataBase();
        String whiteTables = config.getWhiteTable();

        if (!StringUtils.isEmpty(whiteDataBases)){
            Arrays.asList(whiteDataBases.trim().split(",")).forEach(whiteDataBase ->{
                Collections.addAll(schema.dataBaseWhiteList, whiteDataBase);
            });
        }

        if (!StringUtils.isEmpty(whiteTables)){
            Arrays.asList(whiteTables.trim().split(",")).forEach(whiteTable ->{
                Collections.addAll(schema.tableWhiteList, whiteTable);
            });
        }
        schema.load();

        eventListener = new EventListener(queue);
        binaryLogClient = new BinaryLogClient(config.mysqlAddr,
            config.mysqlPort,
            config.mysqlUsername,
            config.mysqlPassword);
        binaryLogClient.setBlocking(true);
        binaryLogClient.setServerId(1001);

        EventDeserializer eventDeserializer = new EventDeserializer();
        eventDeserializer.setCompatibilityMode(EventDeserializer.CompatibilityMode.DATE_AND_TIME_AS_LONG,
            EventDeserializer.CompatibilityMode.CHAR_AND_BINARY_AS_BYTE_ARRAY);
        binaryLogClient.setEventDeserializer(eventDeserializer);
        binaryLogClient.registerEventListener(eventListener);
        binaryLogClient.setBinlogFilename(binlogPositionManager.getBinlogFilename());
        binaryLogClient.setBinlogPosition(binlogPositionManager.getPosition());

        binaryLogClient.connect(3000);

        LOGGER.info("Started.");

        stopped = false;

        doProcess();
    }