@Override public String topicFor(PublishedEvent publishedEvent) { return AggregateTopicMapping.aggregateTypeToTopic(publishedEvent.getEntityType()); }
@Override public String getId(PublishedEvent data) { return data.getId(); }
@Override public String partitionKeyFor(PublishedEvent publishedEvent) { return publishedEvent.getEntityId(); }
private MySqlBinaryLogClient<PublishedEvent> createMySqlBinaryLogClient() { JdbcUrl jdbcUrl = JdbcUrlParser.parse(dataSourceURL); return new MySqlBinaryLogClient<>(eventDataParser, eventuateConfigurationProperties.getDbUserName(), eventuateConfigurationProperties.getDbPassword(), jdbcUrl.getHost(), jdbcUrl.getPort(), eventuateConfigurationProperties.getBinlogClientId(), ResolvedEventuateSchema.make(eventuateSchema, jdbcUrl), sourceTableNameSupplier.getSourceTableName(), eventuateConfigurationProperties.getMySqlBinLogClientName(), eventuateConfigurationProperties.getBinlogConnectionTimeoutInMilliseconds(), eventuateConfigurationProperties.getMaxAttemptsForBinlogConnection()); }
@Test public void shouldParseUrl() { JdbcUrl jdbcUrl = JdbcUrlParser.parse("jdbc:mysql://192.168.99.101/eventuate"); assertEquals("192.168.99.101", jdbcUrl.getHost()); assertEquals(3306, jdbcUrl.getPort()); assertEquals("eventuate", jdbcUrl.getDatabase()); }
@Bean public EventTableChangesToAggregateTopicTranslator<PublishedEvent> mySqlEventTableChangesToAggregateTopicTranslator(CdcDataPublisher<PublishedEvent> mySQLCdcDataPublisher, CdcProcessor<PublishedEvent> mySQLCdcProcessor, CuratorFramework curatorFramework, EventuateConfigurationProperties eventuateConfigurationProperties) { return new EventTableChangesToAggregateTopicTranslator<>(mySQLCdcDataPublisher, mySQLCdcProcessor, curatorFramework, eventuateConfigurationProperties.getLeadershipLockPath()); }
public void startCapturingChanges() throws InterruptedException { logger.debug("Starting to capture changes"); cdcDataPublisher.start(); try { cdcProcessor.start(cdcDataPublisher::handleEvent); } catch (Exception e) { if (e.getCause() instanceof EventuateLocalPublishingException) { logger.error("Stopping capturing changes due to exception:", e); this.stopCapturingChanges(); } } logger.debug("Started CDC Kafka publisher"); }
@Override public void accept(EVENT publishedEvent) { if (couldReadDuplicateEntries) { if (startingBinlogFileOffset.map(s -> s.isSameOrAfter(publishedEvent.getBinlogFileOffset())).orElse(false)) { return; } else { couldReadDuplicateEntries = false; } } eventConsumer.accept(publishedEvent); } });
@Bean(destroyMethod = "close") public CuratorFramework curatorFramework(EventuateLocalZookeperConfigurationProperties eventuateLocalZookeperConfigurationProperties) { String connectionString = eventuateLocalZookeperConfigurationProperties.getConnectionString(); return makeStartedCuratorClient(connectionString); }
@Override public PublishedEvent transformEventBeanToEvent(PublishedEventBean eventBean) { return new PublishedEvent(eventBean.getEventId(), eventBean.getEntityId(), eventBean.getEntityType(), eventBean.getEventData(), eventBean.getEventType(), null, eventBean.getMetadataOptional()); } }
@Override public void onEventSent(PublishedEvent publishedEvent) { offsetStore.save(publishedEvent.getBinlogFileOffset()); } }
@Override public void takeLeadership(CuratorFramework client) throws Exception { takeLeadership(); }
private void resignLeadership() { logger.info("Resigning leadership"); try { eventTableChangesToAggregateTopicTranslator.stopCapturingChanges(); } catch (InterruptedException e) { logger.error("While handling SUSPEND", e); } } }
private MySqlBinaryLogClient<PublishedEvent> makeMySqlBinaryLogClient() { JdbcUrl jdbcUrl = JdbcUrlParser.parse(dataSourceURL); return new MySqlBinaryLogClient<>(eventDataParser, eventuateConfigurationProperties.getDbUserName(), eventuateConfigurationProperties.getDbPassword(), jdbcUrl.getHost(), jdbcUrl.getPort(), eventuateConfigurationProperties.getBinlogClientId(), ResolvedEventuateSchema.make(eventuateSchema, jdbcUrl), sourceTableNameSupplier.getSourceTableName(), eventuateConfigurationProperties.getMySqlBinLogClientName(), eventuateConfigurationProperties.getBinlogConnectionTimeoutInMilliseconds(), eventuateConfigurationProperties.getMaxAttemptsForBinlogConnection()); }
@Test public void shouldParseUrlWithParameters() { JdbcUrl jdbcUrl = JdbcUrlParser.parse("jdbc:mysql://192.168.99.101:3306/eventuate?useUnicode=true"); assertEquals("192.168.99.101", jdbcUrl.getHost()); assertEquals(3306, jdbcUrl.getPort()); assertEquals("eventuate", jdbcUrl.getDatabase()); }
@Bean public EventTableChangesToAggregateTopicTranslator<MessageWithDestination> eventTableChangesToAggregateTopicTranslator(EventuateConfigurationProperties eventuateConfigurationProperties, CdcDataPublisher<MessageWithDestination> cdcKafkaPublisher, CdcProcessor<MessageWithDestination> cdcProcessor, CuratorFramework curatorFramework) { return new EventTableChangesToAggregateTopicTranslator<>(cdcKafkaPublisher, cdcProcessor, curatorFramework, eventuateConfigurationProperties.getLeadershipLockPath()); }
@Override public void accept(EVENT publishedEvent) { if (couldReadDuplicateEntries) { if (startingBinlogFileOffset.map(s -> s.isSameOrAfter(publishedEvent.getBinlogFileOffset())).orElse(false)) { return; } else { couldReadDuplicateEntries = false; } } eventConsumer.accept(publishedEvent); } });
@Test public void shouldParseUrlWithPort() { JdbcUrl jdbcUrl = JdbcUrlParser.parse("jdbc:mysql://192.168.99.101:3306/eventuate"); assertEquals("192.168.99.101", jdbcUrl.getHost()); assertEquals(3306, jdbcUrl.getPort()); assertEquals("eventuate", jdbcUrl.getDatabase()); }
@Bean public EventTableChangesToAggregateTopicTranslator<MessageWithDestination> eventTableChangesToAggregateTopicTranslator(EventuateConfigurationProperties eventuateConfigurationProperties, CdcDataPublisher<MessageWithDestination> cdcKafkaPublisher, CdcProcessor<MessageWithDestination> cdcProcessor, CuratorFramework curatorFramework) { return new EventTableChangesToAggregateTopicTranslator<>(cdcKafkaPublisher, cdcProcessor, curatorFramework, eventuateConfigurationProperties.getLeadershipLockPath()); }