0
votes

I'm trying to set up RabbitMQ with Spring Cloud Stream Support

I have a couple consumers and producers. One of the producers should produce messages to a separate virtual host on a same RabbitMQ instance (later it might be different physical instances).

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

The goal is that binding tasks should use vhost virtual-host-2. Other bindings should use vhost virtual-host-1.

However binder value seems to be ignored and default rabbit binder is taken into account with default settings on application startup.

I noticed it while debugging the runtime:

enter image description here

The binder value on each binding is NULL. Although the value is explicitly provided in properties.

If I set defaultCandidate of any of the binders to true then that binder settings will be used as a replacement for default one.

Is something misconfigured?

2

2 Answers

0
votes

This is one of the reasons why I don't like yaml. It's hard to track what may be misconfigured. In any event, here is the working example I just tried.

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
0
votes

I just copied/pasted your config; fixed some indentation and it worked fine for me...

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();

}

and

enter image description here

      defaultCandidate: false
      inheritEnvironment: false

were incorrectly indented, but I got a YAML parse error.