簡體   English   中英

Spring-cloud kafka stream 模式注冊表

[英]Spring-cloud kafka stream schema registry

我正在嘗試使用功能編程(和 spring 雲流)轉換來自輸入主題的輸入 AVRO 消息,並在 output 主題上發布新消息。 這是我的變換 function:

@Bean
public Function<KStream<String, Data>, KStream<String, Double>> evenNumberSquareProcessor() {
    return kStream -> kStream.transform(() -> new CustomProcessor(STORE_NAME), STORE_NAME);
}

CustomProcessor 是一個實現“Transformer”接口的 class。

我已經嘗試使用非 AVRO 輸入進行轉換,並且效果很好。

我的困難是如何在 application.yaml 文件或 spring 應用程序中聲明模式注冊表。

我嘗試了很多不同的配置(似乎很難找到正確的文檔),每次應用程序都找不到 schema.registry.url 的設置。 我有以下錯誤:

創建名為“kafkaStreamsFunctionProcessorInvoker”的 bean 時出錯:調用 init 方法失敗; 嵌套異常是 java.lang.IllegalStateException: org.apache.kafka.common.config.ConfigException: Missing required configuration "schema.registry.url" 沒有默認值。

這是我的 application.yml 文件:

    spring:
  cloud:
    stream:
      function:
        definition: evenNumberSquareProcessor
      bindings:
        evenNumberSquareProcessor-in-0:
          destination: input
          content-type: application/*+avro
          group: group-1
        evenNumberSquareProcessor-out-0:
          destination: output
      kafka:
        binder:
          brokers: my-cluster-kafka-bootstrap.kafka:9092
          consumer-properties:
            value.deserializer: io.confluent.kafka.serializers.KafkaAvroDeserializer
            schema.registry.url: http://localhost:8081

我也試過這個配置:

spring:
  cloud:
    stream:
      kafka:
        streams:
          binder:
            brokers: my-cluster-kafka-bootstrap.kafka:9092
            configuration:
              schema.registry.url: http://localhost:8081
              default.value.serde: io.confluent.kafka.streams.serdes.avro.SpecificAvroSerde
          bindings:
            evenNumberSquareProcessor-in-0:
              consumer:
                destination: input
                valueSerde: io.confluent.kafka.streams.serdes.avro.SpecificAvroSerde
            evenNumberSquareProcessor-out-0:
                destination: output

我的 spring 啟動應用程序是這樣聲明的,並激活了模式注冊表客戶端:

    @EnableSchemaRegistryClient
@SpringBootApplication
public class TransformApplication {
    public static void main(String[] args) {
        SpringApplication.run(TransformApplication.class, args);
    }
}

感謝您能給我帶來的任何幫助。

問候CG

在配置下configuration模式注冊表,然后它將可供所有活頁夾使用。 順便一提。 avro 序列化程序位於bindings和特定通道下。 如果你想使用默認屬性default.value.serde: 您的 Serde 也可能是錯誤的。

spring:
  cloud:
    stream:
      kafka:
        streams:
          binder:
            brokers: localhost:9092
            configuration:
              schema.registry.url: http://localhost:8081
              default.value.serde: io.confluent.kafka.streams.serdes.avro.SpecificAvroSerde
          bindings:
            process-in-0:
              consumer:
                valueSerde: io.confluent.kafka.streams.serdes.avro.SpecificAvroSerde

不要使用@EnableSchemaRegistryClient 在 Avro Serde 上啟用模式注冊表。 在此示例中,我使用的是您定義的 bean Data 嘗試在此處遵循此示例

@Service
public class CustomSerdes extends Serdes {

    private final static Map<String, String> serdeConfig = Stream.of(
            new AbstractMap.SimpleEntry<>(SCHEMA_REGISTRY_URL_CONFIG, "http://localhost:8081"))
            .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

    public static Serde<Data> DataAvro() {
        final Serde<Data> dataAvroSerde = new SpecificAvroSerde<>();
        dataAvroSerde.configure(serdeConfig, false);
        return dataAvroSerde;
    }
}

暫無
暫無

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

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