Kafka2.0 开启权限后,发送消息报错
kafka版本2.0.1,单台Broker节点,开启权限认证后,向topic生产数据报错
Broker端权限认证的配置如下:
在server.properties中:
security.inter.broker.protocol=SASL_PLAINTEXT
sasl.mechanism.inter.broker.protocol=SCRAM-SHA-256
sasl.enabled.mechanisms=SCRAM-SHA-256
ssl.endpoint.identification.algorithm=
authorizer.class.name=kafka.security.auth.SimpleAclAuthorizer
listeners=SASL_PLAINTEXT://myhostname:9092
advertised.listeners=SASL_PLAINTEXT://myhostname:9092
producer配置如下:
producerProperties.put("metadata.broker.list", brokerList);
producerProperties.put(ProducerConfig.CLIENT_ID_CONFIG, topicName + "_producer");
producerProperties.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
producerProperties.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
producerProperties.put("bootstrap.servers", brokerList);
producerProperties.put("sasl.jaas.config","org.apache.kafka.common.security.scram.ScramLoginModule required username=\"xxx\" password=\"xxxx\";" );
producerProperties.put("security.protocol","SASL_PLAINTEXT");
producerProperties.put("sasl.mechanism","SCRAM-SHA-256");
报错信息:
Sending metadata request (type=MetadataRequest, topics=topic-test) to node dc-resource-157880999-5.qiyi.virtual:9092 (id: -1 rack: null)
Error while fetching metadata with correlation id 3 : {topic-test=INVALID_REPLICATION_FACTOR}
注:关闭权限认证,及注释掉broker端的server.properties中的权限配置,重新启动kafka后,发送消息成功
https://www.orchome.com/500
参考一下这个。
你的答案