apache camel 基本组件介绍

1、bean 对象

1.1 添加bean 构造camelContext直接放入

//新建 bean context

JndiContext jndiContext = new JndiContext();

jndiContext.bind("bind",new TestBean());





// 这是camel上下文对象,整个路由的驱动全靠它了。

DefaultCamelContext camelContext = new DefaultCamelContext(jndiContext);

1.2 添加bean 启动之后动态放入

// 启动route

camelContext.start();

camelContext.setJndiContext(jndiContext);

1.3 使用节点(to)

to("bean:bind?method=test2");

 

不是用method参数 “bean:bind”

1、实现 org.apache.camel.Processor; 执行 process方法

2、不实现接口,先找唯一方法,多个的话找唯一含有 Exchange 参数的方法,其他情况报错会报错

 

1.4通过方法调用

调用beanName 的methodName方法

from("direct:hello").beanRef("bind","test2");

调用bean对象的test2方法

from("direct:hello").bean(TestBean.class,"test2");

不输入方法名称和上面流程类似

 

2、dirct 用于相互通云

例如

to("direct:hello?block=true&timeout=5000");

将消息发到 direct hello中

from("direct:hello").beanRef("bind","test2");

通过from进行监听获取

 

参数 block 是否阻塞

timeout 超时时间

 

3、log

“log:out”

com.log.test 自定义包,level指定输出级别

to("log:com.log.test?level=WARN");

 

4、http (from并不是主动监听,而是发起请求返回数据,如果要监听可以使用 jetty,或者servlet等)

引入maven依赖 

        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-http4</artifactId>
            <version>2.18.0</version>
        </dependency>

使用 http4 替代 http   url 代替uri即可

例如:to("http4://www.baidu.com") 就是对 百度发起一次请求

其他组件

 

官网查看 查看各种类型uri的支持

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值