首页 > 解决方案 > 使用spring-cloud-stream发送rabbitmq消息时,无法指定发送的RoutingKey

问题描述

我使用的是 3.1.3 版本。如下配置后,'output-out-0.producer.bindingRoutingKey'不生效。当我发送消息时,路由键 = command_exchange_open 而不是: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

标签: javarabbitmqspring-cloud-stream

解决方案


routing-key-expression: '''ORDER_PUSH'''生产者属性不应该是bindingRoutingKey

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

这些属性不适用于生产者(除非您已required-groups设置)。


推荐阅读