springboot kafka 带权限的配置,让你少走弯路

spring.kafka.producer.bootstrapServers=192.168.211.54:4988
spring.kafka.producer.properties.sasl.mechanism=PLAIN
spring.kafka.producer.properties.security.protocol=SASL_PLAINTEXT
spring.kafka.producer.properties.sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username=\"caadmin\" password=\"R5s^C8p@B5dA\";

或者硬编码写法

 public static void main(String[] args) throws Exception {

    try {
        String topicName = "mytopic";
        String key = "key1";
        String value = "Value-1";

        Properties prop = new Properties();
        prop.put("bootstrap.server","localhost:9092");
        prop.put("key.serializer","org.apache.kafka.common.serialization.StringSerializer");
        prop.put("value.serializer","org.apache.kafka.cpmmon.serialization.StringSerializer");

        Producer<String, String> producer = new KafkaProducer<>(prop);

        ProducerRecord<String, String> record = new ProducerRecord<>(topicName,key,value);
        producer.send(record);
        producer.close();
        System.out.println("SimpleProducer Completed.");
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
本作品采用《CC 协议》,转载必须注明作者和本文链接
zhaozhangxiao
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!