【问题标题】:Spring Cloud Stream: consume from default Rabbit MQ exchange and specific queueSpring Cloud Stream:从默认的 Rabbit MQ 交换和特定队列消费
【发布时间】:2018-05-15 08:09:20
【问题描述】:

是否可以通过 Spring Cloud Stream 从隐式绑定到默认 RabbitMQ 交换的某些特定队列中消费?

正如我在BindingService.bindConsumer(...) 的调试中看到的那样,如果我将destination 指定为空字符串(yaml 中的''),bindingTargets 字符串数组为空,因此不会发生绑定消费者(binder.bindConsumer(...))。

我可能的解决方法是指定一些随机目的地并将标志 queueNameGroupOnly 设置为 true

【问题讨论】:

    标签: spring-cloud-stream


    【解决方案1】:

    默认情况下,消费者使用路由键 # 将队列 @9​​87654322@ 绑定到主题交换 destination

    the documentation

    queueNameGroupOnly

    如果为 true,则从名称与组相同的队列中消费。否则队列名称为destination.group。这很有用,例如,当使用 Spring Cloud Stream 从现有的 RabbitMQ 队列中消费时。

    默认值:假。

    要从仅绑定到默认交换的现有队列中消费,您需要。

    spring.cloud.stream.bindings.input.destination=<doesn't matter, can be omitted; defaults to input>
    spring.cloud.stream.bindings.input.group=<the name of the queue>
    spring.cloud.stream.rabbit.bindings.input.consumer.bind-queue=false
    spring.cloud.stream.rabbit.bindings.input.consumer.queue-name-group-only=true
    spring.cloud.stream.rabbit.bindings.input.consumer.declare-exchange=false
    

    queueNameGroupOnly 是专门为此用例添加的。

    【讨论】:

      【解决方案2】:

      有可能,您只需要指定应该将“输入”和/或“输出”绑定到哪个目的地。 您可以通过以下属性执行此操作:

      spring.cloud.stream.bindings.input.destination=<the name of the input queue>
      spring.cloud.stream.bindings.input.group=<the name of the input group>
      
      spring.cloud.stream.bindings.output.destination=<the name of the output exchange>
      

      【讨论】:

      • 比这复杂一点;看我的回答。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-18
      • 2019-07-17
      • 2023-01-30
      • 2017-04-28
      • 1970-01-01
      • 2018-03-02
      • 1970-01-01
      相关资源
      最近更新 更多