幂等

apache camel Idempotent

Apache camel

基于规则路由和处理的引擎,提供企业集成的java对象的实现,通过应用程序接口或DSL(domain-specific languages)来配置路由和处理规则,从一个from源头得到数据,通过process处理,再发到一个to目的地;

  • CamelContext
  • RouteBuilder
  • configure(){from().process(Processor).to();}
  • from to 称为endPoint控制端点
  • Tools for Apache Camel”可以图形化Apache Camel的规则编排过程。
  • Enterprise Integration Patterns:企业集成模式
  • endpoint都是通过URI格式进行描述的
Exchange和Message

Exchange,帮助开发人员在控制端点到处理器、处理器到处理器的路由过程中完成消息的统一描述,包含:ExchangeId, fromEndpoint, properties, pattern, Exception,
Message:是Exchange中的属性,inMessage和outMessage,每一个message对象包含四个属性:MessageID、Header、Body和Attachment。

Processor处理器最主要的工作是进行业务数据格式的转化和中间数据的临时存储,Endpoint一般用来处理业务逻辑、建立数据库连接、建立RPC等;

Camel路由规则

Service的start和stop方法控制服务的生命周期;
CamelContext横跨了Camel服务的整个生命周期,并且为Camel服务的工作环境提供支撑。

参考 : http://blog.csdn.net/yinwenjie/article/details/51818352

幂等支持

camel使用IdempotentConsumer类 。根据某个消息ID,到RedisIdempotentRepository 仓储中寻找这个ID,如果存在表示被消费过,否则加入。Redis这里作为消息的存储。
http://www.jdon.com/repository/camelredis.html
配置:

<bean id="idempotentRepository" class="org.apache.camel.component.redis.processor.idempotent.RedisIdempotentRepository">
<constructor-arg value="test-repo"/>
</bean>

<route>
<from uri="direct:start"/>
<idempotentConsumer messageIdRepositoryRef="idempotentRepository">
<simple>${in.body.id}</simple>
<to uri="mock:result"/>
</idempotentConsumer>
</route>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值