【发布时间】:2023-11-11 01:11:01
【问题描述】:
我尝试在我的 java 代码中使用带有注释的死信交换。也许我的假设是错误的,它应该如何工作。但是在我的方法 processMpcMessage 中,我将消息从队列反序列化为 POJO。如果我收到 IllegalargumentException,我希望将消息放入死信队列。我配置了死信交换和路由键,请参阅我的代码示例。 如果我抛出“throw new AmqpRejectAndDontRequeueException(msg, exception);”我希望我之前消费的消息被放入死信队列。 我得到了以下调试消息:
2019-02-07 13:35:42,009 [SimpleAsyncTaskExecutor-1] DEBUG {} - org.springframework.amqp.rabbit.listener.BlockingQueueConsumer - 拒绝消息(requeue=false)
欢迎任何建议 问候 德克
@RabbitListener(bindings = @QueueBinding(
value = @Queue(
value = "${mpc.inbound.receive.queue}",
durable = "true",
arguments = {
@Argument(name = "x-dead-letter-exchange", value = "${mpc.inbound.dead.letter}"),
@Argument(name = "x-dead-letter-routing-key", value = "${mpc.inbound.receive.error.routing.key}"),
@Argument(name = "defaultRequeueRejected", value = "false")
}),
exchange = @Exchange(value = "${mpc.inbound.exchange}",
type = ExchangeTypes.TOPIC, durable = "true"),
key = "${mpc.inbound.routing.key}"
))
public void processMPCMessage(final Message message) {
//Here the message is deserialized in to a java object and this is where I want to throw a exception.
try{
}catch(IllegalArgumgenException ex){
throw new new AmqpRejectAndDontRequeueException(" a error message", ex);
}
}
【问题讨论】:
标签: rabbitmq spring-amqp