use of io.eventuate.local.java.kafka.producer.EventuateKafkaProducer in project eventuate-local by eventuate-local.
the class MySqlBinLogBasedEventTableChangesToAggregateTopicRelay method startCapturingChanges.
public CompletableFuture<Object> startCapturingChanges() throws InterruptedException {
logger.debug("Starting to capture changes");
cdcStartupValidator.validateEnvironment();
producer = new EventuateKafkaProducer(kafkaBootstrapServers);
String connectorName = "my-sql-connector";
Configuration config = Configuration.create().with("connector.class", "io.debezium.connector.mysql.MySqlConnector").with("offset.storage", KafkaOffsetBackingStore.class.getName()).with("bootstrap.servers", kafkaBootstrapServers).with("offset.storage.topic", "eventuate.local.cdc." + connectorName + ".offset.storage").with("poll.interval.ms", 50).with("offset.flush.interval.ms", 6000).with("name", connectorName).with("database.hostname", jdbcUrl.getHost()).with("database.port", jdbcUrl.getPort()).with("database.user", dbUser).with("database.password", dbPassword).with("database.server.id", 85744).with("database.server.name", "my-app-connector").with("table.whitelist", eventuateSchema.isEmpty() ? jdbcUrl.getDatabase() + ".events" : eventuateSchema.qualifyTable("events")).with("database.history", io.debezium.relational.history.KafkaDatabaseHistory.class.getName()).with("database.history.kafka.topic", "eventuate.local.cdc." + connectorName + ".history.kafka.topic").with("database.history.kafka.bootstrap.servers", kafkaBootstrapServers).build();
CompletableFuture<Object> completion = new CompletableFuture<>();
engine = EmbeddedEngine.create().using((success, message, throwable) -> {
if (success) {
completion.complete(null);
} else
completion.completeExceptionally(new RuntimeException("Engine through exception" + message, throwable));
}).using(config).notifying(this::receiveEvent).build();
Executor executor = Executors.newCachedThreadPool();
executor.execute(() -> {
try {
engine.run();
} catch (Throwable t) {
t.printStackTrace();
}
});
logger.debug("Started engine");
return completion;
}
use of io.eventuate.local.java.kafka.producer.EventuateKafkaProducer in project eventuate-local by eventuate-local.
the class PollingBasedEventTableChangesToAggregateTopicRelay method startCapturingChanges.
public CompletableFuture<Object> startCapturingChanges() throws InterruptedException {
logger.debug("Starting to capture changes");
watcherRunning.set(true);
cdcStartupValidator.validateEnvironment();
producer = new EventuateKafkaProducer(kafkaBootstrapServers);
CompletableFuture<Object> completableFuture = new CompletableFuture<>();
new Thread() {
@Override
public void run() {
while (watcherRunning.get()) {
try {
List<EventToPublish> eventToPublishes = eventPollingDao.findEventsToPublish();
if (!eventToPublishes.isEmpty())
logger.debug("Found {} events to publish", eventToPublishes.size());
eventToPublishes.forEach(eventToPublish -> handleEvent(eventToPublish));
if (!eventToPublishes.isEmpty()) {
logger.debug("Marking {} events as published", eventToPublishes.size());
eventPollingDao.markEventsAsPublished(eventToPublishes.stream().map(EventToPublish::getEventId).collect(Collectors.toList()));
}
completableFuture.complete(null);
if (eventToPublishes.isEmpty())
try {
logger.debug("No events. Sleeping for {} msecs", pollingIntervalInMilliseconds);
Thread.sleep(pollingIntervalInMilliseconds);
} catch (Exception e) {
logger.error("error while sleeping", e);
}
} catch (Exception e) {
logger.error("Exception in polling loop", e);
completableFuture.completeExceptionally(new RuntimeException("Polling exception" + e.getMessage(), e));
}
}
watcherFuture.complete(null);
watcherFuture = new CompletableFuture<>();
}
}.start();
return completableFuture;
}
use of io.eventuate.local.java.kafka.producer.EventuateKafkaProducer in project eventuate-local by eventuate-local.
the class CdcKafkaPublisher method start.
public void start() {
logger.debug("Starting CdcKafkaPublisher");
producer = new EventuateKafkaProducer(kafkaBootstrapServers);
logger.debug("Starting CdcKafkaPublisher");
}
Aggregations