Back to basics: Apache Camel routes and direct component

I am a little confused about the routes of the Camel and its two end points: Straight 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") } 

In addition, I have a leisure web service that receives a few requests, does some processing, and then sends a message to this route to get a response from some third-party servers. I created an instance of Camel Context through the Spring framework as follows:

 <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 arises that in an instant I send several different messages to this route. Now, the Camel documentation says that the direct component is called on a single thread and is synchronous. So will all messages be processed simultaneously or in turn?

Also, if I change the direct component to seda, will it have any meaning?

TIA

Update [after Petterโ€™s answer] : Although Petterโ€™s answer clarified, I have new doubts about the same Direct and Seda components. Let's say my route now looks 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"); } 

Now, if I send 5 messages to a direct component from different threads, so that these messages will be processed simultaneously. As you can see from the above route, the direct component sends a message to the seda component. So now there will be only one seda component thread that will handle all 5 different messages? In the end, all messages will be processed one after another?

+4
source share
1 answer

The direct component runs on the caller thread. Simplified, it's like a regular Java method call. Multiple messages may travel along a route while multiple threads invoke a direct endpoint.

When you call the SEDA endpoint (or virtual machine), the message is placed in the queue (in memory). Another thread (along the route) selects messages from the queue one by one and processes them. You can configure the number of threads that the consumer should have by setting the concurrentConsumers parameter. By default, messages with one thread consume only one message at a time, regardless of how many threads this route creates.

It comes down to your statement

in an instant I send several different messages to this route

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

+4
source

All Articles