java 消息路由框架_【协议转换和消息路由】camel-spring-boot-starter 实践

Apache Camel uses URIs to work directly with any kind of Transport or messaging model such as HTTP, ActiveMQ, JMS, JBI, SCA, MINA or CXF, as well as pluggable Components and Data Format options. Apache Camel is a small library with minimal dependencies for easy embedding in any Java application. Apache Camel lets you work with the same API regardless which kind of Transport is used – so learn the API once and you can interact with all the Components provided out-of-box.

以上是引用 Apache Camel官网对它的定义。

Apache Camel 在编排模式中依托 URI 描述规则,实现了传输协议和消息格式的转换,即它具备协议转换,消息路由的能力。

白话翻译下Apache Camel功能:apache camel 能把业务数据封装在 Message 协议中,在各种不同的协议(如:HTTP,JMS,CXF等)中exchange下去。

接下来列举一个业务场景:

定时抓取百度页面内容,并存储到本地磁盘。

分析:1)百度提供的服务是http://www.baidu.com –> 这里的协议便是 http。

2)抓取百度的内容 –> 这里的内容就是数据,camel抓取到数据会把它封装进 Message,

3)抓取到的内容存储到本地磁盘 –> 本地磁盘的协议是 file, 存储下来涉及到内容的转移,即Message 的 Exchange.

简单代码实现:

package com.simonton.camel;

import org.apache.camel.CamelContext;

import org.apache.camel.builder.RouteBuilder;

import org.apache.camel.impl.DefaultCamelContext;

import org.junit.Test;

public class CamelDemoTest {

@Test

public void demo() throws Exception {

//Camel 的上下文对象 类似Sprin

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值