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^[email protected]\";
Or hard coded
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();
}
}
This work adoptsCC agreement, reprint must indicate the author and the link to this article