com.github.shyiko.mysql.binlog.BinaryLogClient Java Examples
The following examples show how to use
com.github.shyiko.mysql.binlog.BinaryLogClient.
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: BinaryLogSupplier.java From replicator with Apache License 2.0 | 6 votes |
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 File: BinLogClientFactory.java From kkbinlog with Apache License 2.0 | 6 votes |
/** * 配置当前binlog位置 * @param client * @param binaryLogConfig */ private void configBinaryLogStatus(BinaryLogClient client, BinaryLogConfig binaryLogConfig) { JSONObject binLogStatus = etcdService.getBinaryLogStatus(binaryLogConfig); if (binLogStatus != null) { Object binlogFilename = binLogStatus.get("binlogFilename"); if (binlogFilename != null) { client.setBinlogFilename((String) binlogFilename); } Long binlogPosition = binLogStatus.getLong("binlogPosition"); if (binlogPosition != null) { client.setBinlogPosition(binlogPosition); } } }
Example #3
Source File: MysqlSyncListener.java From easy-sync with Apache License 2.0 | 6 votes |
public void init(TimeTaskContext context, Producer producer, BinaryLogClient client, DatabaseService databaseService, PositionSaveService positionSaveService) { this.context = context; this.producer = producer; this.client = client; this.databaseService = databaseService; this.positionSaveService = positionSaveService; this.timezoneInMS = databaseService.getTimezoneHours() * 3600 * 1000; /* position=positionService.getPosition(databaseService.getTimeTaskId(),databaseService.getServerId()); if(position==null) { position = EntityUtils.create(Position.class); position.setTimeTaskId(databaseService.getTimeTaskId()); position.setServerId(databaseService.getServerId()); }*/ }
Example #4
Source File: MysqlBinLogSource.java From datacollector with Apache License 2.0 | 6 votes |
private BinaryLogClient createBinaryLogClient(MysqlBinLogSourceConfig config) { BinaryLogClient binLogClient = new BinaryLogClient( sshTunnel.getHost(), sshTunnel.getPort(), config.username.get(), config.password.get() ); switch (config.sslMode) { case REQUIRED: binLogClient.setSSLMode(SSLMode.REQUIRED); break; case VERIFY_CA: binLogClient.setSSLMode(SSLMode.VERIFY_CA); setSSLSocketFactory(binLogClient); break; case VERIFY_IDENTITY: binLogClient.setSSLMode(SSLMode.VERIFY_IDENTITY); setSSLSocketFactory(binLogClient); break; } binLogClient.setServerId(config.serverId); return binLogClient; }
Example #5
Source File: BinaryLogConnectorSource.java From SpinalTap with Apache License 2.0 | 6 votes |
public void onCommunicationFailure(BinaryLogClient client, Exception ex) { log.error( String.format( "Communication failure from source %s, binlogFile=%s, binlogPos=%s", name, client.getBinlogFilename(), client.getBinlogPosition()), ex); if (ex.getMessage().startsWith(INVALID_BINLOG_POSITION_ERROR_CODE)) { ex = new InvalidBinlogPositionException( String.format( "Invalid position %s in binlog file %s", client.getBinlogPosition(), client.getBinlogFilename())); } onCommunicationError(ex); }
Example #6
Source File: BinlogClient.java From ad with Apache License 2.0 | 5 votes |
/** * 该方法应该在应用程序启动时刻 就开始进行binlog 监听, * 可以使用springboot 提供的{@link org.springframework.boot.CommandLineRunner} * 或者{@link org.springframework.boot.ApplicationRunner}默认优先级更高一点 * @see org.springframework.boot.SpringApplication#callRunners(ApplicationContext, ApplicationArguments) * * 此处实现了在 {@link top.ezttf.ad.runner.BinlogRunner} 中直接调用 */ public void connect() { int corePoolSize = 1, maximumPoolSize = 1; long keepAliveTime = 0L; BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>(1); ThreadFactory threadFactory = new ThreadFactoryBuilder().setNameFormat("binlog-thread-%d").build(); ThreadPoolExecutor executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, TimeUnit.MILLISECONDS, workQueue, threadFactory, new ThreadPoolExecutor.AbortPolicy() ); executor.submit(() -> { client = new BinaryLogClient( config.getHost(), config.getPort(), config.getUsername(), config.getPassword() ); if (StringUtils.isNotBlank(config.getBinlogName()) && !config.getPosition().equals(-1L)) { client.setBinlogFilename(config.getBinlogName()); client.setBinlogPosition(config.getPosition()); } client.registerEventListener(listener); try { log.info("connecting to mysql..."); client.connect(); log.info("connected to mysql"); } catch (Exception e) { e.printStackTrace(); log.error("mysql binlog connect error"); } }); executor.shutdown(); }
Example #7
Source File: MysqlSource.java From datacollector with Apache License 2.0 | 5 votes |
private BinaryLogClient createBinaryLogClient() { BinaryLogClient binLogClient = new BinaryLogClient( getConfig().hostname, port, getConfig().username.get(), getConfig().password.get() ); if (getConfig().useSsl) { binLogClient.setSSLMode(SSLMode.REQUIRED); } else { binLogClient.setSSLMode(SSLMode.DISABLED); } binLogClient.setServerId(serverId); return binLogClient; }
Example #8
Source File: RawEventInvocationHandler.java From replicator with Apache License 2.0 | 5 votes |
public RawEventInvocationHandler(BinaryLogClient binaryLogClient, Event event) { this.gtidSet = binaryLogClient.getGtidSet(); this.event = event; this.eventDataSubTypes = Stream .of(RawEventType.values()) .map(RawEventType::getDefinition) .distinct() .collect( Collectors.toMap( (value) -> value.getSimpleName().replace("Raw", "").toLowerCase(), (value) -> value ) ); }
Example #9
Source File: BinlogStream.java From Mycat2 with GNU General Public License v3.0 | 5 votes |
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; }
Example #10
Source File: LogLifecycleListener.java From syncer with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void onCommunicationFailure(BinaryLogClient client, Exception ex) { if (binlogDeprecated(ex)) { if (dupServerId(ex)) { throw new DupServerIdException(ex); } throw new InvalidBinlogException(ex, client.getBinlogFilename(), client.getBinlogPosition()); } else { logger.error("Communication failure", ex); } }
Example #11
Source File: MysqlMasterConnector.java From syncer with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void configLogClient(MysqlConnection connection, String password, ConsumerRegistry registry) throws IOException { client = new BinaryLogClient(connection.getAddress(), connection.getPort(), connection.getUser(), password); client.registerLifecycleListener(new LogLifecycleListener()); client.setEventDeserializer(SyncDeserializer.defaultDeserializer()); client.setServerId(random.nextInt(Integer.MAX_VALUE)); client.setSSLMode(SSLMode.DISABLED); BinlogInfo binlogInfo = registry.votedBinlogInfo(connection); logger.info("Producer[{}] connect to {}", connectorIdentifier, binlogInfo); client.setBinlogFilename(binlogInfo.getBinlogFilename()); client.setBinlogPosition(binlogInfo.getBinlogPosition()); }
Example #12
Source File: BinaryLogConnectorSource.java From SpinalTap with Apache License 2.0 | 5 votes |
public void onDisconnect(BinaryLogClient client) { log.info( "Disconnected from source {}. BinlogFile={}, binlogPos={}", name, client.getBinlogFilename(), client.getBinlogPosition()); metrics.clientDisconnected(); started.set(false); }
Example #13
Source File: BinaryLogConnectorSource.java From SpinalTap with Apache License 2.0 | 5 votes |
public void onEventDeserializationFailure(BinaryLogClient client, Exception ex) { log.error( String.format( "Deserialization failure from source %s, BinlogFile=%s, binlogPos=%s", name, client.getBinlogFilename(), client.getBinlogPosition()), ex); onDeserializationError(ex); }
Example #14
Source File: BinaryLogConnectorSource.java From SpinalTap with Apache License 2.0 | 5 votes |
public BinaryLogConnectorSource( @NonNull final String name, @NonNull final MysqlConfiguration config, final TlsConfiguration tlsConfig, @NonNull final BinaryLogClient binlogClient, @NonNull final MysqlClient mysqlClient, @NonNull final TableCache tableCache, @NonNull final StateRepository stateRepository, @NonNull final StateHistory stateHistory, @NonNull final MysqlSchemaManager schemaManager, @NonNull final MysqlSourceMetrics metrics, @NonNull final AtomicLong currentLeaderEpoch) { super( name, new DataSource(config.getHost(), config.getPort(), name), new HashSet<>(config.getCanonicalTableNames()), tableCache, stateRepository, stateHistory, config.getInitialBinlogFilePosition(), schemaManager, metrics, currentLeaderEpoch, new AtomicReference<>(), new AtomicReference<>()); this.binlogClient = binlogClient; this.mysqlClient = mysqlClient; this.serverUUID = mysqlClient.getServerUUID(); initializeClient(config, tlsConfig); }
Example #15
Source File: CaptureChangeMySQL.java From nifi with Apache License 2.0 | 4 votes |
BinaryLogClient createBinlogClient(String hostname, int port, String username, String password) { return new BinaryLogClient(hostname, port, username, password); }
Example #16
Source File: BinlogEventListener.java From nifi with Apache License 2.0 | 4 votes |
public BinlogEventListener(BinaryLogClient client, BlockingQueue<RawBinlogEvent> q) { this.client = client; this.queue = q; }
Example #17
Source File: BinaryLogConsumer.java From datacollector with Apache License 2.0 | 4 votes |
public BinaryLogConsumer(MysqlSchemaRepository schemaRepository, EventBuffer eventBuffer, BinaryLogClient client) { this.schemaRepository = schemaRepository; this.eventBuffer = eventBuffer; this.client = client; }
Example #18
Source File: BinlogLifecycleListener.java From nifi with Apache License 2.0 | 4 votes |
@Override public void onConnect(BinaryLogClient binaryLogClient) { client.set(binaryLogClient); exception.set(null); }
Example #19
Source File: BinLogPositionSourceOffset.java From datacollector with Apache License 2.0 | 4 votes |
@Override public void positionClient(BinaryLogClient client) { client.setBinlogFilename(filename); client.setBinlogPosition(position); }
Example #20
Source File: GtidSourceOffset.java From datacollector with Apache License 2.0 | 4 votes |
@Override public void positionClient(BinaryLogClient client) { client.setGtidSet(gtidSet); }
Example #21
Source File: BinlogLifecycleListener.java From nifi with Apache License 2.0 | 4 votes |
@Override public void onCommunicationFailure(BinaryLogClient binaryLogClient, Exception e) { client.set(binaryLogClient); exception.set(e); }
Example #22
Source File: BinlogLifecycleListener.java From nifi with Apache License 2.0 | 4 votes |
@Override public void onEventDeserializationFailure(BinaryLogClient binaryLogClient, Exception e) { client.set(binaryLogClient); exception.set(e); }
Example #23
Source File: BinlogLifecycleListener.java From nifi with Apache License 2.0 | 4 votes |
@Override public void onDisconnect(BinaryLogClient binaryLogClient) { client.set(binaryLogClient); }
Example #24
Source File: BinlogLifecycleListener.java From nifi with Apache License 2.0 | 4 votes |
public BinaryLogClient getClient() { return client.get(); }
Example #25
Source File: BinLogPositionSourceOffset.java From datacollector with Apache License 2.0 | 4 votes |
@Override public void positionClient(BinaryLogClient client) { client.setBinlogFilename(filename); client.setBinlogPosition(position); }
Example #26
Source File: BinaryLogConsumer.java From datacollector with Apache License 2.0 | 4 votes |
public BinaryLogConsumer(MysqlSchemaRepository schemaRepository, EventBuffer eventBuffer, BinaryLogClient client) { this.schemaRepository = schemaRepository; this.eventBuffer = eventBuffer; this.client = client; }
Example #27
Source File: GtidSourceOffset.java From datacollector with Apache License 2.0 | 4 votes |
@Override public void positionClient(BinaryLogClient client) { client.setGtidSet(gtidSet); }
Example #28
Source File: LogLifecycleListener.java From syncer with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void onDisconnect(BinaryLogClient client) { logger.warn("Disconnect {}@{}", client.getBinlogFilename(), client.getBinlogPosition()); }
Example #29
Source File: LogLifecycleListener.java From syncer with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void onEventDeserializationFailure(BinaryLogClient client, Exception ex) { logger.error("Deserialization failure", ex); }
Example #30
Source File: LogLifecycleListener.java From syncer with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void onConnect(BinaryLogClient client) { logger.info("Connected {}@{}", client.getBinlogFilename(), client.getBinlogPosition()); }