public static Map<org.apache.kafka.common.TopicPartition, Long> toTopicPartitionTimes(Map<TopicPartition, Long> topicPartitionTimes) { return topicPartitionTimes.entrySet().stream().collect(Collectors.toMap( e -> new org.apache.kafka.common.TopicPartition(e.getKey().getTopic(), e.getKey().getPartition()), Map.Entry::getValue) ); }
public static org.apache.kafka.common.TopicPartition to(TopicPartition topicPartition) { return new org.apache.kafka.common.TopicPartition(topicPartition.getTopic(), topicPartition.getPartition()); }
public static Map<org.apache.kafka.common.TopicPartition, org.apache.kafka.clients.consumer.OffsetAndMetadata> to(Map<TopicPartition, OffsetAndMetadata> offsets) { return offsets.entrySet().stream().collect(Collectors.toMap( e -> new org.apache.kafka.common.TopicPartition(e.getKey().getTopic(), e.getKey().getPartition()), e -> new org.apache.kafka.clients.consumer.OffsetAndMetadata(e.getValue().getOffset(), e.getValue().getMetadata())) ); }
@Override public void offsetsForTimes(TopicPartition topicPartition, Long timestamp, Handler<AsyncResult<OffsetAndTimestamp>> handler) { Map<TopicPartition, Long> topicPartitions = new HashMap<>(); topicPartitions.put(topicPartition, timestamp); this.stream.offsetsForTimes(Helper.toTopicPartitionTimes(topicPartitions), done -> { if(done.succeeded()) { if (done.result().values().size() == 1) { org.apache.kafka.common.TopicPartition kTopicPartition = new org.apache.kafka.common.TopicPartition (topicPartition.getTopic(), topicPartition.getPartition()); org.apache.kafka.clients.consumer.OffsetAndTimestamp offsetAndTimestamp = done.result().get(kTopicPartition); if(offsetAndTimestamp != null) { OffsetAndTimestamp resultOffsetAndTimestamp = new OffsetAndTimestamp(offsetAndTimestamp.offset(), offsetAndTimestamp.timestamp()); handler.handle(Future.succeededFuture(resultOffsetAndTimestamp)); } // offsetAndTimestamp is null, i.e., search by timestamp did not lead to a result else { handler.handle(Future.succeededFuture()); } } else if (done.result().values().size() == 0) { handler.handle(Future.succeededFuture()); } else { handler.handle(Future.failedFuture("offsetsForTimes should return exactly one OffsetAndTimestamp")); } } else { handler.handle(Future.failedFuture(done.cause())); } }); }
log.debug("topic {} partition {}", partition.getTopic(), partition.getPartition()); log.debug("topic {} partition {}", partition.getTopic(), partition.getPartition());