在一个微服务中有可能有多个流吗?

up9lanfz  于 2021-06-04  发布在  Kafka
关注(0)|答案(1)|浏览(393)

在一个微服务中有可能有多个流?
这是我的名字。

bindings:
    input:
       destination: topic1
       content-type: application/*+avro
    output:
       destination: topic2
       content-type: application/*+avro

我能有更多的输入和输出吗?
每个流可以有不同的序列化类吗?

producer-properties:
  key.serializer: io.confluent.kafka.serializers.KafkaAvroSerializer
  value.serializer: io.confluent.kafka.serializers.KafkaAvroSerializer
1tu0hz3e

1tu0hz3e1#

是的,只需添加新绑定:

bindings:
        input:
          destination: topic1
          content-type: application/*+avro
        inputStream1:
          destination: topic_input_1
        inputStream2:
          destination: topic_input_2

        output:
          destination: topic2
          content-type: application/*+avro

        output2:
          destination: output_topic_2

并提供enablebinding和其他附加注解,如streamlistener:

@EnableBinding(MultipleDesBinding.class)
    public class YourApplication {

        @StreamListener
        @SendTo("output")
        public KStream<String, String> topology1(@Input("inputStream") KStream<String, String> inputKStream,
                                                 @Input("inputStream1") KStream<String, String> inputStream1KStream) {

        }

        @StreamListener
        @SendTo("output2")
        public KStream<String, Long> topology2(@Input("inputStream2") KStream<String, String> inputStream2KStream) {

        }
    }

    interface MultipleDesBinding {

        @Input("input")
        KStream<?, ?> input();

        @Input("inputStream1")
        KStream<?, ?> inputStream1();

        @Input("inputStream2")
        KStream<?, ?> inputStream2();

        @Output("output")
        KStream<?, ?> output();

        @Output("output2")
        KStream<?, ?> output2();

    }

您可以在文档:命令式编程模型中查看详细信息。

相关问题