当前位置:   article > 正文

invalid arg ‘x-message-ttl‘ for queue ‘xxx‘ in vhost ‘/‘: {unacceptable_type,longstr}_invalid arg 'x-message-ttl' for queue

invalid arg 'x-message-ttl' for queue

springboot rabbitmq bean方式自动创建queue失败

问题

具体报错内容如下:

2022-11-08 14:49:15,170 29895 [AMQP Connection xxx:5672] ERROR org.springframework.amqp.rabbit.connection.CachingConnectionFactory - Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=406, 
reply-text=PRECONDITION_FAILED - invalid arg 'x-message-ttl' for queue 'xxx' in vhost '/': {unacceptable_type,longstr}, class-id=50, method-id=10)
2022-11-08 14:49:15,172 29897 [main] INFO  org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer - Broker not available; cannot force queue declarations during start: java.io.IOException
  • 1
  • 2
  • 3

使用bean方式创建延迟队列queue

    @Bean
    public Queue messageTtlQueue() {
        return QueueBuilder.durable(ctDataTtl.getQueue())
            // 配置到期后转发的交换
            .withArgument("x-dead-letter-exchange", dataConsume.getExchange())
            // 配置到期后转发的路由键
            .withArgument("x-dead-letter-routing-key", dataConsume.getRoutingKey())
            // 延迟30分钟
            .withArgument("x-message-ttl", dataTtl.getTtl()).build();
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

其中dataTtl是配置类,配置ttl值

@Data
@Configuration
@ConfigurationProperties(prefix = "custom.rabbitmq.data-ttl")
public class DataTtl {
    private String exchange;
    private String queue;
    private String routingKey;
    private String ttl;
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

原因

问题就在配置类DataTtl 中, 其中ttl数据类型不能使用String类型,改为Long之后即可解决问题

解决

dataTtl配置类修改如下:

@Data
@Configuration
@ConfigurationProperties(prefix = "custom.rabbitmq.data-ttl")
public class DataTtl {
    private String exchange;
    private String queue;
    private String routingKey;
    private Long ttl;
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

重启jar包即可创建延迟队列。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/煮酒与君饮/article/detail/1018380
推荐阅读
相关标签
  

闽ICP备14008679号