kafka sasl & java api

第一种

Properties props = new Properties();
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, “node01:9092”);
props.put(“acks”, “all”);
props.put(“retries”, 0);
props.put(“batch.size”, 16384);
props.put(“linger.ms”, 1);
props.put(“buffer.memory”, 33554432);
props.put(“key.serializer”, “org.apache.kafka.common.serialization.StringSerializer”);
props.put(“value.serializer”, “org.apache.kafka.common.serialization.StringSerializer”);

props.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, “SASL_PLAINTEXT”);
props.put(SaslConfigs.SASL_MECHANISM, “PLAIN”);
props.put(“sasl.jaas.config”,
“org.apache.kafka.common.security.plain.PlainLoginModule required username=\”maoxiangyi\” password=\”123321\”;”);


第二种

System.setProperty(“java.security.auth.login.config”, “/software/servers/maoxiangyi/kafka_client_jass.conf”); //配置文件路径


第三种

可以在程序启动参数中设置java.security.auth.login.config, 也就是启动参数加上-Djava.security.auth.login.config=/software/servers/maoxiangyi/kafka_client_jass.conf

java -jar -Djava.security.auth.login.config=/software/servers/maoxiangyi/kafka_client_jass.conf xxx.jar

posted @ 2019-06-11 14:03  春江师兄  阅读(2106)  评论(0编辑  收藏  举报