use of org.eclipse.hono.client.kafka.consumer.AsyncHandlingAutoCommitKafkaConsumer in project hono by eclipse.
the class KafkaBasedCommandConsumerFactoryImpl method start.
@Override
public Future<Void> start() {
final Context context = Vertx.currentContext();
if (context == null) {
return Future.failedFuture(new IllegalStateException("factory must be started in a Vert.x context"));
}
final KafkaCommandProcessingQueue commandQueue = new KafkaCommandProcessingQueue(context);
commandHandler = new KafkaBasedMappingAndDelegatingCommandHandler(vertx, tenantClient, commandQueue, commandTargetMapper, internalCommandSender, kafkaBasedCommandResponseSender, metrics, tracer);
final Map<String, String> consumerConfig = kafkaConsumerConfig.getConsumerConfig("command");
consumerConfig.put(ConsumerConfig.GROUP_ID_CONFIG, groupId);
consumerConfig.putIfAbsent(ConsumerConfig.PARTITION_ASSIGNMENT_STRATEGY_CONFIG, CooperativeStickyAssignor.class.getName());
consumerConfig.putIfAbsent(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");
kafkaConsumer = new AsyncHandlingAutoCommitKafkaConsumer(vertx, COMMANDS_TOPIC_PATTERN, commandHandler::mapAndDelegateIncomingCommandMessage, consumerConfig);
kafkaConsumer.setPollTimeout(Duration.ofMillis(kafkaConsumerConfig.getPollTimeout()));
kafkaConsumer.setConsumerCreationRetriesTimeout(KafkaClientFactory.UNLIMITED_RETRIES_DURATION);
kafkaConsumer.setMetricsSupport(kafkaClientMetricsSupport);
kafkaConsumer.setOnRebalanceDoneHandler(partitions -> commandQueue.setCurrentlyHandledPartitions(Helper.to(partitions)));
kafkaConsumer.setOnPartitionsLostHandler(partitions -> commandQueue.setRevokedPartitions(Helper.to(partitions)));
final Future<Void> cleanupServiceStartFuture = Optional.ofNullable(internalKafkaTopicCleanupService).map(InternalKafkaTopicCleanupService::start).orElseGet(Future::succeededFuture);
return CompositeFuture.all(commandHandler.start(), kafkaConsumer.start(), cleanupServiceStartFuture).mapEmpty();
}
Aggregations