吴密的博客

每天进步一点点
posts - 12, comments - 1, trackbacks - 0, articles - 1

serviceMiX入门二(Routing with Camel)

Posted on 2015-04-09 17:19 xiaolang 阅读(4465) 评论(0)  编辑  收藏
本章我们通过一个简单的实例来介绍如何使用camel。
这个实例中,我们会把文件从目录
camel/input 移动到camel/output.为了方便我们跟踪哪些文件被移动,我们会记录日志。

1、创建一个xml
 ServiceMix中定义一个新的 route,最简单的方式之一就是定义一个Blueprint XML file,就像下边一样:

<?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>
                                           

2.部署
   我们只需要将第一步创建的xml复制到serviceMix下的 deploy 目录,就会被serviceMix 识别并部署。你会看到被放到目录camel/input下的文件被
移动到camel/output,如果你使用log:display命令,会看到文件移动的日志:

2015-04-09 17:10:19,515 | INFO  | le://camel/input | route1
      | ?                                   ? | 116 - org.apache.camel.camel-cor
e - 2.14.1 | Moving test.xml.bak to the output directory

3. 使用命令行管理  route
使用osgi:list,你会看到刚才我们部署的bundle
[ 221] [Active     ] [Created     ] [       ] [   80] test.xml (0.0.0)
你会看到我们刚才部署的bundle ID是221,我们可以通过这个bundle ID来启动或者关闭bundle

karaf@root> osgi:stop 221
karaf@root> osgi:start 221

只有注册用户登录后才能发表评论。


网站导航: