繁体   English   中英

如何在不同的RabbitMQ虚拟主机上为Spring Cloud Stream Binding设置Binders

[英]How to set Binders for Spring Cloud Stream Bindings on different RabbitMQ vhosts

我正在尝试使用Spring Cloud Stream支持设置RabbitMQ

我有几个消费者和生产者。 其中一个生成器应该向同一个RabbitMQ实例上的单独虚拟主机生成消息(稍后它可能是不同的物理实例)。

application.yaml

spring:
  cloud:
    stream:
      binders:
        binder1:
          type: rabbit
            defaultCandidate: false
            inheritEnvironment: false
          environment:
            spring:
              rabbitmq:
                host: localhost
                port: 5672
                virtual-host: virtual-host-1
                username: guest
                password: guest
        binder2:
          type: rabbit
            defaultCandidate: false
            inheritEnvironment: false
          environment:
            spring:
              rabbitmq:
                host: localhost
                port: 5672
                virtual-host: virtual-host-2
                username: guest
                password: guest
      bindings:
        test:
          binder: binder1
        coordinates:
          destination: coordinates
          binder: binder1
        events:
          destination: events
          binder: binder1
        events_output:
          destination: events
          binder: binder1
        tasks:
          destination: tasks
          binder: binder2

目标是绑定tasks应该使用vhost virtual-host-2 其他绑定应使用vhost virtual-host-1

但是, binder值似乎被忽略,并且在应用程序启动时使用默认设置考虑默认的rabbit binder。

我在调试运行时注意到了它:

在此输入图像描述

所述binder在每个结合值是NULL。 尽管该值在属性中明确提供。

如果我将任何绑定器的defaultCandidate设置为true那么该绑定器设置将用作默认绑定器的替换。

有什么错误的配置?

这是我不喜欢yaml的原因之一。 很难跟踪可能配置错误的内容。 无论如何,这是我刚试过的工作示例。

spring:
  cloud:
    stream:
      bindings:
        input:
          binder: rabbit1
          group: vhost1-group
          destination: vhost1-queue
        output:
          binder: rabbit2
          destination: vhost2-queue
      binders:
        rabbit1:
          type: rabbit
          environment:
            spring:
              rabbitmq:
                host: localhost
                virtual-host: vhost1
        rabbit2:
          type: rabbit
          environment:
            spring:
              rabbitmq:
                host: localhost
                virtual-host: vhost2

我刚刚复制/粘贴了你的配置; 修复了一些缩进,它对我来说很好......

spring:
  cloud:
    stream:
      binders:
        binder1:
          type: rabbit
          defaultCandidate: false
          inheritEnvironment: false
          environment:
            spring:
              rabbitmq:
                host: localhost
                port: 5672
                virtual-host: virtual-host-1
                username: guest
                password: guest
        binder2:
          type: rabbit
          defaultCandidate: false
          inheritEnvironment: false
          environment:
            spring:
              rabbitmq:
                host: localhost
                port: 5672
                virtual-host: virtual-host-2
                username: guest
                password: guest
      bindings:
        test:
          binder: binder1
        tasks:
          destination: tasks
          binder: binder2
@SpringBootApplication
@EnableBinding(Foo.class)
public class So56462671Application {

    public static void main(String[] args) {
        SpringApplication.run(So56462671Application.class, args);
    }

}

interface Foo {

    @Input
    MessageChannel test();

    @Input
    MessageChannel tasks();

}

在此输入图像描述

      defaultCandidate: false
      inheritEnvironment: false

错误缩进,但我得到了一个YAML解析错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM