【问题标题】:SpringCloudStream - how to create delayed exchange?SpringCloudStream - 如何创建延迟交换?
【发布时间】:2018-02-08 01:03:39
【问题描述】:

我想创建来自rabbitMQ plugin 的延迟交换。

一开始我尝试使用弹簧活页夹,如我所见,delayed-exchange 标志可用:

spring:
  cloud:
    stream:              
      bindings:
        delayed-ex:
          group: update-delayed
          contentType: application/json
          consumer:
            max-attempts: 1
      rabbit:
        bindings:
          delayed-ex:
            consumer:
              transacted: true
              auto-bind-dlq: true
              republish-to-dlq: true
              delayed-exchange: true
              requeue-rejected: false  

不幸的是,这个配置让我创建了简单的topic 交换,没有任何标志。

我可以使用以下方法创建 bean:

@Bean
public CustomExchange delayedExchange() {
    final Map<String, Object> args = new HashMap<>();
    args.put("x-delayed-type", "topic");     
    return new CustomExchange("delayed-ex", "x-delayed-message", true, false, args);
}

它正在使用当前配置,但它给了我关于我想要覆盖的现有交换的堆栈跟踪:

原因:com.rabbitmq.client.ShutdownSignalException:通道错误;协议方法:#method(reply-code=406,reply-text=PRECONDITION_FAILED - 不等价的 arg 'type' 用于在 vhost '/' 中交换 'delayed-ex':收到 'topic' 但当前是 ''x-delayed-message '', class-id=40, method-id=10)

另一件事(不知道是不是问题)我想让消费者和生产者在同一个服务中,只是为了为我的消息提供缓冲区。

另外,我检查了delayed-exchange 标志的来源,发现这个标志完全没有做任何事情(我错了吗?),因为没有调用来自AbstractExchangeisDelayed 方法。

是否可以声明类型为x-delayed-message 的延迟交换并通过配置来完成,而不是声明bean?我也想删除那个堆栈跟踪

【问题讨论】:

    标签: java spring rabbitmq


    【解决方案1】:

    问题在于 spring-rabbit 依赖项的错误版本。我使用了1.5.6.RELEASE,它不使用isDelayed() 方法。将其更改为1.7.3.RELEASE 版本即可解决问题。

    我删除了我的自定义 bean 并创建了这个配置:

    spring  
      cloud:
        stream:              
          bindings:
            delayed-ex:
              group: update-delayed
              contentType: application/json
              consumer:
                max-attempts: 1
          rabbit:
            bindings:
              delayed-ex:
                consumer:
                  transacted: true
                  auto-bind-dlq: true
                  republish-to-dlq: true
                  delayed-exchange: true
                  requeue-rejected: false     
                producer:
                  delayed-exchange: true 
    

    现在,交换和队列由配置自动创建,无需任何堆栈跟踪。

    【讨论】:

      猜你喜欢
      • 2015-02-15
      • 2021-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多