Skip to content

Commit d37c2f1

Browse files
committed
add log
1 parent a8b9dfa commit d37c2f1

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

plugins/kafkaplugin/src/main/java/org/tron/eventplugin/MessageSenderImpl.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,27 @@ private KafkaProducer createProducer(int eventType){
100100
String defaultConfig = "kafka.conf";
101101
File configFile = new File(defaultConfig);
102102
log.error("file path: {}", configFile.getAbsolutePath());
103-
log.error("after configFile");
104-
if(configFile.exists()) {
105-
log.error("in configFile");
106-
Config config = ConfigFactory.load(defaultConfig);
107-
if (config.hasPath("authorization.user") && config.hasPath("authorization.passwd")) {
108-
String user = config.getString("authorization.user");
109-
String passwd = config.getString("authorization.passwd");
110-
props.put("security.protocol", "SASL_PLAINTEXT");
111-
props.put("sasl.mechanism", "SCRAM-SHA-512");
112-
props.put("sasl.jaas.config",
113-
"org.apache.kafka.common.security.scram.ScramLoginModule required username=\"" +
114-
user + "\" password=\"" + passwd + "\";");
115-
116-
log.error("org.apache.kafka.common.security.scram.ScramLoginModule required username=\"" +
103+
log.error("before configFile");
104+
Config config = null;
105+
106+
if (configFile.exists()) {
107+
config = ConfigFactory.parseFile(configFile);
108+
} else if (Thread.currentThread().getContextClassLoader().getResourceAsStream(defaultConfig) != null) {
109+
config = ConfigFactory.load(defaultConfig);
110+
}
111+
if (config != null && config.hasPath("authorization.user") && config.hasPath("authorization.passwd")) {
112+
String user = config.getString("authorization.user");
113+
String passwd = config.getString("authorization.passwd");
114+
props.put("security.protocol", "SASL_PLAINTEXT");
115+
props.put("sasl.mechanism", "SCRAM-SHA-512");
116+
props.put("sasl.jaas.config",
117+
"org.apache.kafka.common.security.scram.ScramLoginModule required username=\"" +
117118
user + "\" password=\"" + passwd + "\";");
118-
}
119+
120+
log.error("org.apache.kafka.common.security.scram.ScramLoginModule required username=\"" +
121+
user + "\" password=\"" + passwd + "\";");
119122
}
123+
120124
log.error("after configFile");
121125
producer = new KafkaProducer<String, String>(props);
122126

0 commit comments

Comments
 (0)