骆驼分裂器并行处理 [英] camel splitter parallel processing
问题描述
我们有一个服务调用,它返回一个 id 列表,我们用它来调用另一个一次只需要一个 id 的服务,所以我们使用骆驼拆分器,并行处理变成了 true
.现在我们对服务的调用是通过 seda 进行的,因此我们可以对其设置超时.这将导致并行处理不再并行的问题,因为默认情况下 seda 只有 1 个并发消费者在处理它.
We have a service call which returns a list of ids with which we call another service which takes only one id at a time, so we are using the camel splitter with parallel processing turned to true
. Now the call we make for the service is through a seda so we can put a timeout on it. This will cause the problem that parallel processing will not be parallel anymore since seda by default has only 1 concurrent consumers working on it.
选项:
- 在 seda 上放一个 ?concurrentConsumers=x
- 使用 direct 而不是 seda.(没有超时选项?)
- 还有其他选择吗?
1 和 2 哪个更可取?
Of 1 and 2 which one would be preferable?
推荐答案
首先在拆分器上将流设置为 true
对大消息很有用.这意味着它将分块分割输入消息.这减少了内存开销.因此,这将提高处理大消息的性能.
Firstly setting streaming to true
on the splitter is useful for big messages. Which means it will split the input message in chunks. This reduces the memory overhead. So this will improve performance with large messages.
要真正并行处理 seda
队列,您需要按如下方式设置 seda
路由.
For a seda
queue to truly process in parallel you need to set the seda
route as follows.
<from uri="seda:report?multipleConsumers=true&concurrentConsumers=16"/>
这将允许路由最多为并发消费者使用 16 个线程.seda
组件不实现任何类型的持久化或恢复,如果 VM 在消息尚未处理时终止,它们将丢失.如果您需要持久性、可靠性或分布式 seda
,请尝试使用 jms
或 activemq
This will allow the route to use up to 16 threads for concurrent consumers. The seda
component does not implement any kind of persistence or recovery, if the VM terminates while messages are yet to be processed they will be lost. If you need persistence, reliability or distributed seda
, try using either jms
or activemq
direct
组件是同步的,根据文档支持多个消费者已被弃用.从 Camel 2.1 开始:直接端点不支持多个消费者.
The direct
component is synchronous and according to the documentation support for multiple consumers are deprecated. As of Camel 2.1: Direct endpoint does not support multiple consumers.
另一个选项是 vm
组件.vm
组件与 seda
组件的不同之处在于 vm
支持跨 CamelContext
实例的通信 - 所以你可以使用它跨 Web 应用程序通信的机制 本质上,vm
组件是 seda
组件的扩展.
The other option is the vm
component. The vm
component differs from the seda
component in that vm
supports communication across CamelContext
instances - so you can use this mechanism to communicate across web applications Essentially the vm
component is an extension to the seda
component.
因此,如果您需要并行处理,direct
组件是没有用的.如果您需要跨 CamelContent
实例发送消息,则使用 vm
如果不需要,则使用 seda
如上所述.
So if if you need parallel processing the direct
component is not useful. If you need to send message across CamelContent
instances then use vm
if not then use seda
as described above.
这篇关于骆驼分裂器并行处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!