【问题标题】:Bind default RabbitMQ exchange to the default exchange将默认 RabbitMQ 交换绑定到默认交换
【发布时间】:2021-05-20 09:47:52
【问题描述】:

我需要将扇出交换绑定到 Spring Boot RabbitMQ 客户端中的默认交换,但我做不到。当我尝试下面的代码时,我没有看到任何错误,但没有绑定交换(至少它没有显示在 rabbitmq admin 中,消息也没有路由到该交换)。我的代码:

带有路由键 testq 放入 testex 交换的消息消失了 - 没有传递到 testq 队列。

    @Bean
    FanoutExchange testExchange() {
        return new FanoutExchange("testex");
    }
    
    @Bean
    Binding testExchangeToDefaultBinding() {
        return new Binding("", DestinationType.EXCHANGE, "testex", null, null);
    }
    
    @Bean
    Queue testQueue() {
        return new Queue("testq");
    }

这样绑定不行吗?

编辑:还有其他方法可以做类似的事情吗?

【问题讨论】:

    标签: spring-boot rabbitmq


    【解决方案1】:

    默认交换是直接交换,没有经纪人预先声明的名称(空字符串)。

    默认交换器隐式绑定到每个队列,路由键等于队列名称。无法显式绑定或取消绑定默认交换。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-30
      • 1970-01-01
      • 2012-12-17
      • 1970-01-01
      • 1970-01-01
      • 2013-05-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多