Apache Camel 点滴

    Apache Camel是Apache基金会下的一个开源项目,它是一个基于规则路由和处理的引擎,提供企业集成模式的Java对象的实现,通过应用程序接口或称为陈述式的Java领域特定语言(DSL)来配置路由和处理的规则。其核心的思想就是从一个from源头得到数据,通过processor处理,再发到一个to目的的.
    这个from和to可以是我们在项目集成中经常碰到的类型:一个FTP文件夹中的文件,一个MQ的queue,一个HTTP request/response,一个webservice等等.
    Camel可以很容易集成到standalone的应用,在容器中运行的Web应用,以及和Spring一起集成.

<route>
  <from uri="jms:queue:order"/>
  <pipeline>
    <bean ref="validateOrder"/>
    <bean ref="registerOrder"/>
    <bean ref="sendConfirmEmail"/>
  </pipeline>
</route>

Pipeline is default
In the route above we specify pipeline but it can be omitted as its default, so you can write the route as:

<route>
  <from uri="jms:queue:order"/>
  <bean ref="validateOrder"/>
  <bean ref="registerOrder"/>
  <bean ref="sendConfirmEmail"/>
</route>

An example where the pipeline needs to be used, is when using a multicast and "one" of the endpoints to send to (as a logical group) is a pipeline of other endpoints. For example.

<route>
  <from uri="jms:queue:order"/>
  <multicast>
    <to uri="log:org.company.log.Category"/>
    <pipeline>
      <bean ref="validateOrder"/>
      <bean ref="registerOrder"/>
      <bean ref="sendConfirmEmail"/>
    </pipeline>
  </multicast>
</route>

The above sends the order (from jms:queue:order) to two locations at the same time,our log component, and to the "pipeline" of beans which goes one to the other.

<route>
  <from uri="jms:queue:order"/>
  <multicast>
    <to uri="log:org.company.log.Category"/>
    <bean ref="validateOrder"/>
    <bean ref="registerOrder"/>
    <bean ref="sendConfirmEmail"/>
  </multicast>
</route>

you would see that multicast would not "flow" the message from one bean to the next, but rather send the order to all 4 endpoints (1x log, 3x bean) in parallel, which is not (for this example) what we want. We need the message to flow to the validateOrder, then to the registerOrder, then the sendConfirmEmail so adding the pipeline, provides this facility.

<route>
  <from uri="jms:queue:order"/>
  <to uri="bean:validateOrder"/>
  <to uri="mina:tcp://mainframeip:4444?textline=true"/>
  <to uri="bean:sendConfirmEmail"/>
</route>

What we now have in the route is a to type that can be used as a direct replacement for the bean type.

<route>
  <from uri="jms:queue:order"/>
  <bean ref="validateOrder"/>
  <to uri="mina:tcp://mainframeip:4444?textline=true"/>
  <bean ref="sendConfirmEmail"/>
</route>

待续......



猜你喜欢

转载自maosheng.iteye.com/blog/2001300