骆驼路由问题

时间:2013-11-07 12:34:01

标签: apache-camel

我创建了一些路线。以下是有问题的代码。 以下是预期的行为:

  1. Exchange首先在hourlyFeedParts队列处理,然后传递给dailyProcessor。
  2. 在dailyProcessor中,正在检查属性currHour是否为23。如果没有,它只是传递。
  3. 如果currHour == 23,则应处理其中的代码。这部分再次具有以下功能,

    • 如果属性feedsleft不为零,则执行选择currHour==23内的所有代码。这很好。
    • 如果属性feedsLeft为零,则处理其中的代码。代码内查找任何其他消息。如果是,则将其发送至hourlyFeedParts问题出现了:如果有任何要处理的消息,则不会执行to("direct:hourlyFeedParts")之外的代码。但是,如果没有返回任何内容,代码工作正常。
  4. 我想问题可能是代码在to结束。那么,替代方案是什么呢?

    from("direct:dailyProcessor")
      .choice()
        .when(simple("${property.currHour} == 23"))
        .choice()
          .when(simple("${property.feedsLeft} == 0"))
          .split(beanExpression(APNProcessor.class, "recheckFeeds"))
          .to("direct:hourlyFeedParts")
        .endChoice()
      .end()
      .split(beanExpression(new S3FileKeyProcessorFactory(), "setAPNS3Header"))
      .parallelProcessing()
      .id("APN Daily PreProcessor / S3 key  generator ")
      .log("Uploading file ${file:name}")
      .to("{{apn.destination}}")
      .id("APN Daily S3 > uploader")
    .log("Uploaded file ${file:name} to S3")
    .endChoice()
    .end()
    

1 个答案:

答案 0 :(得分:0)

我认为问题是嵌套选择()。

尝试将内在选择提取到单独的路径,例如:

from("direct:dailyProcessor")
  .choice()
    .when(simple("${property.currHour} == 23"))
       .to("direct:inner")
  .split(beanExpression(new S3FileKeyProcessorFactory(), "setAPNS3Header"))
  .parallelProcessing()
  .id("APN Daily PreProcessor / S3 key  generator ")
  .log("Uploading file ${file:name}")
  .to("{{apn.destination}}")
  .id("APN Daily S3 > uploader")
.log("Uploaded file ${file:name} to S3");

from("direct:inner")
   .choice()
      .when(simple("${property.feedsLeft} == 0"))
      .split(beanExpression(APNProcessor.class, "recheckFeeds"))
      .to("direct:hourlyFeedParts");

我没有测试过,但我想你明白了。