首页 文章

Spring Cloud 流并消耗多个kafka主题

提问于
浏览
3

我在一些 @StreamListener 消费多个主题的尝试中遇到了spring-boot-stream的问题 .

根据spring-cloud-stream docs:Accordidng to docs:

destination绑定中间件上通道的目标目标(例如,RabbitMQ交换或Kafka主题) . 如果通道绑定为使用者,则可以绑定到多个目标,并且可以将目标名称指定为逗号分隔的String值 . 如果未设置,则使用通道名称 . 无法覆盖此>属性的默认值 .

但是,在我使用下一个配置后:

spring:
  cloud:
    stream:
      bindings:
        testchannel:
          group: test
          destination: platform.metrics, platform.sleuth

现在我有下一个错误:

Caused by: java.lang.IllegalArgumentException: Topic name can only have ASCII alphanumerics, '.', '_' and '-'
    at org.springframework.cloud.stream.binder.kafka.utils.KafkaTopicUtils.validateTopicName(KafkaTopicUtils.java:39) ~[spring-cloud-stream-binder-kafka-core-1.2.1.RELEASE.jar:1.2.1.RELEASE]
    at org.springframework.cloud.stream.binder.kafka.provisioning.KafkaTopicProvisioner.provisionProducerDestination(KafkaTopicProvisioner.java:107) ~[spring-cloud-stream-binder-kafka-core-1.2.1.RELEASE.jar:1.2.1.RELEASE]
    at org.springframework.cloud.stream.binder.kafka.provisioning.KafkaTopicProvisioner.provisionProducerDestination(KafkaTopicProvisioner.java:60) ~[spring-cloud-stream-binder-kafka-core-1.2.1.RELEASE.jar:1.2.1.RELEASE]
    at org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.doBindProducer(AbstractMessageChannelBinder.java:110) ~[spring-cloud-stream-1.2.2.RELEASE.jar:1.2.2.RELEASE]
    ... 20 common frames omitted

如何将多个主题绑定到一个 @StreamListner 或从主题列表生成动态streamListeners?

1 回答

  • 1

    您只需要替换逗号和下一个目标值之间的空格,它将如下所示:

    spring:
        cloud:
            stream:
                bindings:
                    testchannel:
                        group: test
                        destination: platform.metrics,platform.sleuth
    

相关问题