Search in sources :

Example 1 with BinaryLogClient

use of com.github.shyiko.mysql.binlog.BinaryLogClient in project Mycat-Server by MyCATApache.

the class BinlogStream method allocateBinaryLogClient.

private synchronized BinaryLogClient allocateBinaryLogClient() {
    if (isConnected()) {
        throw new IllegalStateException("MySQL replication stream is already open");
    }
    binaryLogClient = new BinaryLogClient(hostname, port, username, password);
    binaryLogClient.setBinlogFilename(getBinglogFile());
    binaryLogClient.setBinlogPosition(getBinlogPos());
    binaryLogClient.setServerId(getSlaveID());
    binaryLogClient.registerEventListener(new DelegatingEventListener());
    return binaryLogClient;
}
Also used : BinaryLogClient(com.github.shyiko.mysql.binlog.BinaryLogClient)

Example 2 with BinaryLogClient

use of com.github.shyiko.mysql.binlog.BinaryLogClient in project rocketmq-externals by apache.

the class EventProcessor method start.

public void start() throws Exception {
    initDataSource();
    binlogPositionManager = new BinlogPositionManager(config, dataSource);
    binlogPositionManager.initBeginPosition();
    schema = new Schema(dataSource);
    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.");
    doProcess();
}
Also used : Schema(org.apache.rocketmq.mysql.schema.Schema) EventDeserializer(com.github.shyiko.mysql.binlog.event.deserialization.EventDeserializer) BinlogPositionManager(org.apache.rocketmq.mysql.position.BinlogPositionManager) BinaryLogClient(com.github.shyiko.mysql.binlog.BinaryLogClient)

Example 3 with BinaryLogClient

use of com.github.shyiko.mysql.binlog.BinaryLogClient in project eventuate-local by eventuate-local.

the class MySqlBinaryLogClient method start.

public void start(Optional<BinlogFileOffset> binlogFileOffset, Consumer<M> eventConsumer) {
    client = new BinaryLogClient(host, port, dbUserName, dbPassword);
    client.setServerId(binlogClientUniqueId);
    client.setKeepAliveInterval(5 * 1000);
    BinlogFileOffset bfo = binlogFileOffset.orElse(new BinlogFileOffset("", 4L));
    logger.debug("Starting with {}", bfo);
    client.setBinlogFilename(bfo.getBinlogFilename());
    client.setBinlogPosition(bfo.getOffset());
    client.setEventDeserializer(getEventDeserializer());
    client.registerEventListener(event -> {
        switch(event.getHeader().getEventType()) {
            case TABLE_MAP:
                {
                    TableMapEventData tableMapEvent = event.getData();
                    if (tableMapEvent.getTable().equalsIgnoreCase(sourceTableName)) {
                        tableMapEventByTableId.put(tableMapEvent.getTableId(), tableMapEvent);
                    }
                    break;
                }
            case EXT_WRITE_ROWS:
                {
                    logger.debug("Got binlog event {}", event);
                    offset = ((EventHeaderV4) event.getHeader()).getPosition();
                    WriteRowsEventData eventData = event.getData();
                    if (tableMapEventByTableId.containsKey(eventData.getTableId())) {
                        try {
                            eventConsumer.accept(writeRowsEventDataParser.parseEventData(eventData, getCurrentBinlogFilename(), offset));
                        } catch (IOException e) {
                            throw new RuntimeException("Event row parsing exception", e);
                        }
                    }
                    break;
                }
            case ROTATE:
                {
                    RotateEventData eventData = event.getData();
                    if (eventData != null) {
                        binlogFilename = eventData.getBinlogFilename();
                    }
                    break;
                }
        }
    });
    connectWithRetriesOnFail();
}
Also used : BinlogFileOffset(io.eventuate.local.common.BinlogFileOffset) IOException(java.io.IOException) BinaryLogClient(com.github.shyiko.mysql.binlog.BinaryLogClient)

Example 4 with BinaryLogClient

use of com.github.shyiko.mysql.binlog.BinaryLogClient in project Mycat_plus by coderczp.

the class BinlogStream method allocateBinaryLogClient.

private synchronized BinaryLogClient allocateBinaryLogClient() {
    if (isConnected()) {
        throw new IllegalStateException("MySQL replication stream is already open");
    }
    binaryLogClient = new BinaryLogClient(hostname, port, username, password);
    binaryLogClient.setBinlogFilename(getBinglogFile());
    binaryLogClient.setBinlogPosition(getBinlogPos());
    binaryLogClient.setServerId(getSlaveID());
    binaryLogClient.registerEventListener(new DelegatingEventListener());
    return binaryLogClient;
}
Also used : BinaryLogClient(com.github.shyiko.mysql.binlog.BinaryLogClient)

Example 5 with BinaryLogClient

use of com.github.shyiko.mysql.binlog.BinaryLogClient in project debezium by debezium.

the class ReadBinLogIT method startClient.

protected void startClient(Consumer<BinaryLogClient> preConnect) throws IOException, TimeoutException, SQLException {
    // Connect the bin log client ...
    counters = new EventQueue(DEFAULT_TIMEOUT, this::logConsumedEvent, this::logIgnoredEvent);
    client = new BinaryLogClient(config.getHostname(), config.getPort(), "replicator", "replpass");
    // avoid clashes between BinaryLogClient instances
    client.setServerId(client.getServerId() - 1);
    client.setKeepAlive(false);
    client.setSSLMode(SSLMode.DISABLED);
    client.registerEventListener(counters);
    client.registerEventListener(this::recordEvent);
    client.registerLifecycleListener(new TraceLifecycleListener());
    EventDeserializer eventDeserializer = new EventDeserializer();
    eventDeserializer.setEventDataDeserializer(EventType.STOP, new StopEventDataDeserializer());
    client.setEventDeserializer(eventDeserializer);
    if (preConnect != null)
        preConnect.accept(client);
    // does not block
    client.connect(DEFAULT_TIMEOUT);
    // Set up the table as one transaction and wait to see the events ...
    conn.execute("DROP TABLE IF EXISTS person", "CREATE TABLE person (" + "  name VARCHAR(255) primary key," + "  age INTEGER NULL DEFAULT 10," + "  createdAt DATETIME NULL DEFAULT CURRENT_TIMESTAMP," + "  updatedAt DATETIME NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP" + ")");
    counters.consume(2, EventType.QUERY);
    counters.reset();
}
Also used : EventDeserializer(com.github.shyiko.mysql.binlog.event.deserialization.EventDeserializer) BinaryLogClient(com.github.shyiko.mysql.binlog.BinaryLogClient)

Aggregations

BinaryLogClient (com.github.shyiko.mysql.binlog.BinaryLogClient)6 EventDeserializer (com.github.shyiko.mysql.binlog.event.deserialization.EventDeserializer)2 MutationOrderValidator (com.airbnb.spinaltap.common.validator.MutationOrderValidator)1 CachedMysqlSchemaStore (com.airbnb.spinaltap.mysql.schema.CachedMysqlSchemaStore)1 LatestMysqlSchemaStore (com.airbnb.spinaltap.mysql.schema.LatestMysqlSchemaStore)1 MysqlSchemaDatabase (com.airbnb.spinaltap.mysql.schema.MysqlSchemaDatabase)1 MysqlSchemaStore (com.airbnb.spinaltap.mysql.schema.MysqlSchemaStore)1 MysqlSchemaStoreManager (com.airbnb.spinaltap.mysql.schema.MysqlSchemaStoreManager)1 MysqlSchemaTracker (com.airbnb.spinaltap.mysql.schema.MysqlSchemaTracker)1 MysqlTableSchema (com.airbnb.spinaltap.mysql.schema.MysqlTableSchema)1 SchemaTracker (com.airbnb.spinaltap.mysql.schema.SchemaTracker)1 EventOrderValidator (com.airbnb.spinaltap.mysql.validator.EventOrderValidator)1 MutationSchemaValidator (com.airbnb.spinaltap.mysql.validator.MutationSchemaValidator)1 BinlogFileOffset (io.eventuate.local.common.BinlogFileOffset)1 IOException (java.io.IOException)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 BinlogPositionManager (org.apache.rocketmq.mysql.position.BinlogPositionManager)1 Schema (org.apache.rocketmq.mysql.schema.Schema)1 DBI (org.skife.jdbi.v2.DBI)1