Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between "seda + concurrentConsumers" and "direct + threads"

Apache Camel provide two solutions for using thread pool:

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

and

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 ?

like image 262
Pith Avatar asked Oct 22 '13 07:10

Pith


1 Answers

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 Component

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.

Difference between thread pools and concurrent consumers

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

Like, in your case,

For Concurrent consumers - from("seda:stageName?concurrentConsumers=5").process(...)

For Thread Pool - from("direct:stageName").thread(5).process(...)

WHAT TO USE

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.

like image 106
Prateek Avatar answered Nov 06 '22 03:11

Prateek