java - 使用 Java DSL 使 Camel 拆分选项可配置

标签 java spring properties split apache-camel

我的 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/

相关文章:

java - 使用 StringBuilder 连接查询字符串

java - 从对象中检索 bean 属性值

java - 使用命令行参数加载属性文件 - Java

objective-c - 如何动态确定 Objective-C 属性类型?

java - HtmlUnit获取页面源码实现显示Exception

java - 那个旧的 AVD 在哪里?我应该选择什么 'Screen'?

java - 为什么 spring rest 文档使用 MockMvcBuilders.webAppContextSetup?

java - 使用 jpa 和 hibernate 的 Spring Security

ios - 读写属性是否需要@synthesize?

java - 配置问题 : spring-security-web classes are not available. 你需要这些才能使用 <filter-chain-map>