如果exxchange是一个List,我想有条件地拆分一个List并继续处理 [英] I want to conditionally split a List if exxchange is a List and continue processing

查看:186
本文介绍了如果exxchange是一个List,我想有条件地拆分一个List并继续处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图有条件地将交换(如果它是一个列表)拆分为其内容,否则将其保留为单个项目,并且都使用同一处理器

I'm trying to conditionally split an exchange into its contents if it is a List, otherwise leave it as a single item and have both go to the same processor

理想情况下,我不想在direct:端点之间设置很多来实现这一目标

I ideally do not want to set up lots of inbetween direct:endpoints to achieve this

from( X )
    .when( body().isInstanceOf( List.class )
        .split( body() )
        .setHeader( "x", constant( "I don't care " ) // this needs to be set as split must have at least one child node
        .process( ? ) // here the exchange.in.body is now a single item from the List // this is what I want to continue outside of this when block
    .end() // also tried .end().end() and .endChoice()
    .process( ... ) // here the exchange in is a List again, I want it to be the single items, split

我不明白为什么不将交换留为单个单位,也就是说,当它离开when'block'时,它将如何再次成为List. 我觉得骆驼期望"我使用direct:endpoints来实现这一目标,但是我发现使用更多直接点时,可读性会迅速下降,并且希望尽可能避免使用它们.

I do not understand why the exchange is not left as single units, that is how it becomes a List again when it leaves the when 'block'. I get the feeling Camel 'expects' me to use direct:endpoints to achieve this, but I find readability decreases quickly the more direct points are used and want to avoid them if possible.

推荐答案

当前,骆驼的拆分组件的设置方式仅是列表下面的代码将作为单独的记录进行处理.关闭拆分块后,您将返回到单个交换机.打破这种局面的唯一方法是利用像直接端点这样的中点.如果要分解逻辑,则可以始终创建单独的路由构建器类.另一种选择是在论坛上请求功能.

Currently the way camel's split component is setup only the code underneath a list will process as individual records. Once you close the split block you are back to a single exchange. The only way to break that up would be to leverage a mid point like a direct endpoint. If you want to break up the logic you can always create separate route builder classes. The other option is to request a feature on the forums.

这篇关于如果exxchange是一个List,我想有条件地拆分一个List并继续处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆