我有一个制片人:

rabbitTemplate.convertAndSend(QueueConstants.PROVISIONING_EXCHANGE, QueueConstants.PROVISIONING_ROUTING_KEY, message);


而我的配置:

@Bean
Queue organizationProvisioningQueue() {
    return QueueBuilder.durable(QueueConstants.PROVISIONING_QUEUE)
            .withArgument("x-dead-letter-exchange", "")
            .withArgument("x-dead-letter-routing-key", QueueConstants.DEAD_LETTER_QUEUE)
            .build();
}

@Bean
Queue deadLetterQueue() {
    return QueueBuilder.durable(QueueConstants.DEAD_LETTER_QUEUE).build();
}

@Bean
DirectExchange exchange() {
    return new DirectExchange(QueueConstants.PROVISIONING_EXCHANGE);
}

@Bean
Binding binding() {
    return BindingBuilder.bind(organizationProvisioningQueue()).to(exchange()).with(QueueConstants.PROVISIONING_ROUTING_KEY);
}


和我的消息处理器:

@RabbitListener(queues = QueueConstants.PROVISIONING_QUEUE)
public void process(ProvisioningMessage message) throws ProvisioningException {
    System.out.println("Processing " + message);

    throw new ProvisioningException ("Some ex " + message);
}


和常量:

public static final String PROVISIONING_EXCHANGE = "provisioning-exchange";
public static final String PROVISIONING_ROUTING_KEY = "provisioning";
public static final String PROVISIONING_QUEUE = "provisioning-queue";

public static final String DEAD_LETTER_QUEUE = PROVISIONING_QUEUE + ".dlq";


死信队列不起作用,因为在引发异常后每次都会对消息进行重新排队,从而导致死循环,而不是进入死信队列。

由于已建议,但我也将队列名称也更改为以.dlq结尾,但仍然没有成功。
我究竟做错了什么?

最佳答案

您需要抛出AmqpRejectAndDontRequeueException或将侦听器容器的defaultRequeueRejected属性设置为false

dlq的名称无关紧要。

10-07 13:09