簡體   English   中英

使用經過身份驗證的 Confluent Schema Registry 配置 Spark Structured Streaming

[英]Configuring Spark Structured Streaming with authenticated Confluent Schema Registry

我在 Spark Streaming 中使用 Kafka Source 來接收在 Confluent Cloud 中使用 Datagen 生成的記錄。 我打算使用 Confluent Schema Registry,

目前,這是我面臨的例外:*

線程“main”中的異常io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException:未經授權; 錯誤代碼:401

匯合雲的架構注冊表需要傳遞一些我不知道如何輸入它們的身份驗證數據:

basic.auth.credentials.source=USER_INFO
schema.registry.basic.auth.user.info=secret: secret

我想我必須將此身份驗證數據傳遞給 CachedSchemaRegistryClient,但我不確定是否這樣做以及如何傳遞。

// Setup the Avro deserialization UDF
   schemaRegistryClient = new CachedSchemaRegistryClient(schemaRegistryUrl, 128)
    kafkaAvroDeserializer = new AvroDeserializer(schemaRegistryClient)
    spark.udf.register("deserialize", (bytes: Array[Byte]) =>
      kafkaAvroDeserializer.deserialize(bytes)

如果我嘗試將身份驗證發送到架構注冊表

val restService = new RestService(schemaRegistryURL)

  val props = Map(
    "basic.auth.credentials.source" -> "USER_INFO",
    "schema.registry.basic.auth.user.info" -> "secret:secret"
  ).asJava

  var schemaRegistryClient = new CachedSchemaRegistryClient(restService, 100, props)

我得到Cannot resolve overloaded constructor CachedSchemaRegistryClient ,似乎只有 2 個參數要發送到 CachedSchemaRegistryClient。

我該如何解決?

我遇到了這篇文章,但在這里他們沒有對融合雲中的架構注冊表應用任何身份驗證。

這段代碼對我有用:

private val schemaRegistryUrl = "<schemaregistryURL>"   
val props = Map("basic.auth.credentials.source" -> "USER_INFO",
 "schema.registry.basic.auth.user.info" -> "<api-key>:<api-secret>").asJava

 private val schemaRegistryClient = new CachedSchemaRegistryClient(schemaRegistryUrl, 100,props)

我們需要確保在轉換為 JAVA 時我們正在執行正確的導入:

 import scala.collection.JavaConverters.mapAsJavaMapConverter

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM