【问题标题】:Does a binding need to match the arguments/settings with the queue in Spring RabbitMQ?绑定是否需要将参数/设置与 Spring RabbitMQ 中的队列匹配?
【发布时间】:2021-11-10 19:40:19
【问题描述】:

鉴于 Spring Boot 中的以下 Queue (RabbitMQ) bean...

@Bean
Queue exampleQueue() {
    return QueueBuilder.durable("exampleQueue")
            .quorum()
            .singleActiveConsumer()
            .build();
}

@Bean
public DirectExchange directExchange() {
    return ExchangeBuilder.directExchange("direct-exchange")
            .durable(true)
            .build();
}

...我在我正在审查的代码中发现了以下Binding 定义:

@Bean
Binding exampleBinding(DirectExchange directExchange, Queue exampleQueue) {
    final Binding binding = BindingBuilder.bind(exampleQueue)
            .to(directExchange)
            .with("example-routing-key");
    binding.addArgument("x-queue-type", "quorum");
    binding.addArgument("x-single-active-consumer", "true");
    return binding;
}

我的问题是:这些额外的参数 x-queue-type 和 x-single-active-consumer 是否有必要?我的理解是,队列已经定义了这些设置,因此绑定不会显式重复它们?

【问题讨论】:

  • 一旦队列被声明,你就不需要在绑定中为它们添加参数了。

标签: rabbitmq spring-amqp


【解决方案1】:

那些是队列参数,而不是绑定参数,所以,不,它们不是必需的;大概 RabbitMQ 只是忽略了它们。

【讨论】:

    猜你喜欢
    • 2014-03-30
    • 1970-01-01
    • 2022-12-03
    • 2012-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-25
    • 1970-01-01
    相关资源
    最近更新 更多