kafka使用 SASL/PLAIN 认证 java客户端如何连接?

Candice Chung 发表于: 2017-03-16   最后更新时间: 2020-12-01 15:23:53   9,081 游览

看了下SaslConfigs和CommonClientConfigs,配了如下配置,没有成功。大神有没有demo分享下?

props.put(CommonClientConfigs.DEFAULT_SECURITY_PROTOCOL,"SASL_PLAINTEXT");
        props.put( CommonClientConfigs.SECURITY_PROTOCOL_DOC, "KafkaClient {\n" +
                "org.apache.kafka.common.security.plain.PlainLoginModule required\n" +
                "username=\"kafka\"\n" +
                "password=\"kafka-test\";\n" +
                "};\n");
        props.put(SaslConfigs.DEFAULT_SASL_MECHANISM,"PLAIN");
发表于 2017-03-16
添加评论

做了如下更改,可以消费到数据了

System.setProperty("java.security.auth.login.config", "/tmp/kafka_client_jaas.conf"); 
props.put("security.protocol", "SASL_PLAINTEXT");
props.put("sasl.mechanism", "PLAIN");
-> Candice Chung 6年前

直接运行可以吗?还是要打成jar包上传才能使用?

答人 -> Candice Chung 5年前
System.setProperty("java.security.auth.login.config", "/tmp/kafka_client_jaas.conf");

用这种方式,连接不同的kafka,账号和密码不一致怎么办的

你的答案

查看kafka相关的其他问题或提一个您自己的问题