Java 如何使用Beam KafkaIO配置客户端身份验证
我一直在阅读Beam KafkaIO教程,并试图找到有关kafka客户端身份验证的文档,但到目前为止只找到了非常基本的示例。我需要为Kafkaio客户端提供以下配置以成功进行身份验证:Java 如何使用Beam KafkaIO配置客户端身份验证,java,apache-kafka,apache-beam,Java,Apache Kafka,Apache Beam,我一直在阅读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
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)
p.apply(KafkaIO.read()
.使用BootstrapServer(“kafka1:9022”)
.withTopic(“测试主题”)
.withKeyDeserializer(LongDeserializer.class)
.withValueDeserializer(StringDeserializer.class)
您可以使用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)
p.apply(KafkaIO.read()
.使用BootstrapServer(“kafka1:9022”)
.withTopic(“测试主题”)
.withKeyDeserializer(LongDeserializer.class)
.withValueDeserializer(StringDeserializer.class)
.updateConsumerProperties(道具)
您可以在此处找到有关如何在KafkaIO中设置自定义属性的更多文档: