回到基础:Apache的骆驼路由和直组件 [英] Back to Basics : Apache Camel Routes and Direct Component

查看:165
本文介绍了回到基础:Apache的骆驼路由和直组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对骆驼的路线和它的两个端点有点糊涂了:直接和塞达。好吧,让我们说,我有一个像这样的路线:

I am bit confused about Camel routes and its two endpoints : Direct and Seda. Well let's say i have a route like this :

public void configure()
{
 from("direct:services")
  .process(//Some processing here)
  .to("http://ThirdPartyServers")
}

在这上面我有过消息接收几个请求,做了一些处理,然后手这条路线,以获得一些第三方的服务器响应休息Web服务。我已经经历了这样的Spring框架实例化骆驼上下文:

On top of this I have a rest web service which receives several requests, does some processing and then hands over the message to this route to get response from some third party servers. I have instantiated Camel Context through Spring framework like this :

<camelContext id="appCamelContext" xmlns="http://camel.apache.org/schema/spring"
        trace="true" streamCache="true">
        <propertyPlaceholder id="properties"
            location="classpath:camel.properties" />
        <camel:routeBuilder ref="oneRouteBuilder" />
        <camel:routeBuilder ref="photosRouteBuilder" />
</camelContext>

现在的问题是,在一个瞬间我发送多个不同的讯息给这条路线。现在,骆驼文档中说,直接组件是在单独的线程调用并是同步的。因此,将所有的消息由一个处理并行或者一个处理会怎样?

Now the question is that in a instant I send multiple different messages to this route. Now Camel documentation says that direct component is invoked in single thread and is synchronous. So will all the messages be processed concurrently or one by one processing will happen ?

另外,如果我的直接组成部分更改为SEDA,将它有什么区别?

Also if i change the direct component to seda, will it make any difference ?

TIA

更新[后皮特的回答]
 尽管皮特的回答澄清,但我有一个关于同一个直接和塞达组件新的疑问。比方说现在我的路线是这样的:

Update [after Petter's answer]: Although Petter's answer has clarified but i have new doubt regarding the same Direct and Seda components. Lets say my route is now like this :

public void configure(){
from("direct:services")
 .choice()
 .when("some predicate here-Predicate1")
 .to("seda:predicate1")
 .otherwise()
 .to("seda:fallback")
 .end();

 from("seda:predicate1")
 .process("some processing")
 .to("http://ThirdPartyServers");

 from("seda:fallback")
 .process("some processing")
 .to("jms:fallbackqueue");
}

现在,如果我发送5条信息直接从成分不同的线程,所以这些消息将被同时处理。正如你可以在上面看到的路线,直接组件将消息发送到SEDA组件。所以现在会有镇静成分只有一个线程将处理所有不同的5条消息?含义到底的所有消息将由一个被处理的?

Now if i send 5 messages to direct component from different threads, so these messages would be processed concurrently. As you can see in the above route, direct component sends the message to seda component. So now will there be only one thread of seda component which will process all the different 5 messages? Meaning in the end all the messages will be processed one by one ?

推荐答案

直流分量在调用者的线程中运行。简化的,这是作为一个普通的Java方法调用。因为多个线程调用的直接端点的多个消息可以通过路由只要运行。

The direct component runs in the thread of the caller. Simplified, it's as a regular java method invocation. Multiple messages can run through the route as long as multiple threads are calling the direct endpoint.

在调用SEDA(或VM)端点,消息放在一个队列(在内存中)。另一个线程(在路由)由一个主从队列中的一个消息,并进行处理。您可以配置多少线程的SEDA消费者应通过设置concurrentConsumers选项都有。缺省情况下,一个线程使用消息可以确保一次仅一个消息被处理,无论多少线程正在生产到该路由。

When invoking the SEDA (or VM) endpoint, you message is put on a queue (in memory). Another thread (in the route) picks messages from the queue one by one and processes them. You can configure how many threads the seda consumer should have by setting the concurrentConsumers option. By default, the one thread consuming messages makes sure only one message at a time is processed no matter how many threads are producing to this route.

它归结为你的发言

在一个瞬间我发送多个不同的讯息,以这条路线

in a instant I send multiple different messages to this route

如果这意味着不同的线程,或者仅仅从一个单一的线程的序列中,

If this means different threads, or just from one single thread in a sequence,

这篇关于回到基础:Apache的骆驼路由和直组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆