假设我有这样的路线。
<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>
结果图仅映射了这三个字段。
答案 0 :(得分: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 :(得分:-1)
您可以使用骆驼语(http://camel.apache.org/simple.html)访问JMS消息的内容(正文或属性):
<route>
<from uri="activemq:queue:someQueue"/>
<to uri="mybatis:select-items?statementType=${body}"/>
</route>