|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
package com.example.demokafka.util;
|
|
|
|
|
package com.example.zxweb.utils;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
import org.apache.kafka.common.serialization.StringDeserializer;
|
|
|
|
@ -22,18 +22,25 @@ public class KafkaUtil {
|
|
|
|
|
public String secret;
|
|
|
|
|
public static String X_Consumer_Username = "dwVendor";
|
|
|
|
|
|
|
|
|
|
public static Properties getSafeProducerPro() {
|
|
|
|
|
public Properties getSafeProducerPro() {
|
|
|
|
|
Properties properties = new Properties();
|
|
|
|
|
properties.setProperty("bootstrap.servers", "10.0.10.153:29551,10.0.10.153:29552,10.0.10.153:29553");
|
|
|
|
|
properties.setProperty("acks", "all");
|
|
|
|
|
properties.setProperty("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
|
|
|
|
|
properties.setProperty("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
|
|
|
|
|
if (StringUtils.isNotBlank(appCode)) {
|
|
|
|
|
System.out.println("使用鉴权");
|
|
|
|
|
properties.setProperty("bootstrap.servers", "10.0.10.153:29553,10.0.10.153:29554");
|
|
|
|
|
properties.setProperty("sasl.jaas.config", "org.apache.kafka.common.security.scram.ScramLoginModule required username=\"dwVendor\" password=\"fEVcb^QFB;IN$K5\";");
|
|
|
|
|
properties.setProperty("sasl.mechanism", "SCRAM-SHA-512");
|
|
|
|
|
properties.setProperty("security.protocol", "SASL_SSL");
|
|
|
|
|
properties.setProperty("ssl.truststore.location", trustestore);
|
|
|
|
|
properties.setProperty("ssl.truststore.password", "pwd123");
|
|
|
|
|
}else{
|
|
|
|
|
properties.setProperty("bootstrap.servers", "10.0.10.153:29551,10.0.10.153:29552");
|
|
|
|
|
}
|
|
|
|
|
//properties.setProperty("sasl.jaas.config", String.format("org.apache.kafka.common.security.scram.ScramLoginModule required username=\"%s\" password=\"%s\";",appCode,secret));
|
|
|
|
|
//properties.setProperty("sasl.jaas.config", "org.apache.kafka.common.security.scram.ScramLoginModule required username=\"e92224\" password=\"323236g6#\";");
|
|
|
|
|
properties.setProperty("sasl.mechanism", "SCRAM-SHA-512");
|
|
|
|
|
properties.setProperty("security.protocol", "SASL_SSL");
|
|
|
|
|
properties.setProperty("ssl.truststore.location", trustestore);
|
|
|
|
|
properties.setProperty("ssl.truststore.password", "pwd123");
|
|
|
|
|
properties.setProperty("buffer.memory", "33554432");
|
|
|
|
|
properties.setProperty("retries", "0");
|
|
|
|
|
properties.setProperty("ssl.endpoint.identification.algorithm", "");
|
|
|
|
@ -53,7 +60,7 @@ public class KafkaUtil {
|
|
|
|
|
properties.setProperty("sasl.jaas.config", "org.apache.kafka.common.security.scram.ScramLoginModule required username=\"dwVendor\" password=\"fEVcb^QFB;IN$K5\";");
|
|
|
|
|
properties.setProperty("sasl.mechanism", "SCRAM-SHA-512");
|
|
|
|
|
properties.setProperty("security.protocol", "SASL_SSL");
|
|
|
|
|
properties.setProperty("ssl.truststore.location", "/opt/kafka/client.trustestore.p12");
|
|
|
|
|
properties.setProperty("ssl.truststore.location", trustestore);
|
|
|
|
|
properties.setProperty("ssl.truststore.password", "pwd123");
|
|
|
|
|
}else{
|
|
|
|
|
properties.setProperty("bootstrap.servers", "10.0.10.153:29551,10.0.10.153:29552");
|