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;
}
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();
}
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();
}
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;
}
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();
}
Aggregations