Using Camel
现在我知道了如何通过shell console来操作Apache ServiceMix,现在是时候来使用它了,这也是这些命令为什么被创建。让我们通过Camel route来创建我们第一个集成解决方案并把它部署到ServiceMix下。
Our simple scenario
在这个简单的方案中,我们打算把一个文件从一个目录camel\input移到另一个目录camel\output。为了保证我们可以追踪被移动的文件,每当文件被移动,都会写一条日志。
Creating the route
部署一个新路由的最简单方法之一就是在Blueprint 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:camel/input"/>
<log message="Moving ${file:name} to the output directory"/>
<to uri="file:camel/output"/>
</route>
</camelContext>
</blueprint>
Deploying the route
为了部署和启动这个路由,只要拷贝这个XML到ServiceMix的deploy目录(我把文件命名为sample1.xml)。ServiceMix会获得这个文件并将它部署。你会看到camel\input文件夹出现在ServiceMix安装目录中,任何放入这个目录中的文件都会被移进camel\output。
如果打印出日志,你将会看到文件被移动的记录。
>osgi:list | grep sample1
...
>log:display
其实当你将XML拷贝到deploy目录后,ServiceMix就已经感受到了有一个新的bundle被添加进来,于是就会将它自动部署到容器当中。你可能已经注意到我们并没有重启ServiceMix实例。
Using the shell to manage the route
从前面的步骤中我们可以获得bundle id = 156。通过id我们可以启动和停止它...
首先停止
karaf@root> osgi:stop 200
马上这个路由就不再是活动状态了,这个时候你再把文件放到input文件夹中,它不会再消失了。但是当你一启动路由,文件马上就会被移动走。
karaf@root> osgi:start 200