note of camel in action--chapter 2 Routing with Camel

1   what is routing

 

      Input and output queues are unaware of the conditions in between them. The condi-tional logic is decoupled from the message consumer and producer.

2    java dsl

   

    A typical JAVA DSL is written like this: from..process..filter...bean...log...to...

    The from method tells Camel to consume messages from an FTP endpoint( fror example), and the to method instructs Camel to send messages to a JMS endpoint(example).

3   using camel and spring

    step 1   In maven ,camel-spring artifactId firstly needs to be imported.

    step 2   application.xml  needs to add the following piece of code:

                <camelContext xmlns="http://camel.apache.org/schema/spring">
      <packageScan>
        <package>camelinaction.routes</package>

                            <excludes>**.*Test*</excludes>
        <includes>**.*</includes>
      </packageScan>
     </camelContext>

    step 3   self-designed route extends SpringRouteBuilder

type of route

4  Using a content-based router

   from("jms:incomingOrders")
    .choice()
    .when(header("CamelFileName").endsWith(".xml"))
    .to("jms:xmlOrders")
    .when(header("CamelFileName").regex("^.*(csv|csl)$"))
    .to("jms:csvOrders")
    .otherwise()
    .to("jms:badOrders")
    .end()
    .to("jms:continuedProcessing");

5  Using message filters

  

 

        the source directory has two xml files and filter method filter them according to the xpath rules

        xpath syntax

6  Using multicasting
            

    under this route type,  When the list of destinations is known ahead of time and is static, you can add an element to the route that will consume messages from a source endpoint and then send the message out to a list of definite destinations.  parallelProcessing is used here for setting up the multicast to distribute messages to the destinations in parallel.

    By default, the multicast will continue sending messages to destinations even if one fails. In your application, though, you may consider the whole process as failed if one destination fails. What do you do in this case?  answer : use the stopOnException() right after the multicast()

 

7  Using recipient lists

    

      the destinations are determined by header("recipients") which must be iterable and processed in the processor, which means the destinations are dynamic.

   from what i 've experienced in working simple() can also be used instead of header().

 

8 Using the wireTap method( for debug in production environment)

      By using the wireTap method in the Java DSL , you can send a copy of the exchange to a secondary destination without affecting the behavior of the rest of the route:

   

 

   

  

转载于:https://www.cnblogs.com/liuheng0213/p/10527584.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值