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的支持

猜你喜欢

转载自blog.csdn.net/asd5629626/article/details/81627616