问题:

在代码中测试SparkStreaming与Kafka整合的过程,需要在kafka中提前创建两个topic,但是在执行创建脚本的过程中报错如下

 kafka-topics.sh --zookeeper linux1:2181,linux2:2181,linux3:2181 --create --topic wufabao_topic01 --replication-factor 2 --partitions 3

WARNING: Due to limitations in metric names, topics with a period ('.') or underscore ('_') could collide. To avoid issues it is best to use either, but not both.
Error while executing topic command : Replication factor: 2 larger than available brokers: 0.
[2022-02-09 17:27:18,432] ERROR org.apache.kafka.common.errors.InvalidReplicationFactorException: Replication factor: 2 larger than available brokers: 0.
 (kafka.admin.TopicCommand$)

原因:

kafka配置的zookeeper存放的元数据的路径不对,我在kafka中配置的元数据路径为:
zookeeper.connect=linux1:2181,linux2:2181,linux3:2181/myKafka

解决方案:

修改脚本中kafka元数据路径为如下
kafka-topics.sh --zookeeper linux1:2181,linux2:2181,linux3:2181/myKafka --create --topic wufabao_topic01 --replication-factor 2 --partitions 3
创建成功
在这里插入图片描述

Logo

华为云1024程序员节送福利,参与活动赢单人4000元礼包,更有热门技术干货免费学习

更多推荐