我的 Camel route 有一个分离器,看起来像这样......
from("direct:myRoute")
// Split each exchange into multiple sub-exchanges on the basis of MySplitter.class
// Configure the splitter to stop on exception that comes up during processing of each sub-exchange
// Configure the splitter to share unit of work with the main exchange that means processing of the entire Exchange is an atomic success/failure
.split().method(MySplitter.class).stopOnException().shareUnitOfWork()
//do something with each sub-exchange
.to("direct:processEachSubExchange")
.end();
我想做的是让 stopOnException
保持可配置。这意味着我想在外部化属性的帮助下启用/禁用在出现异常时停止的功能。
使用 Java DSL 可以实现这一点吗?
最佳答案
您还可以使用选择 block 来引导路线,然后您可以对异常进行内容特定的处理。
from("{{somewhere.in.endpoint}}")
.choice()
.when(header("endOnExceptionFlag").isEqualTo(true))
.to("direct:splitEndOnException")
.otherwise()
.to("direct:splitIgnoreExceptions")
.endChoice()
.end()
// process split with exception handling
.from("direct:splitEndOnException")
.split().method(MySplitter.class).stopOnException().shareUnitOfWork()
.to("direct:processEachSubExchange")
.end();
// process split ignoring exceptions
.from("direct:splitIgnoreExceptions")
.split().method(MySplitter.class).shareUnitOfWork()
.to("direct:processEachSubExchange")
.end();
关于java - 使用 Java DSL 使 Camel 拆分选项可配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28725687/