【发布时间】:2020-02-14 22:47:46
【问题描述】:
我目前有 4 个队列:
- 测试队列
- 测试队列短期死信
- 测试队列长期死信
- 测试队列停车场
当邮件进入test-queue 时,我会检查邮件的格式是否正确。如果不是我想将消息直接发送到停车场队列。
我不能使用AmqpRejectAndDontRequeue(),因为它会自动将消息发送到配置的DLQ(test-queue-short-term-dead-letter)。
将RabbitTemplate.convertAndSend() 与另一个例外(例如BadRequestException)一起使用不起作用。该消息按预期进入停车场队列,但相同的消息将保留在test-queue
在程序继续执行时,单独使用RabbitTemplate.convertAndSend() 将不起作用。
所有队列都绑定到一个直接交换,每个队列都有唯一的路由键。 test-queue 配置有以下参数:
x-dead-letter-exchange: ""x-dead-letter-routing-key: <shortTermDeadLetterKey>
接收者:
@RabbitListener(queues = "test-queue")
public void receiveMessage(byte[] person) {
String personString = new String(person);
if (!personString.matches(desiredRegex)) {
rabbitTemplate.convertAndSend("test-exchange", "test-queue-parking-lot",
"invalid person");
log.info("Invalid person");
}
...some other code which I dont want to run as the message has arrived in the incorrect format
}
【问题讨论】:
标签: java rabbitmq message-queue spring-amqp