Camel

Camel消息模型主要由两个类

Message 系统间进行数据传送的实体。
Camel_第1张图片
image.png

header是k-v结构,包含sender id,字符集,授权信息等。key是String, value是Object。
body是Object,因此可包含任何内容。同时也意味着,设计者必须保证接收方能正确解释这些内容。Camel提供了很多converter,大部分情况下可以正确将发送方的内容自动转换为接收方的格式。
message中还有fault flag,用来表示失败的情况反馈。
在路由中,message是包含在Exchange中的。

Exchange 代表一次“对话”(conversation)即数据交换,包含了in 的message和out的message。它是路由中消息的容器。

message exchange patterns (MEPs):标识出是单向消息(one-way或event message)还是request-response消息。它是由pattern属性设置的:InOnly,比如JMS消息;InOut,比如http消息。


Camel_第2张图片
image.png

in message肯定会有。如果pattern是InOnly,就只有in message;如果是InOut,才会有out message。in message是request,out message代表了reply to the request。

Camel总体结构

Camel_第3张图片
image.png

注意endpoint和component的关系,endpoint是对外的接口,component是endpoint的工厂。

endpoint url的结构

Camel_第4张图片
image.png

scheme指明哪个commponent处理这个endpoint。例如FileComponent作为工厂(根据context path和options)创建FileEndpoint。

http相关的endpoint

Camel:http 是用来作为http客户端,访问某个http服务器。它不能作为Route的入口。要在route中第一个访问,可以将from配置一个quartz2组件定时执行:

from("quartz2://myGroup/myTimerName?trigger.repeatInterval=2&trigger.repeatCount=0")
        .to("http://172.22.224.165:8000/testApi")
        .process(new HttpProcessor())
        .to("log:helloworld?showExchangeId=true&showBody=true");

Camel:jetty可以作为http服务器,接受其他客户端的http请求:

     from("jetty:http://127.0.0.1:8000/testApi").
     process(new HttpProcessor()).
     to("log:onlyatest?showExchangeId=true&level=DEBUG");  
``
这样camel变成了一个http服务器,http客户端向http://127.0.0.1:8000/testApi发送http请求,就可以触发这个route。

你可能感兴趣的:(Camel)