kafka消费者启动报错

时间:2024-04-19 19:04:32

报错信息:

 WARN Fetching topic metadata with correlation id 14 for topics [Set(test)] from broker [BrokerEndPoint(2,ubuntu,9092)] failed (kafka.client.ClientUtils$)

WARN Fetching topic metadata with correlation id  for topics [Set(test)] from broker [BrokerEndPoint(,ubuntu,)] failed (kafka.client.ClientUtils$)
java.nio.channels.ClosedChannelException
at kafka.network.BlockingChannel.send(BlockingChannel.scala:)
at kafka.producer.SyncProducer.liftedTree1$(SyncProducer.scala:)
at kafka.producer.SyncProducer.kafka$producer$SyncProducer$$doSend(SyncProducer.scala:)
at kafka.producer.SyncProducer.send(SyncProducer.scala:)
at kafka.client.ClientUtils$.fetchTopicMetadata(ClientUtils.scala:)
at kafka.client.ClientUtils$.fetchTopicMetadata(ClientUtils.scala:)
at kafka.consumer.ConsumerFetcherManager$LeaderFinderThread.doWork(ConsumerFetcherManager.scala:)
at kafka.utils.ShutdownableThread.run(ShutdownableThread.scala:)
^X[-- ::,] WARN Fetching topic metadata with correlation id for topics [Set(test)] from broker [BrokerEndPoint(,ubuntu,)] failed (kafka.client.ClientUtils$)
java.nio.channels.ClosedChannelException
at kafka.network.BlockingChannel.send(BlockingChannel.scala:)
at kafka.producer.SyncProducer.liftedTree1$(SyncProducer.scala:)
at kafka.producer.SyncProducer.kafka$producer$SyncProducer$$doSend(SyncProducer.scala:)
at kafka.producer.SyncProducer.send(SyncProducer.scala:)
at kafka.client.ClientUtils$.fetchTopicMetadata(ClientUtils.scala:)
at kafka.client.ClientUtils$.fetchTopicMetadata(ClientUtils.scala:)
at kafka.consumer.ConsumerFetcherManager$LeaderFinderThread.doWork(ConsumerFetcherManager.scala:)
at kafka.utils.ShutdownableThread.run(ShutdownableThread.scala:)

  问题:可以非常明显的看到kafka消费者启动报错

  这个主机名是ubuntu,这个名字在hosts文件中我没有配置映射,非常粗心的一个问题。

  解决:在/etc/hosts文件中添加主机名和ip映射。

  说明:这个kafka相互通信连接的时候是默认拿着主机名加端口号的,而我开始在hosts文件中映射的ip并不是使用的主机名,因为几台机器的主机名命名不规范,所以我的映射文件是统一命名py101、py102、py103这种。而kafka默认拿着主机名寻找映射信息,然而hosts文件中没有,故报错。