[英]Apache camel set mongodb collection dynamically
I'm trying to create a route where the endpoint depents on the incoming message. 我正在尝试创建一条路由,端点将在传入消息上使用该路由。 The aim is to write into a mongodb in different databases and collection.
目的是在不同数据库和集合中写入mongodb。
I'm looking for an easy way to get the information from the message header and write it in to the <to uri=""/>
我正在寻找一种简单的方法来从消息头中获取信息并将其写入
<to uri=""/>
<route> <from uri="jms:topic:BUS_IN" /> <to uri="mongodb:myDb?database=${header.someValue}&collection=storyTeaser&operation=save" /> </route>
Thanks a lot 非常感谢
You could add a second route that sets the header variables: 您可以添加第二条路由来设置标头变量:
<route>
<from uri="jms:topic:BUS_IN" />
<camel:setHeader headerName="CamelMongoDbDatabase">
<camel:simple>testmydb</camel:simple>
</camel:setHeader>
<camel:setHeader headerName="CamelMongoDbCollection">
<camel:simple>mycollection</camel:simple>
</camel:setHeader>
<to uri="jms:queue:mongodb.out"/>
</route>
And then add the parameter "dynamicity" in the uri of your first route: 然后在您的第一条路线的uri中添加参数“ dynamicity”:
<route>
<from uri="jms:queue:mongodb.out" />
<to uri="mongodb:myDb?database=new_test&collection=old&dynamicity=true&operation=save"/>
</route>
Using Apache Camels toD function https://camel.apache.org/message-endpoint.html will allow you to dynamically set the URI as messages are passed through. 使用Apache Camels toD函数https://camel.apache.org/message-endpoint.html将允许您在消息传递时动态设置URI。 The URI allows for simple language https://camel.apache.org/simple.html where we can for instance use the filename to generate a collection.
URI允许使用简单的语言https://camel.apache.org/simple.html ,例如,我们可以使用文件名来生成集合。
Heres an example Route: 以下是路线示例:
from(input).routeId("SampleRoute")
.toD("mongodb3://mongoBean?database=myDB&collection=${file:onlyname.noext}&" +
"operation=insert&createCollection=true")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.