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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM