我有如下内容:
onException(Exception.class)
.maximumRedeliveries(2).redeliveryDelay(1000L).asyncDelayedRedelivery()
.log(LoggingLevel.ERROR, LOGGER, "Body before process ->> \"${body}\" for the cause of -> \"${exception.message}\"")
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
JSONObject obj = new JSONObject();
obj.put("body", exchange.getIn().getBody());
obj.put("errMsg", "testErrorMsg");
exchange.getIn().setBody(obj);
}
})
.log(LoggingLevel.ERROR, LOGGER, "Body after process ->> \"${body}\" for the cause of -> \"${exception.message}\"")
.setExchangePattern(ExchangePattern.InOnly).setFaultBody(constant(true))
.setHeader(RabbitMQConstants.REQUEUE, constant(Boolean.FALSE)).handled(false);
原始消息:
{"key" : "123" }
我希望在发送到 DLQ 时收到如下自定义消息:
{
"body": {
"key": "123"
},
"errMsg": "testErrorMsg"
}
在日志中,我可以看到正文按照我的预期进行了转换,但在 DLQ 队列中它显示了原始消息。
在发送到 DLQ 之前可以修改消息吗?
最佳答案
欢迎来到 StackOverflow!
您可以使用Deal Letter Channel EIP ,其 onPrepareFailure
添加自定义处理器
,在将Exchange
交付给DLQ之前对其进行修改。
关于java - 如何使用camel OnException将自定义对象发布到DLQ队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60321015/