运行kafka-console-producer.sh的异常(0.8.1.1)

时间:2014-11-24 22:53:55

标签: apache-kafka

我正在尝试kafka-console-producer.sh。我在控制台上输入了一些内容并按下了回车键,这样我就可以在控制台上获得大量的堆栈跟踪。感谢任何指针。

启动制作人的命令是:

./bin/kafka-console-producer.sh --broker-list localhost:2181 --topic test

然后我键入一些字符串并按Enter键并在控制台中查看以下内容。

[2014-11-24 15:27:36,022] ERROR fetching topic metadata for topics [Set(test)] from broker [ArrayBuffer(id:0,host:localhost,port:2181)] failed (kafka.utils.Utils$)
kafka.common.KafkaException: fetching topic metadata for topics [Set(test)] from broker [ArrayBuffer(id:0,host:localhost,port:2181)] failed
    at kafka.client.ClientUtils$.fetchTopicMetadata(ClientUtils.scala:67)
    at kafka.producer.BrokerPartitionInfo.updateInfo(BrokerPartitionInfo.scala:82)
    at kafka.producer.async.DefaultEventHandler$$anonfun$handle$2.apply$mcV$sp(DefaultEventHandler.scala:78)
    at kafka.utils.Utils$.swallow(Utils.scala:167)
    at kafka.utils.Logging$class.swallowError(Logging.scala:106)
    at kafka.utils.Utils$.swallowError(Utils.scala:46)
    at kafka.producer.async.DefaultEventHandler.handle(DefaultEventHandler.scala:78)
    at kafka.producer.async.ProducerSendThread.tryToHandle(ProducerSendThread.scala:104)
    at kafka.producer.async.ProducerSendThread$$anonfun$processEvents$3.apply(ProducerSendThread.scala:87)
    at kafka.producer.async.ProducerSendThread$$anonfun$processEvents$3.apply(ProducerSendThread.scala:67)
    at scala.collection.immutable.Stream.foreach(Stream.scala:547)
    at kafka.producer.async.ProducerSendThread.processEvents(ProducerSendThread.scala:66)
    at kafka.producer.async.ProducerSendThread.run(ProducerSendThread.scala:44)
Caused by: java.io.EOFException: Received -1 when reading from channel, socket has likely been closed.
    at kafka.utils.Utils$.read(Utils.scala:376)
    at kafka.network.BoundedByteBufferReceive.readFrom(BoundedByteBufferReceive.scala:54)
    at kafka.network.Receive$class.readCompletely(Transmission.scala:56)
    at kafka.network.BoundedByteBufferReceive.readCompletely(BoundedByteBufferReceive.scala:29)
    at kafka.network.BlockingChannel.receive(BlockingChannel.scala:100)
    at kafka.producer.SyncProducer.liftedTree1$1(SyncProducer.scala:74)
    at kafka.producer.SyncProducer.kafka$producer$SyncProducer$$doSend(SyncProducer.scala:71)
    at kafka.producer.SyncProducer.send(SyncProducer.scala:112)
    at kafka.client.ClientUtils$.fetchTopicMetadata(ClientUtils.scala:53)
    ... 12 more

我在zookeeper控制台上也看到了警告:

WARN Exception causing close of session 0x0 due to java.io.EOFException (org.apache.zookeeper.server.NIOServerCnxn)    

我使用以下内容来设置我的主题:

./bin/kafka-topics.sh --create --zookeeper localhost:2181 --partitions 1 --replication-factor 1 --topic test

我可以列出我的主题:

./bin/kafka-topics.sh --list --zookeeper localhost:2181

2 个答案:

答案 0 :(得分:21)

您的broker-list参数指向Zookeeper而不是实际的代理。 正确的用法是:

./bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test

假设您的代理在端口9092上运行(默认)。

您可以参考here了解详情(Step 4: Send some messages中描述了您的问题)

答案 1 :(得分:3)

这是因为你以错误的方式开始消费者。如果您要查看official documentation,则可以看到您必须:

启动Zookeper

bin/zookeeper-server-start.sh config/zookeeper.properties

启动Kafka

bin/kafka-server-start.sh config/server.properties

创建主题

bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

开始为主题制作消息

bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test 

注意区别:您要连接到zookeper(端口2181),您需要连接到代理(端口9092)