ApacheCamel基础构件

1.CamelContext

The CamelContext represents a single Camel routing rulebase. You use the CamelContext in a similar way to the Spring ApplicationContext.
See Lifecycle to understand the overall lifecycle of the CamelContext.
CamelContext表示单个Camel路由规则库,其使用方式类似于Spring ApplicationContext。
请参阅生命周期(原链接)以了解CamelContext的整个生命周期(本地连接)。

2 RouteBuilder

The RouteBuilder is a base class which is derived from to create routing rules using the DSL. Instances of RouteBuilder are then added to the CamelContext.
RouteBuilder是一个基类,派生自使用DSL创建路由规则。 然后将RouteBuilder的实例添加到CamelContext中。

3 Routes

Camel supports the definition of routing rules using a Java DSL (domain specific language) which avoids the need for cumbersome XML using a RouteBuilder.
Camel支持使用Java DSL(特定于域的语言)定义路由规则,这避免了使用RouteBuilder对繁琐的XML的需求。
For example a simple route can be created as follows.

RouteBuilder builder = new RouteBuilder() {
    public void configure() {
        errorHandler(deadLetterChannel("mock:error"));
        from("direct:a").to("direct:b");
    }
};

As you can see from the above Camel uses URIs to wire endpoints together.
Camel使用URI将端点连接在一起

4 URI

(本地API)String formatting——Available as of Camel 2.0 详细参见URIs——API描述
If you have endpoint URIs that accept options and you want to be able to substitute the value, e.g. build the URI by concat the strings together, then you can use the java.lang.String.format method. But in Camel 2.0 we have added two convenient methods in the Java DSL so you can do fromF and toF that uses String formatting to build the URI.
如果您的端点URI接受选项,并且您希望能够替换该值,例如通过将字符串连接在一起来构建URI,然后可以使用java.lang.String.format方法。但是在Camel 2.0中我们在Java DSL中添加了两个方便的方法,因此您可以使用String格式来构建URI。
from(“direct:start”).toF(“file://%s?fileName=%s”, path, name);
fromF(“file://%s?include=%s”, path, pattern).toF(“mock:%s”, result);

5 Filters

You can combine simple routes with filters which can be arbitrary Predicate implementations.
您可以将简单路由与过滤器结合使用,过滤器可以是任意谓词实现。

RouteBuilder builder = new RouteBuilder() {
    public void configure() {
        errorHandler(deadLetterChannel("mock:error"));
        from("direct:a")
            .filter(header("foo").isEqualTo("bar"))
                .to("direct:b");
    }
};

6 Choices

With a choice you provide a list of predicates and outcomes along with an optional default otherwise clause which is invoked if none of the conditions are met.
通过选择,您可以提供谓词和结果列表以及可选的default otherwise子句,如果不满足任何条件,则调用该子句。

RouteBuilder builder = new RouteBuilder() {
    public void configure() {
        errorHandler(deadLetterChannel("mock:error"));
        from("direct:a")
            .choice()
                .when(header("foo").isEqualTo("bar"))
                    .to("direct:b")
                .when(header("foo").isEqualTo("cheese"))
                    .to("direct:c")
                .otherwise()
                    .to("direct:d");
    }
};

7 Processor

Using a custom processor
Here is an example of using a custom Processor
以下是使用自定义处理器的示例

myProcessor = new Processor() {
    public void process(Exchange exchange) {
        log.debug("Called with exchange: " + exchange);
    }
};
RouteBuilder builder = new RouteBuilder() {
    public void configure() {
        errorHandler(deadLetterChannel("mock:error"));
        from("direct:a")
            .process(myProcessor);
    }
};

You can mix and match custom processors with filters and choices.
您可以将自定义处理器与过滤器和选项自由搭配。

RouteBuilder builder = new RouteBuilder() {
    public void configure() {
        errorHandler(deadLetterChannel("mock:error"));
        from("direct:a")
            .filter(header("foo").isEqualTo("bar"))
                .process(myProcessor);
    }
};

8 Endpoints

Camel supports the Message Endpoint pattern using the Endpoint interface. Endpoints are usually created by a Component and Endpoints are usually referred to in the DSL via their URIs.
Camel使用Endpoint接口支持Message Endpoint模式。 端点通常由组件创建,端点通常通过其URI在DSL中引用。
From an Endpoint you can use the following methods

createProducer() will create a Producer for sending message exchanges to the endpoint
createConsumer() implements the Event Driven Consumer pattern for consuming message exchanges from the endpoint via a Processor when creating a Consumer
createPollingConsumer() implements the Polling Consumer pattern for consuming message exchanges from the endpoint via a PollingConsumer
createProducer()将创建一个Producer,用于向端点发送消息交换
createConsumer()实现了事件驱动的使用者模式,用于在创建使用者时通过处理器消耗来自端点的消息交换
createPollingConsumer()实现Polling Consumer模式,用于通过PollingConsumer消费来自端点的消息交换

9 Exchange (Message Exchange)

To support various message exchange patterns like one way Event Message and Request Reply messages Camel uses an Exchange interface which has a pattern property which can be set to InOnly for an Event Messagewhich has a single inbound Message, or InOut for a Request Reply where there is an inbound and outbound Message.
为了支持各种消息交换模式,例如单向事件消息和请求应答消息,Camel使用具有模式属性的Exchange接口,该属性可以设置为InOnly,用于具有单个入站消息的事件消息,或者InOut用于请求应答,其中 是入站和出站消息。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值