Apache ServiceMix入门之三

上节介绍了一个简单的Camel的小例子,在例子中,介绍了Camel的Componet、Endpoint、URI的概念,总结起来就是:

1、Component就是Endpoint的实例工厂;

2、在编排的camel路由中,Componet是用URI来表示的;

3、每个camel路由都有一个信息的来源Endpoint,并通过路由流过/流向目的Endpoint。

上节举了一个file component的例子,下面再举几个其它Component的例子,以开视听:


<?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"
default-timeout="0">

<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<route>
<from uri="file:c:/inbox"/>
<to uri="file:c:/outbox"/>
</route>

<route>
<from uri="sftp://username@xxx.xxx.xxx.xxx//home/inbox?password=******&stepwise=false" />
<to uri="file:c:/inbox"/>
</route>
</camelContext>

</blueprint>


上例在上节的例子中的camelContext下增加了一个route,就是定义了第二个路由,这个路由用了camel-ftp component,这个component支持FTP、SFTP和FTPS三种协议,例子用了sftp协议。

由于camel-ftp component并不是ServiceMix默认安装的,所以需要在console运行安装:


karaf@root>feature:install camel-ftp


为了日后自动装有该component,可以在<servicemix_root>/etc/org.apache.karaf.features.cfg里找到

featuresBoot=karaf-framework,config,activemq-broker,activemq-spring,cxf-specs,camel,camel-activemq,camel-cxf,camel-blueprint,war,camel-ftp

在这行后面加上",camel-ftp"。

要运行以上例子,需要找个ssh(Secure Shell)服务器,将例子中的xxx.xxx.xxx.xxx替换成服务器IP,username替换成ssh的登录用户名,******替换成ssh的登录密码,/home/inbox部分则替换成ssh服务器上的某个目录。

部署好后,试试在ssh服务器里,复制一个文件到/home/inbox目录下,你就会在servicemix运行的机器上的C:\outbox下找到那个文件。

整个过程就是:文件被复制到/home/inbox后,就被新的路由定义的camel-ftp endpoint轮询到,用sftp协议下载到C:\inbox下,然后又由于第一个路由定义的“file:/c:/inbox"的endpoint轮询到,交给"file:/c:/outbox"的endpoint复制到C:\outbox目录下。

下次再举个quartz、direct、log和activemq的component的例子。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值