Apache camel 动态设置 mongodb collection
Apache camel set mongodb collection dynamically
我正在尝试创建一个端点取决于传入消息的路由。目的是在不同的数据库中写入一个mongodb和collection。
我正在寻找一种简单的方法来从消息 header 中获取信息并将其写入 <to uri=""/>
<route>
<from uri="jms:topic:BUS_IN" />
<to uri="mongodb:myDb?database=${header.someValue}&collection=storyTeaser&operation=save" />
</route>
非常感谢
您可以添加第二条路线来设置 header 变量:
<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>
然后在你的第一个路由的uri中添加参数"dynamicity":
<route>
<from uri="jms:queue:mongodb.out" />
<to uri="mongodb:myDb?database=new_test&collection=old&dynamicity=true&operation=save"/>
</route>
使用 Apache Camels toD 函数 https://camel.apache.org/message-endpoint.html will allow you to dynamically set the URI as messages are passed through. The URI allows for simple language https://camel.apache.org/simple.html 例如,我们可以在其中使用文件名生成集合。
这是一个示例路线:
from(input).routeId("SampleRoute")
.toD("mongodb3://mongoBean?database=myDB&collection=${file:onlyname.noext}&" +
"operation=insert&createCollection=true")
我正在尝试创建一个端点取决于传入消息的路由。目的是在不同的数据库中写入一个mongodb和collection。
我正在寻找一种简单的方法来从消息 header 中获取信息并将其写入 <to uri=""/>
<route>
<from uri="jms:topic:BUS_IN" />
<to uri="mongodb:myDb?database=${header.someValue}&collection=storyTeaser&operation=save" />
</route>
非常感谢
您可以添加第二条路线来设置 header 变量:
<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>
然后在你的第一个路由的uri中添加参数"dynamicity":
<route>
<from uri="jms:queue:mongodb.out" />
<to uri="mongodb:myDb?database=new_test&collection=old&dynamicity=true&operation=save"/>
</route>
使用 Apache Camels toD 函数 https://camel.apache.org/message-endpoint.html will allow you to dynamically set the URI as messages are passed through. The URI allows for simple language https://camel.apache.org/simple.html 例如,我们可以在其中使用文件名生成集合。
这是一个示例路线:
from(input).routeId("SampleRoute")
.toD("mongodb3://mongoBean?database=myDB&collection=${file:onlyname.noext}&" +
"operation=insert&createCollection=true")