简体   繁体   中英

is it possible to refer environmental variable as values for properties in the kafkaProducer.properties and KafkaConsumer.properties files of Kafka

Im have a producer and consumer java code and Im trying to upgrade it to connect with the Kafka which is secured with SSL. I'm in a situation that the ssl related passwords should be given only via environmental variables. So is it possible to directly refer to the values refered by Environmental variables in the KafkaProducer.properties and KafkaConsumer.properties files

For Example: I declare an environmental variable in linux system SSL_KEY_PASSWORD=password

And inside the KafkaProducer/Consumer properties, I declare as, ''' ssl.key.password=${SSL_KEY_PASSWORD} '''

Sample KAFKA Consumer/Producer property file config may look like,

# For SSL
security.protocol=SSL
ssl.truststore.location=/var/private/ssl/client.truststore.jks
ssl.truststore.password=${TRUSTSTORE_PASS_ENV_VARIABLE}
# For SSL auth
ssl.keystore.location=/var/private/ssl/client.keystore.jks
ssl.keystore.password=${KEYSTORE_PASS_ENV_VARIABLE}
ssl.key.password=${KEY_PASS_ENV_VARIABLE}

No, they cannot.

Unclear how you are using the files or Kafka clients. If from the shell commands, you should create a bash wrapper around the command you're running that uses sed or other templating scripts that generates the files before running the final command.

If you are actually writing Java code, then build the Properties from the environment there, and not using files.

Don't think properties file values are interpolated but probably you can test it once. Alternatively you can also remove these lines from property file and do it from code something like below...

   final Properties properties = new Properties();
   final FileInputStream input = new FileInputStream(yourExistingFile);
   
   properties.load(input); 
   properties.put("ssl.key.password",System.getenv("SSL_KEY_PASSWORD"));//this is additional property

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM