Search code examples
javarabbitmqspring-cloud-stream

When I use spring-cloud-stream to send rabbitmq messages, I cannot specify the RoutingKey sent


I use the 3.1.3 version. After the following configuration,'output-out-0.producer.bindingRoutingKey' does not take effect. When I send a message, Routing keys = command_exchange_open instead of: ORDER_PUSH

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-stream-binder-rabbit</artifactId>
</dependency>

spring:
  rabbitmq:
    addresses: amqp://sycx:sycx@192.168.1.204
  cloud:
    stream:
      rabbit:
        bindings:
          input-in-0:
            consumer:
              bindingRoutingKey: ORDER_PUSH
              exchangeType: direct
              queueNameGroupOnly: true
          output-out-0:
            producer:
              bindingRoutingKey: ORDER_PUSH
              queueNameGroupOnly: true
              bindQueue: false
      bindings:
        input-in-0:
          destination: command_exchange_open
          group: ORDER_END
        output-out-0:
          destination: command_exchange_open
          group: ORDER_END
    function:
      definition: input;output

Solution

  • The producer property should be routing-key-expression: '''ORDER_PUSH''' not bindingRoutingKey.

              output-out-0:
                producer:
                  bindingRoutingKey: ORDER_PUSH
                  queueNameGroupOnly: true
                  bindQueue: false
    

    These properties do not apply to producers (unless you have required-groups set).