Rabbitmq错误CachingConnectionFactory:1302-频道关闭:频道错误;

时间:2019-01-26 06:06:33

标签: rabbitmq spring-amqp spring-cloud-stream

我收到此错误

ERROR CachingConnectionFactory:1302-通道关闭:通道错误;协议方法:#method(reply-code = 406,reply-text = PRECONDITION_FAILED-虚拟主机'qa40'中队列'xyz.xyz.dlq'的等价arg'x-message-ttl':收到类型为'10000'的值'signedint',但当前为none,class-id = 50,method-id = 10)

我的配置文件中有此

spring.cloud.stream.bindings.xyz.destination=xyz
spring.cloud.stream.bindings.xyz.group=xyz_group
spring.cloud.stream.bindings.xyz.consumer.max-attempts=1
spring.cloud.stream.rabbit.bindings.xyz.consumer.republish-to-dlq=true
spring.cloud.stream.rabbit.bindings.xyz.consumer.requeue-rejected=false
spring.cloud.stream.rabbit.bindings.xyz.consumer.auto-bind-dlq=true
spring.cloud.stream.rabbit.bindings.xyz.consumer.dlq-ttl=10000
spring.cloud.stream.rabbit.bindings.xyz.consumer.dlq-dead-letter-exchange=

我正在使用延迟交换,即

public class xyzDlqConsumer extends RerouteDLQMessages {

    private final static String QUEUE_NAME = xyz.xyz_group;
    private final static String DLQ = QUEUE_NAME + ".dlq";

    public String getOriginalQueue() {
        return QUEUE_NAME;
    }

    @RabbitListener(queues = DLQ)
    private void callRepublish(Message failedMessage) {
        rePublish(failedMessage);
    }
}

public abstract class RerouteDLQMessages {

    private static final String X_RETRIES_HEADER = "x-retries";
    private static final String DELAY_EXCHANGE = "dlqReRouter";
    @Value("${RETRIES_COUNT}") . //3
    private Integer retriesCount;
    @Value("${DELAY_TIME}") //10000
    private Integer messageDelay;
    @Autowired
    private RabbitTemplate rabbitTemplate;


    protected abstract String getOriginalQueue();

    public void rePublish(Message failedMessage) {

        Map<String, Object> headers = failedMessage.getMessageProperties().getHeaders();
        Integer retriesHeader = (Integer) headers.get(X_RETRIES_HEADER);
        if (retriesHeader == null) {
            retriesHeader = Integer.valueOf(0);
        }

        if (retriesHeader < retriesCount) {
            headers.put(X_RETRIES_HEADER, retriesHeader + 1);
            headers.put("x-delay", messageDelay * retriesHeader);
            this.rabbitTemplate.send(DELAY_EXCHANGE, getOriginalQueue(), failedMessage);
        } else {

            //do whatever you want after three attempts
        }
    }

    @Bean
    public DirectExchange delayExchange() {
        DirectExchange exchange = new DirectExchange(DELAY_EXCHANGE);
        exchange.setDelayed(true);
        return exchange;
    }

    @Bean
    public Binding bindOriginalToDelay() {
        return BindingBuilder.bind(new Queue(getOriginalQueue())).to(delayExchange()).with(getOriginalQueue());
    }
}

1 个答案:

答案 0 :(得分:1)

错误消息说明了一切;

  

虚拟主机'qa40'中队列'xyz.xyz.dlq'的等价arg'x-message-ttl':接收到的值类型为'signedint'的值'10000',但当前值为none,class-id = 50,方法-id = 10)

队列是不可变的;创建它们后就无法更改它们的属性。

您正在尝试声明一个ttl设置为10000的队列,而已经存在一个没有ttl current is none的队列。

你不能那样做;如果要添加TTL,则必须删除并重新创建队列。