如何使用信任库和密码创建Kafka AdminClientConfig(Kafka JAVA Admin api)。 AdminClientConfig具有指定AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG的方法,但是如何指定“ ssl.truststore.location”和“ password”属性呢?

如果我们使用属性文件,如何使用属性文件创建AdminClientConfig?

最佳答案

您可以像在其他客户端中一样为AdminClient指定SSL配置。


没有属性文件:

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);

使用属性文件:

admin.properties中:

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


然后在您的Java代码中:

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

09-05 05:33