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

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

问题描述

如果它是一个列表,我正在尝试有条件地将交换拆分为其内容,否则将其保留为单个项目,并且两者都转到同一个处理器

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

理想情况下,我不想设置很多中间直接:端点来实现这一点

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

我不明白为什么交换不作为单个单元保留,这就是当它离开时块"时它再次变成列表的方式.我感觉 Camel '期望'我使用 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.

推荐答案

目前camel的split组件的设置方式只有list下面的代码会作为单独的记录处理.关闭拆分块后,您将返回单个交换.打破这种局面的唯一方法是利用像直接端点这样的中点.如果你想分解逻辑,你总是可以创建单独的路由构建器类.另一种选择是在论坛上请求功能.

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是一个列表,我想有条件地拆分一个列表并继续处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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