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);
}
Aggregations