是否可以使用avro在.yml中定义弹簧流输出粘合剂?

时间:2019-04-17 13:20:14

标签: java apache-kafka-streams spring-kafka

我正在构建一个spring-cloud-streams应用程序,其中输出是AVRO serde的,我设法使其正常工作,但是,我并不真的喜欢每个输出键/值的SpecificAvroSerde,我需要设置schemaRegistryUrl,调用配置

final SpecificAvroSerde serde = new SpecificAvroSerde();
serde.configure(
  Collections.singletonMap(
    AbstractKafkaAvroSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG, schemaRegistryUrl),
    true)

并使用.to(String topic,ProducedWith ...)下沉流,并且不能使用spring @SendTo("output")批注和流处理器定义。 在属性spring.cloud.stream.kafka.streams.bindings.output.producer中,可以设置keySerde和valueSerde,但没有效果,因为即使设置了schema.registry.url,它也不会自动配置自身。是否有可能只使用.yml配置

spring.cloud.stream:
  kafka.streams:
    binder:
      applicationId: stream-app
      brokers: localhost:9092
      autoCreateTopics: true
      configuration:
        schema.registry:
          url: http://localhost:8081
        commit.interval.ms: 1000
        default.key.serde: org.apache.kafka.common.serialization.Serdes$StringSerde
        default.value.serde: org.springframework.kafka.support.serializer.JsonSerde
    bindings:
      input:
        ...

      output:
        producer:
          keySerde: io.confluent.kafka.streams.serdes.avro.SpecificAvroSerde
          valueSerde: io.confluent.kafka.streams.serdes.avro.SpecificAvroSerde

  bindings:
    simple-data-stream-input:
      contentType: application/json
      destination: INPUT_TOPIC
    simple-data-stream-output:
      contentType: application/avro
      destination: OUTPUT_TOPIC

,流处理器定义

public interface SimpleDataStreamProcessor {
  @Input(SimpleDataStream.INPUT)
  KStream<?, ?> input();

  @Output(SimpleDataStream.OUTPUT)
  KStream<?, ?> output();
}

@StreamListener("input")
@SendTo("output")
public KStream<SomeAvroKey, SomeAvroValue> process(KStream<String, String> inputStream) {
   return ...;
}

0 个答案:

没有答案