如何从Kafka队列的开头(以编程方式)读取消息?

时间:2016-07-09 11:54:07

标签: java scala apache-kafka

当从终端启动Kafka Consumer时,可以设置--from-beginning,以便消费者从Kafka队列的开头读取消息。

~/kafka/bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic TutorialTopic --from-beginning

但是,如何在Scala(或Java)中设置此参数?这是我的样本ConsumerConfig

  import kafka.consumer.ConsumerConfig

  def createConsumerConfig(zookeeper: String, groupId: String): ConsumerConfig = {
    val props = new Properties()
    props.put("zookeeper.connect", zookeeper);
    props.put("group.id", groupId);
    props.put("auto.offset.reset", "largest");
    props.put("zookeeper.session.timeout.ms", "400");
    props.put("zookeeper.sync.time.ms", "200");
    props.put("auto.commit.interval.ms", "1000");
    val config = new ConsumerConfig(props)
    config
  }

0 个答案:

没有答案