java - 发现以元素 'simple' 开头的无效内容。 Camel 问题

标签 java spring apache-camel dsl

我的要求是每隔几分钟轮询一次数据库并获取一条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/

相关文章:

java - 使用服务层模拟创建 Controller 测试,该测试将运行实际容器(例如 tomcat,可能会更改 spring 上下文文件)

java - 如何以编程方式从 OSGI 蓝图中获取 bean?

Java JFrame 两个框架同时显示问题

JavaFX LineChart - 从图表中清除数据

java - 如何在 Dijkstra 最短路径上获取路径

java - 与缓存相关的 HTTP header 在 App Engine 上的 Servlet 响应中被覆盖

java - Spring 中的日志消息银行

java - spring 表达了不满足的依赖...有时

java - 使用 Camel 调用 REST URL

apache-camel - Camel : "file" component, 但只将文件名作为正文传递