当捕获异常时,有什么方法可以停止路由执行(显示日志消息后)?
<doTry>
<process ref="messageProcessor"/>
<doCatch>
<exception>java.lang.IllegalArgumentException</exception>
<log message="some message related to the exception" />
</doCatch>
</doTry>
请提供一种在 Spring DSL 中实现此目的的方法。我已经尝试过
最佳答案
在 doCatch 中添加了一个进程,该进程停止的是 Camel 上下文。
<doTry>
<process ref="messageProcessor"/>
<doCatch>
<exception>java.lang.IllegalArgumentException</exception>
<handled>
<constant>true</constant>
</handled>
<setHeader headerName="exceptionStackTrace">
<simple>${exception.stacktrace}</simple>
</setHeader>
<process ref="mandatoryParameterIsNull"/>
</doCatch>
</doTry>
处理器:
@Component
public class MandatoryParameterIsNull implements Processor{
Logger log = Logger.getLogger(MandatoryParameterIsNull.class);
@Override
public void process(Exchange exchange) throws Exception {
if (log.isDebugEnabled()) {
log.debug("Some parameter is mandatory");
log.debug(exchange.getIn().getHeader("exceptionStackTrace"));
}
exchange.getContext().getShutdownStrategy().setLogInflightExchangesOnTimeout(false);
exchange.getContext().getShutdownStrategy().setTimeout(60);
exchange.getContext().stop();
}
}
关于apache-camel - Camel - 如何在异常时停止路由执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32379367/