您的位置:首页 > 产品设计 > UI/UE

学习ServiceMix笔记(五) 学习ServiceMix的blueprint配置

2014-04-18 00:00 302 查看
摘要: 对比两个blueprint配置文件看blueprint的基本使用方法

先来看两个blueprint配置文件,一个是上次实现启动停止服务的transfile.xml,一个是系统的examples\camel\camel-blueprint下的配置文件。内容如下:

transfile.xml

<?xml version="1.0" encoding="UTF-8"?>
<blueprint
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">

<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<route>
<from uri="file:activemq/input"/>
<to uri="file:activemq/output"/>

<setBody>
<simple>
FileMovedEvent(file: ${file:name}, timestamp: ${date:now:hh:MM:ss.SSS})
</simple>
</setBody>
<to uri="activemq://events" />
</route>
</camelContext>

<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
<property name="brokerURL" value="tcp://localhost:61616"/>
<property name="userName" value="smx"/>
<property name="password" value="smx"/>
</bean>

</blueprint>


examples\camel\camel-blueprint

<?xml version="1.0" encoding="UTF-8"?>
<blueprint
xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd"> 
<cm:property-placeholder persistent-id="org.apache.servicemix.examples">
<cm:default-properties>
<cm:property name="prefix" value="Blueprint-Example"/>
</cm:default-properties>
</cm:property-placeholder>

<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<route>
<from uri="timer://myTimer?fixedRate=true&period=2000" />
<bean ref="myTransform" method="transform"/>
<to uri="log:ExampleRouterBlueprint" />
</route>
</camelContext>

<bean id="myTransform" class="org.apache.servicemix.examples.camel.MyTransform">
<property name="prefix" value="${prefix}" />
</bean>

</blueprint>


  前一个文件分为 camelContext,bean两个节点,后一个分为 cm:property-placeholder,camelContext,bean三个节点,cm:property-placeholder是用来预定义一些camel的属性后面进行调用,我们只研究camelContext,bean两个节点。

  对于camelContext,这是整个服务的关键所在,route指名了当前服务处理业务流程的出入口:我们先来看transfile.xml配置文件。

数据入口

对于transfile.xml文件来说,from 指名数据来源,操作对象file,对应文件操作功能(有关file的一个操作和属性设置具体请看http://camel.apache.org/file2.html)。

<from uri="file:activemq/input"/>


监测activemq/input目录下的文件变化,如果文件存在,那么读取文件,通过后而的数据处理过程进程处理。

2. 数据处理

在此配置文件中无数据处理过程,只是简单的文件读取,直接转发给数据出口的文件写入请求。

3. 数据出口

<to uri="file:activemq/output"/>


把读取到的文件,写入的指定的目录下。

<setBody>
<simple>
FileMovedEvent(file: ${file:name}, timestamp: ${date:now:hh:MM:ss.SSS})
</simple>
</setBody>
<to uri="activemq://events" />


这里对应另外一个数据出口,把接收文件的一些信息发送给activemq,setBody是一个简单的数据处理过程,也可以是自定义的数据处理过程。

接下来我们再看一下examples\camel\camel-blueprint中的xml文件里的内容:

数据入口

对于camel-blueprint的配置文件来说,from 指名数据来源,操作对象timer,定义了一个timer对象myTimer,定时执行指定的数据处理过程,timer操作是调用camel的Quartz服务,进行一些与时间有关的操作,具体属性请看http://camel.apache.org/timer.html里面的介绍。。

<from uri="timer://myTimer?fixedRate=true&period=2000"/>


2. 数据处理

<bean ref="myTransform" method="transform"/>


数据处理过程是一个JAVA类,调用类里的transform方法进行数据处理。

3. 数据出口

<to uri="log:ExampleRouterBlueprint" />


输出日志信息。

除了上面的file,timer,activem,log四个外,还有其它的操作吗?协议文件传送FTP,FTPS,WEB服务HTTP,websocket,邮件POP3,SMTP,竟然可以直接和MyBatis ,JDBC连接进行操作,这些我们以后再一点一点学习吧。有关其它可以调用的输入输出组件请查看介绍http://camel.apache.org/components.html。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息