Search in sources :

Example 1 with SerializedEvent

use of io.eventuate.javaclient.commonimpl.SerializedEvent in project eventuate-local by eventuate-local.

the class EventuateKafkaAggregateSubscriptions method subscribe.

@Override
public CompletableFuture<?> subscribe(String subscriberId, Map<String, Set<String>> aggregatesAndEvents, SubscriberOptions subscriberOptions, Function<SerializedEvent, CompletableFuture<?>> handler) {
    List<String> topics = aggregatesAndEvents.keySet().stream().map(AggregateTopicMapping::aggregateTypeToTopic).collect(toList());
    EventuateKafkaConsumer consumer = new EventuateKafkaConsumer(subscriberId, (record, callback) -> {
        SerializedEvent se = toSerializedEvent(record);
        if (aggregatesAndEvents.get(se.getEntityType()).contains(se.getEventType())) {
            handler.apply(se).whenComplete((result, t) -> {
                callback.accept(null, t);
            });
        } else {
            callback.accept(null, null);
        }
    }, topics, eventuateLocalAggregateStoreConfiguration.getBootstrapServers());
    addConsumer(consumer);
    consumer.start();
    return CompletableFuture.completedFuture(null);
}
Also used : EventuateKafkaConsumer(io.eventuate.local.java.kafka.consumer.EventuateKafkaConsumer) SerializedEvent(io.eventuate.javaclient.commonimpl.SerializedEvent)

Aggregations

SerializedEvent (io.eventuate.javaclient.commonimpl.SerializedEvent)1 EventuateKafkaConsumer (io.eventuate.local.java.kafka.consumer.EventuateKafkaConsumer)1