Bharat
Bharat

Reputation: 311

How to specify Kafka AdminClientConfig (Kafka Admin api) With Trust store and Password

How to Create Kafka AdminClientConfig (Kafka JAVA Admin api) With Trust store and Password. AdminClientConfig has method to specify AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG but How can we specify "ssl.truststore.location" and "password" property ?

If we use property file how to create AdminClientConfig with property file ?

Upvotes: 2

Views: 4919

Answers (1)

Mickael Maison
Mickael Maison

Reputation: 26885

You specify the SSL configurations for the AdminClient exactly like in the other Clients.

  • Without a Properties file:

    Properties adminProps = new Properties();
    adminProps.put(...)
    adminProps.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, "some/path/truststore");
    adminProps.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, "password");
    
    AdminClient admin = KafkaAdminClient.create(adminProps);
    
  • With a Properties file:

    In admin.properties:

    bootstrap.servers=localhost:9092
    ...
    ssl.truststore.location=some/path/truststore
    ssl.truststore.password=password
    

    Then in your Java code:

    Properties adminProps = new Properties();
    adminProps.load(new FileInputStream("admin.properties"));
    AdminClient admin = KafkaAdminClient.create(adminProps);
    

Upvotes: 1

Related Questions