Camel Splitters 在执行后会保留交换体吗?

Do Camel Splitters preserve exchange body after they execute?

Java 8 和 Apache Camel 2.19.5 在这里。我有以下 bean 处理器:

@Component("foobarResolver")
public class FoobarResolver {
  public List<Foobar> resolve(Fizzbuzz fizzbuzz) {
    List<Foobar> foobars = new ArrayList<Foobar>();

    // Use some logic in here to make the fizzbuzz populate the foobars list.

    return foobars;
  }
}

@Component("fizzbuzzProcessor")
public class FizzbuzzProcessor {
  public FizzbuzzOutput process(Fizzbuzz fizzbuzz) {
    // Blah whatever
  }
}

以及以下 Camel 路线:

<route id="fizzbuzzHandler">
  <!-- XML '<fizzbuzz>' messages get sent here by an upstream process -->
  <from uri="activemq:fizzbuzzes"/>

  <!-- Use XStream to deserialize the XML into a 'Fizzbuzz' POJO instance -->
  <unmarshal ref="xs"/>

  <split>
    <method ref="bean:foobarResolver"/>
    <to uri="activemq:analyze"/>
  </split>

  <!-- Now assuming our body is once again the Fizzbuzz we can just continue as normal... -->

  <!-- Process the fizzbuzz -->
  <to uri="bean:fizzbuzzProcessor"/>

  <!-- Send fizzbuzzProcessor's output to 'output' queue -->
  <to uri="activemq:output"/>
</route>

正如您所见,反序列化的 Fizzbuzz 实例被发送到 FoobarResolver bean 处理器,后者将该实例转换为 List<Foobar>,然后发送每个 Foobar 进入 analyze 队列,一个接一个。至少那是我设计的意图!

我很好奇的是:分裂之后,交换体变成了什么?是 "revert" 回到 Fizzbuzz(这是我想要的),还是交换体现在是由 FoobarResolver 产生的 List<Foobar>(这不是我想要的)?如果正文现在是 List<Foobar>,我该如何重新配置​​以使 FizzbuzzProcessor 接收到 Fizzbuzz

出现恢复到pre-split body:

@SpringBootApplication
public class SocamelApplication extends RouteBuilder implements ApplicationRunner {
    @Autowired
    private FooProcessor fooProcessor;

    public static void main(String[] args) {
        SpringApplication.run(SocamelApplication.class, args);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        Thread.sleep(5000);
    }

    @Override
    public void configure() throws Exception {
        from("timer://foo?period=100&repeatCount=1").setBody()
                                                    .constant(Arrays.asList("Hello", "World"))
                                                    .log("1 >>> ${body} ")
                                                    .split(body())
                                                    .log("2 >>> ${body}")
                                                    .bean(fooProcessor)
                                                    .log("3 >>> ${body}")
                                                    .end()
                                                    .log("4 >>> ${body}");

    }

    @Bean
    public FooProcessor fooProcessor() {
        return new FooProcessor();
    }

}

class FooProcessor implements Processor {

    @Override
    public void process(Exchange exchange) throws Exception {
        String reverseMe = exchange.getIn()
                                   .getBody(String.class);

        String reversed = new StringBuilder(reverseMe).reverse()
                                                      .toString();

        exchange.getOut()
                .setBody(reversed);
    }

}

产量:

1 >>> Hello,World 
2 >>> Hello
3 >>> olleH
2 >>> World
3 >>> dlroW
4 >>> Hello,World