接着前面前面的camel web 章程,本章程主要介绍 Direct,seda,和 routes的xml导入(import)。
建议在阅读该文时参阅笔者前两篇博客
using Camel in a Web Application
先来简单的,direct (点击进入官网)和 how do import routes from other xml file (点击进入官网)
比如我们需要大量的 xml配置route,但是同时出现在applicationContext文件中有非常庞大,臃肿,多人维护有容易冲突。那么解决该问题的一个办法就是根据业务,或者其他类别,把各个route配置到别的xml文件,在applicationContext中import,然后使用。(如果你使用的不是 xml 配置路由,选择通过代码编码route,camel 有一个org.apache.camel.spring.config.scan.route的包可以自动扫描代码中 继承RouteBuilder 自动加载路由,不过个人觉得那样路由规则都在代码中编码,如路由还需要重新编译极为不便,所以我选择 xml配置的方式)
routes import 十分简单,笔者就直接贴官网原文
For example we could have a file namedmyCoolRoutes.xml
which contains a couple of routes as shown:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd
">
<!-- this is an included XML file where we only the the routeContext -->
<!-- we can have a route -->
<
route
id="cool">
<
from
uri="direct:start"/>
<
to
uri="mock:result"/>
</
route
>
<!-- and another route,you can have as many your like -->
<
route
id="bar">
<
from
uri="direct:bar"/>
<
to
uri="mock:bar"/>
</
route
>
</
routeContext
>
</
beans
>
|
Then in your XML file which contains the CamelContext you can use Spring to import themyCoolRoute.xml
file.
And then inside<camelContext/>
you can refer to the<routeContext/>
by its id as shown below:
<!-- import the routes from another XML file -->
<
import
resource="myCoolRoutes.xml"/>
<!-- refer to a given route to be used -->
<
routeContextRef
ref="myCoolRoutes"/>
<!-- we can of course still use routes inside camelContext -->
<
route
id="inside">
<
from
uri="direct:inside"/>
<
to
uri="mock:inside"/>
</
route
>
</
camelContext
>
|