我在代码中使用循环。我知道循环在出现第一个 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/