我一直在阅读Beam KafkaIO教程,并一直在尝试查找有关kafka客户端身份验证的文档,但到目前为止,仅发现了非常基本的示例。我需要为Kafkaio客户端提供以下配置以成功进行身份验证:
bootstrap.servers=kafka1:9093
security.protocol=SSL
ssl.truststore.location=/var/private/ssl/kafka.client.truststore.jks
ssl.truststore.password=test1234
ssl.keystore.location=/var/private/ssl/kafka.client.keystore.jks
ssl.keystore.password=test1234
ssl.key.password=test1234
如何指定此配置?
到目前为止,我在示例中发现的所有内容都是以这种方式配置的:
p.apply(KafkaIO.<Long, String>read()
.withBootstrapServers("kafka1:9022")
.withTopic("test-topic")
.withKeyDeserializer(LongDeserializer.class)
.withValueDeserializer(StringDeserializer.class)
答案 0 :(得分:1)
您可以使用updateConsumerProperties(properties)
方法设置ssl配置。
为此,您需要设置以下消费者属性。
Properties props = new Properties();
props.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, "SSL");
props.put(SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, "/var/private/ssl/kafka.client.truststore.jks");
props.put(SslConfigs.SSL_KEYSTORE_LOCATION_CONFIG, resourcePath.get("keystore.jks"));
props.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, "test1234");
props.put(SslConfigs.SSL_KEY_PASSWORD_CONFIG, "test1234");
props.put(SslConfigs.SSL_KEYSTORE_PASSWORD_CONFIG, "test1234");
通过以下方法传递上述属性:
p.apply(KafkaIO.<Long, String>read()
.withBootstrapServers("kafka1:9022")
.withTopic("test-topic")
.withKeyDeserializer(LongDeserializer.class)
.withValueDeserializer(StringDeserializer.class)
.updateConsumerProperties(props)
您可以在此处找到有关如何在KafkaIO中设置自定义属性的更多文档:https://beam.apache.org/releases/javadoc/2.5.0/org/apache/beam/sdk/io/kafka/KafkaIO.html