Search in sources :

Example 1 with EventuateKafkaProducer

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;
}
Also used : EventuateKafkaProducer(io.eventuate.local.java.kafka.producer.EventuateKafkaProducer) CompletableFuture(java.util.concurrent.CompletableFuture) Executor(java.util.concurrent.Executor) Configuration(io.debezium.config.Configuration) KafkaOffsetBackingStore(org.apache.kafka.connect.storage.KafkaOffsetBackingStore)

Example 2 with EventuateKafkaProducer

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;
}
Also used : ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) CuratorFramework(org.apache.curator.framework.CuratorFramework) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EventuateKafkaProducer(io.eventuate.local.java.kafka.producer.EventuateKafkaProducer) CompletableFuture(java.util.concurrent.CompletableFuture) Collectors(java.util.stream.Collectors) EventuateKafkaProducer(io.eventuate.local.java.kafka.producer.EventuateKafkaProducer) CompletableFuture(java.util.concurrent.CompletableFuture) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 3 with EventuateKafkaProducer

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");
}
Also used : EventuateKafkaProducer(io.eventuate.local.java.kafka.producer.EventuateKafkaProducer)

Aggregations

EventuateKafkaProducer (io.eventuate.local.java.kafka.producer.EventuateKafkaProducer)3 CompletableFuture (java.util.concurrent.CompletableFuture)2 Configuration (io.debezium.config.Configuration)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 Executor (java.util.concurrent.Executor)1 TimeUnit (java.util.concurrent.TimeUnit)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Collectors (java.util.stream.Collectors)1 CuratorFramework (org.apache.curator.framework.CuratorFramework)1 KafkaOffsetBackingStore (org.apache.kafka.connect.storage.KafkaOffsetBackingStore)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1