rabbitmq Spring Cloud Stream Rabbit Binder为所有使用者共享并发

cl25kdpy  于 2022-11-23  发布在  RabbitMQ
关注(0)|答案(1)|浏览(158)

我尝试使用Spring Cloud Stream RabbitMQ绑定器集成我的应用程序。我有2个应用程序。生产者和消费者。在消费者应用程序中有2个输入通道,阅读不同的消息负载类型。我知道我们可以为输入通道定义并发设置。但在我的消费者应用程序中,所有输入通道应该共享相同并发性我意思是并发性设置应该由所有输入通道共享我找不到任何方法来完成这个
这是我在消费者应用程序中的设置。我知道我可以通过以下方式定义不同的并发数。但在我的情况下,并发数应该是5(机器的核心数),对于模拟1和模拟2通道

spring:
  autoconfigure:
    exclude: org.springframework.boot.actuate.autoconfigure.metrics.jdbc.DataSourcePoolMetricsAutoConfiguration
  application:
    name: simulator
  cloud:
    stream:
      function:
          definition: simulate1;simulate2
      rabbit:
        type: rabbit
        environment:
          spring:
            rabbitmq:
              host: localhost
              port: 5672
              username: guest
              password: guest
      kafka:
        binder:
          replicationFactor: 2
          auto-create-topics: true
          brokers: localhost:9092, localhost:9093, localhost:9094
          consumer-properties:
            key.deserializer: org.apache.kafka.common.serialization.StringDeserializer
            value.deserializer: org.springframework.kafka.support.serializer.JsonDeserializer
            spring:
              json:
                trusted:
                  packages: '*'
          configuration:
            value.deserializer: org.springframework.kafka.support.serializer.ErrorHandlingDeserializer
            key.deserializer: org.springframework.kafka.support.serializer.ErrorHandlingDeserializer
      bindings:
        simulate1-in-0:
          destination: pf-topic
          content-type: application/json
          group: service
          binder: rabbit
          consumer:
            use-native-decoding: true
            concurrency: 5
        simulate2-in-0:
              destination: pf-topic
              content-type: application/json
              group: service
              binder: rabbit
              consumer:
                use-native-decoding: true
                concurrency: 5
kcugc4gi

kcugc4gi1#

请参阅文档https://docs.spring.io/spring-cloud-stream/docs/current/reference/html/spring-cloud-stream.html#binding-properties

spring.cloud.stream.default.consumer.concurrency=5

相关问题