java - Camel : Adding multiple to inside loop

标签 java apache-camel

我在代码中使用循环。我知道循环在出现第一个 to 时中断,如 Apache Camel: Route loop is lost when choice is added to the path 中所述。

现在,我有一个路由定义,我希望在循环结束之前在不同 channel 之间进行路由。例如:

.loop(simple("${header." + FILE_COUNT + "}"))
    .to("direct:file-iterator")
.end()

from("direct:file-iterator").id("file-iterator")
                                    .to("direct:read-file-checksum")    
                                    .to("direct:file-unzip")

对于这种情况有没有任何解决方法,因为在我的代码中只有第一次迭代后才执行第一个?

最佳答案

这条路线:

public void configure() {
   from("direct:start")
       .loop(2)
       .log("CamelLoopIndex = ${header.CamelLoopIndex}")
       .to("direct:file-iterator")
       .end();

   from("direct:file-iterator")
       .id("file-iterator")
       .log("  in file-iterator")
       .to("direct:read-file-checksum")
       .to("direct:file-unzip");

    from("direct:read-file-checksum")
       .log("    in read-file-checksum");

    from("direct:file-unzip")
       .log("    in direct:file-unzip");
    }
}

导致以下输出:

[main] route1                         INFO  CamelLoopIndex = 0
[main] file-iterator                  INFO    in file-iterator
[main] route2                         INFO      in read-file-checksum
[main] route3                         INFO      in direct:file-unzip
[main] route1                         INFO  CamelLoopIndex = 1
[main] file-iterator                  INFO    in file-iterator
[main] route2                         INFO      in read-file-checksum
[main] route3                         INFO      in direct:file-unzip

这就是我所期望的。如果此路线符合您的设置,那么您的问题不是循环问题,您应该查看direct:file-unzip路线。

关于java - Camel : Adding multiple to inside loop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22151930/

相关文章:

java - PersonQueue 不是抽象的,不会重写 Queue 中的抽象方法 addLast()

apache-camel - 为什么 Camel SCR 被弃用?

java - 使用cameltestsupport进行Camel单元测试,模板始终为空

java - 抛出 javax.validation.UnexpectedTypeException : HV000030 exception when validating Scala's Map with @NotEmpty

java - JGrapht:添加顶点和边后动态图错误

java - 如何将 JSON 字符串解析为 Jackson 中的 JsonNode?

java - 使用 hessian 从 android 发送 double 到 php 时出现解析错误

java - 在不同的类中创建 Camel 路线

apache-kafka - 如何用camel-kafka手动控制offset commit?

java - Apache-Camel:如何控制交换 header 的范围?