Created
June 22, 2020 20:21
-
-
Save danielkec/cb8d474d3c6baf40bbeb124f37ad9cbf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Channel<String> fromKafka = Channel.<String>builder() | |
.publisherConfig(KafkaConnector.configBuilder() | |
.bootstrapServers("localhost:9092") | |
.groupId("example-group-1") | |
.topic("messaging-test-topic-1") | |
.autoOffsetReset(KafkaConfigBuilder.AutoOffsetReset.LATEST) | |
.enableAutoCommit(false) | |
.keyDeserializer(StringDeserializer.class) | |
.valueDeserializer(StringDeserializer.class) | |
.build() | |
) | |
.build(); | |
// Prepare Kafka connector, can be used by any channel | |
KafkaConnector kafkaConnector = KafkaConnector.create(); | |
Messaging.builder() | |
.connector(kafkaConnector) | |
.subscriber(fromKafka, ReactiveStreams.<Message<String>>builder() | |
//Apply back-pressure, flatMapCompletionStage request one by one | |
.flatMapCompletionStage(message -> { | |
return CompletableFuture.runAsync(() -> { | |
//Do something lengthy | |
Multi.timer(300, TimeUnit.MILLISECONDS, executor) | |
.first() | |
.await(); | |
//Acknowledge message has been consumed | |
message.ack(); | |
}); | |
}) | |
.ignore()) | |
.build() | |
.start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment