Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java ApacheCamel-两个连续执行的路由的相同源_Java_Apache Camel - Fatal编程技术网

Java ApacheCamel-两个连续执行的路由的相同源

Java ApacheCamel-两个连续执行的路由的相同源,java,apache-camel,Java,Apache Camel,我想从同一条路线依次执行两条路线 换句话说,我想启动这个执行流: from("route1")--> to("route2") //executed with output of route1 as source to("route3") //executed with output of route1 as source and executed after route2 finish 如何使用ApacheCamel实现这一点 亲切的问候像这样的事情应该可以 from(

我想从同一条路线依次执行两条路线

换句话说,我想启动这个执行流:

from("route1")-->
    to("route2") //executed with output of route1 as source
    to("route3") //executed with output of route1 as source and executed after route2 finish
如何使用ApacheCamel实现这一点


亲切的问候

像这样的事情应该可以

from("route1")
    .to("route2")
    .to("route3");

from("route2").process(exchange -> {

  Object body = exchange.getIn().getBody();
  // Processing logic......
  // Make sure you don't change the state of body.
  exchange.getIn().setBody(body);
});

from("route3").process(exchange -> {
  //This will have body from route1
  Object body = exchange.getIn().getBody();
})
您可以使用多播或无线监听,但这无助于您保持执行顺序,即路由3在路由2之后。

我相信这就是您要寻找的。每个收件人都会收到原始交换的副本。默认行为是连续的

例如:

from("direct:route1")
    .recipientList("direct:route2,direct:route3");

在您的route2中,从route1获取主体,然后在route2内部处理后,将相同主体从route1设置为exchange.GetIn,您可以使用这些路由的direct组件在它们之间进行路由,例如“direct:route2”、“direct:route3”等。实际系统比我解释的要复杂一些,因为route2是分布在不同项目中的十多条路由(为了简化示例,我将其解释为一条路由)。所以传播身体的想法很复杂,因为在这些路径中身体会发生变化。没有别的办法吗?我真的很抱歉,因为我忘了这个图案。这就是解决办法。谢谢