Apache camel route,activemq和mybatis - 传递参数

问题描述 投票:0回答:2

假设我有这样的路线。

        <route>
            <from uri="activemq:queue:someQueue"/>
            <to uri="mybatis:select-items?statementType=SelectOne"/>
        </route>

如何从activemq获取消息并将其传递给mybatis select? (这只是一个字符串)

@编辑。

我想得到这样的字符串:category1, category2

我的选择看起来像:

<select id="select-authors" resultMap="authors-result">
                SELECT
                 name, age, category
                FROM author
                WHERE category IN
                <foreach item="item" index="index" collection="categories"
                 open="(" separator="," close=")">
                    #{item}
                 </foreach>
     </select>

结果图只是映射这3个字段。

apache-camel activemq mybatis
2个回答
0
投票

因此,如果您有一个来自activemq使用者的“category1,category2”字符串,您需要从中进行收集以进行mybatis foreach处理。我使用java dsl做示例因为它会更快。

from("activemq:queue:someQueue")
            .process(exchange -> {
                String jmsString = exchange.getIn().getBody(String.class);
                List<String> strings = Arrays.asList(jmsString.split(","));
                exchange.getIn().setBody(strings);
            })
            .to("mybatis:select-items?statementType=SelectOne");

并改变映射如:

<select id="select-authors" parameterType="java.util.List" resultMap="authors-result">
            SELECT
             name, age, category
            FROM author
            WHERE category IN
            <foreach item="item" collection="list"
             open="(" separator="," close=")">
                #{item}
             </foreach>
 </select>

这应该工作。更多有用的例子,你可以找到here


-1
投票

您可以使用Camel简单语言(http://camel.apache.org/simple.html)来访问JMS消息的内容(正文或属性):

<route>
   <from uri="activemq:queue:someQueue"/>
   <to uri="mybatis:select-items?statementType=${body}"/>
</route>
© www.soinside.com 2019 - 2024. All rights reserved.