Created
December 15, 2020 11:41
-
-
Save mchmielarz/6241538bf920609041c61d4c0551e442 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
// create required number of vertices | |
IntStream.range(0, numberOfPartitions) | |
.forEach(partition -> { | |
vertx.deployVerticle( | |
() -> KafkaPartitionedVerticle.create(topic, partition, kafkaConfig), | |
deploymentOptions, | |
async -> log.info("Partitioned Kafka consumer deployed. DeploymentId: {}", async.result()) | |
); | |
}); | |
// inside KafkaPartitionedVerticle | |
class KafkaPartitionedVerticle extends AbstractVerticle { | |
// initialization | |
@Override | |
public void start() { | |
KafkaConsumer.create(vertx, kafkaConfig) | |
.assign(new TopicPartition(topic, partition), AsyncResult::result) | |
.handler(record -> | |
// processing logic comes here | |
) | |
.endHandler(v -> log.info("End of data. Topic: {}, partition: {}", this.topic, this.partition)) | |
.exceptionHandler(e -> log.error("Partitioned Kafka consumer error", e)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment