您的位置:首页 > 运维架构 > Apache

Apache Camel 中camel配置文件引入其他xml文件介绍--将camel配置文件拆分后并引用

2016-02-19 16:10 691 查看
1、rest

可以在新文件中用<restContext/>标签

例如:需要导入的文件myCoolRests.xml,内容为

<restContext id="myCoolRest" xmlns="http://camel.apache.org/schema/spring">
<rest uri="/say/hello">
<get>
<to uri="direct:hello"/>
</get>
</rest>
</restContext>


在camel的配置文件中用spring导入,如:<import resource="myCoolRests.xml" />

然后在<camelContext/>标签中通过<restContextRef>标签引入,标签中参数ref等于<restContext/>的id值。

例如:

<camelContext xmlns="http://camel.apache.org/schema/spring">

<restContextRef ref="myCoolRest"/>

<rest uri="/say/bye">
<get consumes="application/json">
<to uri="direct:bye"/>
</get>
<post>
<to uri="mock:update"/>
</post>
</rest>

<route>
<from uri="direct:hello"/>
<transform>
<constant>Hello World</constant>
</transform>
</route>
<route>
<from uri="direct:bye"/>
<transform>
<constant>Bye World</constant>
</transform>
</route>
</camelContext>

注意:<restContextRef>标签可以在<camelContext>标签中重复使用。

2、route

可以在新文件中使用<routeContext>标签

例如:需要导入的文件myCoolRoutes.xml,内容为

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
">

<!-- this is an included XML file where we only the the routeContext -->
<routeContext id="myCoolRoutes" xmlns="http://camel.apache.org/schema/spring">
<!-- 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>


在camel的配置文件中用spring导入,如:<import resource="myCoolRoutes.xml" />

然后在<camelContext/>标签中通过<routeContextRef>标签引入,标签中参数ref等于<restContext/>的id值。

例如:

<!-- import the routes from another XML file -->
<import resource="myCoolRoutes.xml"/>

<camelContext xmlns="http://camel.apache.org/schema/spring">

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

注意:同<restContextRef>标签一样<routeContextRef>标签可以在<camelContext>标签中重复使用。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: