摘要:有时候我们常把一些配置信息写在xxx.properties文件中,为的是改动的时候轻松一点,那么笔者在用camel时也尝试了一下
参考地址:http://camel.apache.org/using-propertyplaceholder.html
借助前面的servicemix搭的环境,我们在etc文件夹下放入后缀名为cfg的文件,如图
好,接下来看看camel里面怎么使用
可以在deploy文件夹下,新建xml文件,内容如下
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" default-timeout="0">
<camelContext xmlns="http://camel.apache.org/schema/blueprint"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<propertyPlaceholder location="file:${karaf.home}/etc/yfaf.camel.cfg" />
<route>
<from uri="mqtt:kotlin?host=tcp://localhost:1883&username={{mq_user}}&password={{mq_pwd}}&subscribeTopicNames=order/data"/>
<bean ref="com.yf.af.mqPms.authorization.AuthorizationBroker" method="orderMessage" />
<to uri="activemq:topic:test.timer?username={{mq_user}}&password={{mq_pwd}}" />
</route>
</camelContext>
</blueprint>
location:文件的存放路径
笔者的用户名和密码就是从文件中读取出来的