首页 > 解决方案 > Spring Cloud Stream:没有allowOverride,无法连接到2个rabbitmq集群

问题描述

我有一个带有以下配置的 Spring Boot 应用程序(我们称之为示例服务)来连接到 2 个不同的 rabbitmq 集群。


spring:
  cloud:
    stream:
      defaultBinder: rabbitA
      binders:
        rabbitA:
          inheritEnvironment: false
          defaultCandidate: false
          type: rabbit
          environment:
            spring:
              rabbitmq:
                addresses: rabbitmq-a:5672
                username: user-a
                password: password-a
        rabbitB:
          inheritEnvironment: false
          defaultCandidate: false
          type: rabbit
          environment:
            spring:
              rabbitmq:
                addresses: rabbitmq-b:5672
                  username: user-b
                  password: password-b
      bindings:
        dataFromA:
          destination: exchange-1
            group: queue-1
          binder: rabbitA
        dataFromB:
          destination: exchange-2
            group: queue-2
          binder: rabbitB

它本身工作正常,它连接到两个集群。问题是该服务部署在一个环境中,其中有一个带有以下文件的 spring 配置服务器:

应用程序.yml

spring.rabbitmq:
  addresses: rabbitmq-a:5672
  username: user-a
  password: password-a

然后这似乎覆盖了位于“环境”属性下的每个活页夹的配置集。所以我需要添加这个额外的配置。

示例服务.yml

spring.cloud:
  config:
    overrideSystemProperties: false
    allowOverride: true
    overrideNone: false

现在 example-service 再次连接到两个 rabbitmq 集群。但是我观察到了某些副作用,主要是无法再覆盖配置服务器 example-service.yml 中的其他属性,这对我来说是真正的需要。所以我放弃了使用 allowOverride 及其相关属性。

问题是......是否可以在不使用 allowOverride 的情况下使其工作,同时将 spring.rabbitmq.addresses/username/password 保留在远程配置服务器 application.yml 中?

非常感谢您提前。

亲切的问候。

标签: spring-bootrabbitmqspring-cloud-streamspring-amqp

解决方案


Which version are you using? I just tested it with 3.0.6 and it works fine:

spring:
  cloud:
    stream:
      binders:
        rabbitA:
          type: rabbit
          inherit-environment: false
          environment:
            spring:
              rabbitmq:
                virtual-host: A
        rabbitB:
          type: rabbit
          inherit-environment: false
          environment:
            spring:
              rabbitmq:
                virtual-host: B
      bindings:
        input1:
          binder: rabbitA
          destination: input1
          group: foo
        input2:
          binder: rabbitB
          destination: input2
          group: bar
  rabbitmq:
    virtual-host: /

enter image description here

Probably not related, but your group indentation is wrong.


推荐阅读