Zookeeper属性仍然是Kafka消费者的要求吗?

时间:2016-07-31 19:51:08

标签: java apache-kafka kafka-consumer-api

我在这里指的是一篇文章: Connecting to Zookeeper in a Apache Kafka Multi Node cluster

这里提到,从kafka V9版本开始,Producer和Consumer不必使用zookeeper.connect属性,只需要bootstrap.servers就足以生成/使用数据。

我的POM.xml在消费者方面看起来像这样:

<properties>
    <java.version>1.7</java.version>
    <kafka.version>0.9.0.1-cp1</kafka.version>
    <kafka.scala.version>2.11</kafka.scala.version>
    <confluent.version>2.0.1</confluent.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>


<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.10</artifactId>
<version>0.10.0.0</version>
</dependency>

我在消费者方面遇到了以下问题,没有zookeeper.connect属性。没有zookeeper连接属性,有没有人让消费者部分工作?

[WARNING] 
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalArgumentException: requirement failed: Missing required property 'zookeeper.connect'
at scala.Predef$.require(Predef.scala:233)
at kafka.utils.VerifiableProperties.getString(VerifiableProperties.scala:177)
at kafka.utils.ZKConfig.<init>(ZkUtils.scala:902)
at kafka.consumer.ConsumerConfig.<init>(ConsumerConfig.scala:101)
at kafka.consumer.ConsumerConfig.<init>(ConsumerConfig.scala:105)
at io.confluent.examples.consumer.ConsumerGroup.<init>(ConsumerGroup.java:30)
at io.confluent.examples.consumer.ConsumerGroup.main(ConsumerGroup.java:113)
... 6 more

1 个答案:

答案 0 :(得分:2)

只有新的消费者才能在不连接Zookeeper的情况下工作,并且可以在kafka-clients工件中使用。您必须添加依赖项:

<dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka-clients</artifactId>
    <version>0.10.0.0</version>
</dependency>

并使用org.apache.kafka.clients.consumer.包中的实现。