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

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

使用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();
    }

其中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;
}

原因

问题就在配置类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;
}

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

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值