![](/img/trans.png)
[英]How to handle exception using onException() in Spring Boot Camel
[英]How to publish custom object to DLQ queue using camel OnException
我有如下內容:
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
添加自定義Processor
,在將Exchange
交付給 DLQ 之前對其進行修改。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.