[Camel Basics]
Define routes:
Either using Spring xml or Java DSL.
Spring xml:
<camelContext>
<routeBuilder ref="myBuilder" /> //to load the Java DSL routes defined in MyRouteBuilder class
<routeContextRef> //to load the routes in <routeContext> defined in other xml file
<route>
<from> <process> <to>
</route>
</....>
<bean id="myBuilder" class="org.apache.camel.spring.example.test1.MyRouteBuilder"/>
Java DSL:
extends RouteBuilder, implement the abstract method configure().
@Override
public void configure() throws Exception {
Endpoint orderUpdates = endpoint("pubsub://batman-order-updates");
from("pubsub://adv-updates").process(galaxyAdvCache.input(header(Ref.INBOX)));
}
Apache Camel Test
In the separate integration module:
main/java: BGIntegration.java[RouteBuilder]
main/resources: integration-b-g.xml(Only used to include the java DSL route in BGIntegration into Camel context).
test/java: BMock.java[RouteBuilder], GMock.java[RouteBuilder], BGIntegrationTest.java
test/resources: mock-b-g.xml
Only the BGIntegration.java is used for the tests in test project, all the other 3 are for unit test.
In BGIntegration:
matcher.request("b://pubsub://b-order-updates").uniqueCorrelationId(orderId())
.reply("g:pubsub://tibrv-incoming-suggestion").size(1).correlationId(gSourceOrderID())
.timeout(10000)
.enrich(inheritInbox)
.to("g:first-matched-suggestion");
In BGIntegrationTest:
@Produce(context = "b", uri = "direct://mock-order")
private ProducerTemplate bOrderTemplate; //用于给b提供原始order
@Produce(context = "g", uri = "direct://mock-order") //用于给g提供原始msg
private ProducerTemplate gOrderTemplate;
bOrderTemplate.sendBodyAndHeader(bOrder(orderId), Ref.INBOX, ref.id()); //bOrder和gOrder都是新构建的,只需set好用于match的field即可。
gOrderTemplate.sendBodyAndHeader(gOrder, Ref.INBOX, ref.id());
In BMock:
from("direct://mock-order").to(report.request(orderLabel())
.in(content(OrderDataContract.class)), endpoint("pubsub://b-order-updates"));
//从direct://mock-order把order传给真正route里的b://pubsub://b-order-updates。
In GMock:
Samilar route from direct://mock-order to g:pubsub://tibrv-incoming-suggestion.
Another route from g:first-matched-suggestion to mock://matched-suggestion. mock component会存储msg来做future assertions.
Back to BGIntegrationTest:
@EndpointInject(context = "g", uri = "mock://matched-suggestion")
MockEndpoint matchedOrderMock;
matchedOrderMock.reset();
matchedOrderMock.expectedBodiesReceived(galaxyOrder); //Mock的测试条件
在往初始endpoint produce完msg以后,最后要测试matcher是否将两个msg match成功并存入mock://matched-suggestion.
matchedOrderMock.assertIsSatisfied();
http://camel.apache.org/testing.html
Mock component: 声明期待,确认期待是否满足。期待包括:msg count, msg payload, msg header, msgs order...
The Mock component provides a powerful declarative testing mechanism, which is similar to jMock in that it allows declarative expectations to be created on any Mock endpoint before a test begins. Then the test is run, which typically fires messages to one or more endpoints, and finally the expectations can be asserted in a test case to ensure the system worked as expected.
Remember that Mock is designed for testing. When you add Mock endpoints to a route, each Exchange sent to the endpoint will be stored (to allow for later validation) in memory until explicitly reset or the JVM is restarted.
The following annotations is supported and inject by Camel's CamelBeanPostProcessor
|
Annotation |
Description |
|---|---|
|
|
To inject an endpoint, see more details at POJO Producing. |
|
|
Camel 2.13: To inject a bean obtained from the Registry. See Bean Injection. |
|
|
Camel 2.12: To inject a value using property placeholder. |
|
|
To inject a producer to send message to an endpoint. See POJO Producing. |
|
|
To inject a consumer on a method. See POJO Consuming. |
[Camel Basics]的更多相关文章
- Assembler : The Basics In Reversing
Assembler : The Basics In Reversing Indeed: the basics!! This is all far from complete but covers ab ...
- Camel运行原理分析
Camel运行原理分析 以一个简单的例子说明一下camel的运行原理,例子本身很简单,目的就是将一个目录下的文件搬运到另一个文件夹,处理器只是将文件(限于文本文件)的内容打印到控制台,首先代码如下: ...
- The Basics of 3D Printing in 2015 - from someone with 16 WHOLE HOURS' experience
全文转载自 Scott Hanselman的博文. I bought a 3D printer on Friday, specifically a Printrbot Simple Metal fro ...
- Cadence UVM基础视频介绍(UVM SV Basics)
Cadence关于UVM的简单介绍,包括UVM的各个方面.有中文和英文两种版本. UVM SV Basics 1 – Introduction UVM SV Basics 2 – DUT Exampl ...
- C basics
C 日记目录 C basics ................ writing Numeration storage , structor space assigning pointer, a ...
- Xperf Basics: Recording a Trace(转)
http://randomascii.wordpress.com/2011/08/18/xperf-basics-recording-a-trace/ This post is obsolete ...
- Xperf Analysis Basics(转)
FQ不易,转载 http://randomascii.wordpress.com/2011/08/23/xperf-analysis-basics/ I started writing a des ...
- Radio Basics for RFID
Radio Basics for RFID The following is excerpted from Chapter 3: Radio Basics for UHF RFID from the ...
- 【IOS笔记】View Controller Basics
View Controller Basics 视图控制器基础 Apps running on iOS–based devices have a limited amount of screen s ...
随机推荐
- python中的类变量、实例变量
类变量,是各个实例共享的资源,就像中央空调,只有一个,但每个房间(实例)均可享用. 实例变量,是每个实例各自分配使用的变量,每个房间(实例)都有一台空调,供自己使用. class handle(obj ...
- hdu---(1325)Is It A Tree?(并查集)
Is It A Tree? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- 你不知道的JavaScript--值得你挑战的JavaScript面试题(45题)
1,以下表达式的运行结果是: ["1","2","3"].map(parseInt) A.["1","2&qu ...
- Android存储数据方式
可以查看Android开发文档中的:/docs/guide/topics/data/data-storage.html Android provides several options for you ...
- 20145236 冯佳 《Java程序设计》第2周学习总结
20145236 <Java程序设计>第2周学习总结 教材学习内容总结 一.Java的基本类型. 在Java中的基本类型主要可区分为整数.字节.浮点数字符与布尔. •整数: 类型 长度 范 ...
- 使用tomcat配置文件下载服务器,自定义下载列表
先上图,利用tomcat,这个下载界面没有代码,点击文件名即可下载 详细参考:http://tomcat.apache.org/tomcat-7.0-doc/default-servlet.html
- EF的Model First
一,添加ADO.NET实体数据模型(即edmx) 1,添加edmx 新建一个类库项目,项目中添加新项,选择数据/ADO.NET实体数据模型,如下图. 点击添加,实体数据模型向导窗口 ...
- HtmlHelper—DropDownList:SelectList、SelectListItem
前言 在项目中经常使用到DropDownList来显示数据库中的数据,典型的例子为为某书籍选择所属类型. 使用SelectList来实现: 实现一: Controller 代码 SelectList ...
- 转: CSS中overflow的用法
Overflow可以实现隐藏超出对象内容,同时也有显示与隐藏滚动条的作用,overflow属性有四个值:visible (默认), hidden, scroll, 和auto.同样有两个overflo ...
- Android窃取用户信息新思路
0×01 我们能得到哪些android手机上的app敏感信息手机上的app敏感信息◦通讯录,通讯记录,短信◦各种app的帐号密码,输入信息资料等◦各种影音资料,照片资料◦等等0×02 我们有哪些方法 ...