console-producer.sh(0.8.1.1)时出现异常

ltskdhd1  于 2021-06-08  发布在  Kafka
关注(0)|答案(2)|浏览(422)

我正在试用kafka-console-producer.sh。我在控制台上输入一些东西,然后按enter键,控制台上就会有成吨的堆栈跟踪,就像这样。谢谢你的指点。
启动生产者的命令是:

./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
jyztefdp

jyztefdp1#

这是因为你开始你的消费者在一个错误的方式。如果您查看官方文件,您会发现您必须:
启动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)

moiiocjp

moiiocjp2#

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

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

假设你的经纪人在港口 9092 (默认)。
有关更多信息,请参阅此处(中描述了您的问题) Step 4: Send some messages )

相关问题