---
title: "Apache ServiceMix入门之三"
author: "killko"
date: "2013-03-14T00:41:26Z"
tags: []
categories: ["开源软件"]
slug: "apache-servicemix"
draft: false
lastmod: "2013-03-14T00:41:26Z"
id: 1829026
url: "https://killko.iteye.com/blog/1829026"
---

上节介绍了一个简单的Camel的小例子，在例子中，介绍了Camel的Componet、Endpoint、URI的概念，总结起来就是：

1、Component就是Endpoint的实例工厂；

2、在编排的camel路由中，Componet是用URI来表示的；

3、每个camel路由都有一个信息的来源Endpoint，并通过路由流过/流向目的Endpoint。

上节举了一个file component的例子，下面再举几个其它Component的例子，以开视听：


```java

<?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=******&amp;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运行安装：


```java

karaf@root>feature:install camel-ftp

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

```java

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的例子。