截至日期的Apache Kafka消费者

时间:2017-05-25 08:25:51

标签: apache-kafka consumer

是否存在可以在特定时间段/日期消费的低级别或高级别消费者Kafka 0.8.2? (Kafka-client,spark-Kafka,...)

2 个答案:

答案 0 :(得分:0)

使用OffsetAndTimestamp:

ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(100));
            Set<TopicPartition> assignments = consumer.assignment();
            Map<TopicPartition, Long> query = new HashMap<>();
            for (TopicPartition topicPartition : assignments) {
                query.put(topicPartition, date);
            }

            Map<TopicPartition, OffsetAndTimestamp> result = consumer.offsetsForTimes(query);

            result.entrySet().stream().forEach(entry -> consumer.seek(entry.getKey(),
                    Optional.ofNullable(entry.getValue()).map(OffsetAndTimestamp::offset).orElse(new Long(0))));

            flag = false;

        for (ConsumerRecord<String, String> record : records)
            System.out.printf("offset = %d, key = %s, value = %s%n", record.offset(), record.key(), record.value());

答案 1 :(得分:-1)

不,没有。你必须转到0.10才能获得这种功能。