ServiceMix - [Quickstart]3.通过Camel路由

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值