【问题标题】:Apache camel route, activemq and mybatis - passing argumentApache骆驼路由、activemq和mybatis——传参
【发布时间】:2018-09-12 18:19:53
【问题描述】:

假设我有这样的路线。

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

如何从activemq获取messaeg并将其传递给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 个字段。

【问题讨论】:

  • 请更新您的问题并提供更多详细信息。什么消息被发送到 someQueue ?选择项查询的映射看起来如何?

标签: apache-camel activemq mybatis


【解决方案1】:

所以如果你有一个来自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

【讨论】:

    【解决方案2】:

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

    <route>
       <from uri="activemq:queue:someQueue"/>
       <to uri="mybatis:select-items?statementType=${body}"/>
    </route>
    

    【讨论】:

    • 为什么要将 body 对象设置为 statementType 参数?根据文档,它需要是 StatementType 枚举值。
    • 对不起,我显然误解了这个问题。它认为这是关于如何将 JMS 消息(正文)作为目标 uri 的参数/参数传递......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-05
    • 2014-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多