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

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>标签中重复使用。

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值