camel

最近项目里会用到camel,近期会写一篇文章来总结camel中的一些常用的‘知识点’。

总结一下。

1 from

from("file://C:\\Users\\xxx\\documents\\camel?fileName=b.txt").routeId("routeId")
.log(LoggingLevel.DEBUG,"lalala ${id} ${body}")
.inOnly("direct:BBB")
.log(LoggingLevel.DEBUG,"--------"+"${body}"+"processing ${id}");
一直会监听这个路径下的b.txt文件。

2 camel 设置打印log

3 bean processor

类似拦截器,对exchange进行一些处理

如果在bean,processor中有调用exchange.get()方法,读取exchange中的流,之后需要重新set进去才行,否则,之后exchange中的内容为null。

做了一个简单的demo,就了解到这些基本的方法作用,其他的再慢慢探索,还是很枯燥的。

4 onException

捕捉camel route中产生的异常

http://people.apache.org/~dkulp/camel/exception-clause.html 

网页中有比较详细的例子可参考。

5 streamCaching

stream缓存,因为stream类型的数据只能读一次。from Camel 2.0 缓存默认不可用。

6 marsh unmarsh

marsh bean转xml

unmarsh xml转bean

 7 setExchangePattern(待完成)

可参考 https://examples.javacodegeeks.com/enterprise-java/apache-camel/apache-camel-exchange-example/

http://www.catchmycity.com/tutorial/apache-camel-difference-between-exchangepattern-inout-and-exchangepattern-inonly-in-apache-camel_101

InOnly 

InOut request-reply

Not all camel endpoints support INOUT. The JMS endpoint supports it but the file endpoint does not.

Unfortunately this is indeed not well documented.

 

8 setProperty

setProperty在route中传递, setHeader在exchange中传递。

Similar to message headers, but they last for the duration of the entire exchange.

可参考 http://camel.465427.n5.nabble.com/Camel-Java-DSL-setProperty-behaviour-td5718226.html

9 choice

.choice()
                .when().simple("${body} == 'test inout'").setBody(simple("one")).endChoice()
                .when().simple("${body} == 'aaa'").setBody(simple("two")).endChoice()
                .end()

可参考  https://cleverbuilder.com/articles/camel-choice-when/

10 doTry() doCatch(xx.class)

处理异常,类似java try catch

11 multicast() split()

multicast

The Multicast allows to route the same message to a number of endpoints and process them in a different way. The main difference between the Multicast and Splitter is that Splitter will split the message into several pieces but the Multicast will not modify the request message.

可参考  http://people.apache.org/~dkulp/camel/multicast.html

split

The Splitter from the EIP Pattern allows you split a message into a number of pieces and process them individually

可参考 http://camel.apache.org/splitter.html

12  SEDA indirect vm

可参考 http://camel.apache.org/how-do-the-direct-event-seda-and-vm-endpoints-compare.html

https://cleverbuilder.com/articles/camel-direct-vm-seda/

  • ComponentTypeWithin same CamelContextWithin same JVM
    DirectSynchronousYesNo
    Direct-VMSynchronousYesYes
    SEDAAsynchronousYesNo
    VMAsynchronousYesYes

 13 recipientList

使用recipientList可以创建动态的接收者。

example

from("direct:a").recipientList(header("myHeader").tokenize(","));

myHeader = {'direct:a','direct:b'}

14 camel 打印exchange信息到控制台 

解决 DEBUG ProducerCache                  - >>>> Endpoint[direct:start] Exchange[Message: 01234567890123456789... [Body clipped after 20 chars, total length is 1000]]
参考 http://camel.apache.org/how-do-i-set-the-max-chars-when-debug-logging-messages-in-camel.html 设置camelContext信息输出长度。
endpoint.getxxx 参考下图输出body信息。

 15  camel - mybatis

参考 https://camel.apache.org/mybatis-example.html

16 wire tap

参考 https://www.javarticles.com/2015/05/apache-camel-wire-tap-examples.html

https://stackoverflow.com/questions/41482674/what-is-the-difference-bewteen-wiretap-and-multicast-in-apache-camel

 

 

17 routePolicy

在 RoutePolicySupport 抽象类中存在着这些方法:

实现routePolicy 可在route开始,结束等时候执行。在我理解,routepolicy是一个拦截器,在route执行的各个时间被trigger。

 18 Apache Camel的核心概念

参考 http://holbrook.github.io/2014/02/10/apache_camel.html

 

 

 

 





 

转载于:https://www.cnblogs.com/Jenny22/p/9927668.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值