我尝试在我的Java代码中使用带有注释的死信交换。我的假设也许是错误的,它应该如何工作。但是在我的方法processMpcMessage中,我将消息从队列反序列化为POJO。如果收到IllegalargumentException,我希望将消息放入死信队列。我配置了死信交换和路由密钥,请参见我的代码示例。 如果我抛出“抛出新的AmqpRejectAndDontRequeueException(msg,异常);”我希望将我先前使用的消息放入死信队列中。 我得到以下调试消息:
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);
}
}
答案 0 :(得分:1)
队列已经存在吗?
队列是幂等的;创建它们后,您将无法更改它们的属性(参数)。首先将其删除,以便重新创建。
如果不是那样,请打开DEBUG日志记录以查看发生了什么。