我的要求是每隔几分钟轮询一次数据库并获取一条sql。因此我的代码是
<camel:route>
<camel:from uri="timer:dataRetrieve?period=5s"/>
<camel:to uri="sql:select output_obj,create_dt,destination_type from dbo.gcas_events_test where process_sw = 'N' order by create_dt desc" />
</camel:route>
我期望数据集中有 3 个字段。我想看看destination_type='SEC' 是否必须走不同的路线。
所以我想出了。
<camel:route>
<camel:from uri="timer:dataRetrieve?period=5s"/>
<camel:to uri="sql:select output_obj,create_dt,destination_type from dbo.gcas_events_test where process_sw = 'N' order by create_dt desc" />
<camel:choice>
<camel:when>
<simple>${body.destination_type}='SEC'</simple>
<camel:to uri="foo" />
</camel:when>
</camel:choice>
</camel:route>
它会在简单标记处引发错误。 ognl 也有类似的问题。我在这里做错了什么? ${body.destination_type}='SEC'
也能工作吗? (假设我在数据集中有该值)。
最佳答案
根据Camel doc , select 语句的输出是 List<Map<String, Object>>
如果没有进行不同的配置。在你的情况下,第一个 destination_type
可以按如下方式访问结果集中找到的内容:
${body[0][destination_type]}
路由定义应如下所示(使用 ==
而不是简单的 =
):
<camel:route>
<camel:from uri="timer:dataRetrieve?period=5s"/>
<camel:to uri="sql:select output_obj,create_dt,destination_type from dbo.gcas_events_test where process_sw = 'N' order by create_dt desc" />
<camel:choice>
<camel:when>
<camel:simple>${body[0][destination_type]} == 'SEC'</simple>
<camel:to uri="foo" />
</camel:when>
</camel:choice>
</camel:route>
如果结果集中的每条记录都需要一条一条的处理,那么你可以使用 splitter :
<camel:route>
<camel:from uri="timer:dataRetrieve?period=5s"/>
<camel:to uri="sql:select output_obj,create_dt,destination_type from dbo.gcas_events_test where process_sw = 'N' order by create_dt desc" />
<camel:split>
<camel:simple>${body}</camel:simple>
<camel:choice>
<camel:when>
<camel:simple>${body[destination_type]} == 'SEC'</simple>
<camel:to uri="foo" />
</camel:when>
</camel:choice>
</camel:split>
</camel:route>
关于java - 发现以元素 'simple' 开头的无效内容。 Camel 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23769789/