如何使用Kafka数据源指定流查询的Kafka自定义配置(例如Confluent Cloud身份验证)?

时间:2019-11-04 10:17:25

标签: scala apache-spark apache-kafka spark-structured-streaming confluent-platform

我想使用针对Confluent Cloud的结构化流进行读写。问题是我无法在文档中找到进行身份验证的方法。

我有下一个数据连接:

ssl.endpoint.identification.algorithm=https
sasl.mechanism=PLAIN
request.timeout.ms=20000
bootstrap.servers=pkc-nq5ga.westeurope.azure.confluent.cloud:9092
retry.backoff.ms=500
sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="<CLUSTER_API_KEY>" password="<CLUSTER_API_SECRET>";
security.protocol=SASL_SSL

在没有密码的情况下针对localhost进行测试时,我没有任何问题。

val inputStream = spark.readStream
    .format("kafka")
    .option("kafka.bootstrap.servers", brokers)
    .option("subscribe", inputTopic)
    .option("startingOffsets", startingOffsetsValue)
    .load()

 outputStream.writeStream
    .format("kafka")
    .option("kafka.bootstrap.servers", outputBrokers)
    .option("topic", outputTopic)
    .option("checkpointLocation", pathCheckpoint)
    .start()
    .awaitTermination()

有人知道如何通过身份验证配置才能到达融合云

1 个答案:

答案 0 :(得分:2)

引用官方文档Kafka Specific Configurations

  

可以通过带有kafka.前缀,例如stream.option("kafka.bootstrap.servers", "host:port")

的DataStreamReader.option来设置Kafka自己的配置。

这样,我们可以传递连接数据,例如

.option("kafka.ssl.endpoint.identification.algorithm", "https")