“seda + concurrentConsumers"有什么区别?和“直接+线程";

Apache Camel 提供两种使用线程池的解决方案:

Apache Camel provide two solutions for using thread pool:

from("seda:stageName?concurrentConsumers=5").process(...)

from("direct:stageName").thread(5).process(...)

我想知道,这两种解决方案有什么区别?是否只是两种写相同的东西?有哪些用例?

I would like to know, what is the difference between the two solutions ? Is it just two kind of write the same thing or not ? What are the use cases ?

推荐答案

SEDA 组件

seda: 组件 提供异步 SEDA 行为,以便在 BlockingQueue 上交换消息,并在与生产者不同的线程中调用消费者.

SEDA Component

The seda: component provides asynchronous SEDA behavior so that messages are exchanged on a BlockingQueue and consumers are invoked in a separate thread to the producer.

direct: 组件 在生产者发送消息交换时提供任何消费者的直接、同步调用.此端点可用于连接现有路由,或者如果与路由器位于同一 JVM 中的客户端想要访问路由.

The direct: component provides direct, synchronous invocation of any consumers when a producer sends a message exchange. This endpoint can be used to connect existing routes or if a client in the same JVM as the router wants to access the routes.

线程池是一个可以在运行时根据负载动态增加/收缩的池,并发消费者始终是固定的.

The thread pool is a pool that dynamically can increase/shrink at runtime depending on load, the concurrent consumers is always fixed.

比如,就你而言,

并发消费者 - from("seda:stageName?concurrentConsumers=5").process(...)

对于线程池 - from("direct:stageName").thread(5).process(...)

现在,如果您总是希望有 5 个线程可用,请使用 Concurrent Consumers 并且如果您希望线程根据负载可用(但不超过 5 个)然后使用线程池.

Now,if you always want to have 5 threads available then use Concurrent Consumers and if you want the threads to be available as per the load(but not more than 5) then use Thread Pool.

相关文章