@@ -100,23 +100,27 @@ private KafkaProducer createProducer(int eventType){
100
100
String defaultConfig = "kafka.conf" ;
101
101
File configFile = new File (defaultConfig );
102
102
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=\" " +
117
118
user + "\" password=\" " + passwd + "\" ;" );
118
- }
119
+
120
+ log .error ("org.apache.kafka.common.security.scram.ScramLoginModule required username=\" " +
121
+ user + "\" password=\" " + passwd + "\" ;" );
119
122
}
123
+
120
124
log .error ("after configFile" );
121
125
producer = new KafkaProducer <String , String >(props );
122
126
0 commit comments