You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by anand_tech <an...@gmail.com> on 2013/05/02 11:39:37 UTC
Back to Basics : Apache Camel Routes and Direct Component
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")
}
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 ?
Also if i change the direct component to seda, will it make any difference ?
Also 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");
}
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 ?
TIA
--
View this message in context: http://camel.465427.n5.nabble.com/Back-to-Basics-Apache-Camel-Routes-and-Direct-Component-tp5731899.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Back to Basics : Apache Camel Routes and Direct Component
Posted by Christian Posta <ch...@gmail.com>.
Yes, it depends on how many concurrentConsumers you have. Default is 1.
And yes, if you use direct component with 5 separate application threads
calling into the route, you won't need context switching and blocking
queues.
Take a good look at SEDA (
http://en.wikipedia.org/wiki/Staged_event-driven_architecture, as well as
the camel-seda component referenced by Claus above...) to see when it
becomes advantageous.
On Wed, May 29, 2013 at 8:05 AM, anand_tech <an...@gmail.com> wrote:
> Thanks for quick response
>
> so at the end it boils to how much concurrentConsumers i have configured on
> seda endpoint. And i mentioned "one" because i haven't configured any
> concurrentConsumers in my code as of now, so there would be only one seda
> thread processing all the exchanges rite ?
>
> And one more question : if i change this seda to direct component then all
> 5
> different threads will now be processed concurrently since direct is like
> method invocation : no blocking queue and async stuff. Please correct me.
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Back-to-Basics-Apache-Camel-Routes-and-Direct-Component-tp5731899p5733419.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta
Re: Back to Basics : Apache Camel Routes and Direct Component
Posted by anand_tech <an...@gmail.com>.
Thanks for quick response
so at the end it boils to how much concurrentConsumers i have configured on
seda endpoint. And i mentioned "one" because i haven't configured any
concurrentConsumers in my code as of now, so there would be only one seda
thread processing all the exchanges rite ?
And one more question : if i change this seda to direct component then all 5
different threads will now be processed concurrently since direct is like
method invocation : no blocking queue and async stuff. Please correct me.
--
View this message in context: http://camel.465427.n5.nabble.com/Back-to-Basics-Apache-Camel-Routes-and-Direct-Component-tp5731899p5733419.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Back to Basics : Apache Camel Routes and Direct Component
Posted by Christian Posta <ch...@gmail.com>.
each of your 5 threads will place its exchange into a in-memory queue
representing the SEDA component, and then the threads for the SEDA
component will process the exchanges. That means the seda component will
process the exchange in different threads than your calling thread. The
number of seda threads is configurable by you, so it's not necessarily
"one" like you mention.
On Wed, May 29, 2013 at 7:37 AM, anand_tech <an...@gmail.com> wrote:
> So it means that 5 different threads of direct component will pour the
> messages into one single thread of SEDA ?
>
> I am sorry if i am really being noob here
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Back-to-Basics-Apache-Camel-Routes-and-Direct-Component-tp5731899p5733415.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--
*Christian Posta*
http://www.christianposta.com/blog
twitter: @christianposta
Re: Back to Basics : Apache Camel Routes and Direct Component
Posted by anand_tech <an...@gmail.com>.
So it means that 5 different threads of direct component will pour the
messages into one single thread of SEDA ?
I am sorry if i am really being noob here
--
View this message in context: http://camel.465427.n5.nabble.com/Back-to-Basics-Apache-Camel-Routes-and-Direct-Component-tp5731899p5733415.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Back to Basics : Apache Camel Routes and Direct Component
Posted by Claus Ibsen <cl...@gmail.com>.
The seda component allows to specify a number of concurrent consumers,
so can you process messages in parallel if you want.
When you send a message to a seda endpoint it depends if its InOnly or
InOut. The latter will have the sender wait for the message to
complete (but you can configure this).
See the seda page for more details
http://camel.apache.org/seda
On Thu, May 2, 2013 at 12:03 PM, anand_tech <an...@gmail.com> wrote:
> Thanks, can you also have a look at the last part of my question i.e. route
> having both direct and seda component.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Back-to-Basics-Apache-Camel-Routes-and-Direct-Component-tp5731899p5731903.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Re: Back to Basics : Apache Camel Routes and Direct Component
Posted by anand_tech <an...@gmail.com>.
Thanks, can you also have a look at the last part of my question i.e. route
having both direct and seda component.
--
View this message in context: http://camel.465427.n5.nabble.com/Back-to-Basics-Apache-Camel-Routes-and-Direct-Component-tp5731899p5731903.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Back to Basics : Apache Camel Routes and Direct Component
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
direct is like direct method invocation in java code, eg like calling
a method on a java class.
So this call happens with the current thread.
So like in java if you have concurrent threads calling the same
method, then this happens concurrently.
And the same for the Camel direct component.
SEDA has a queue in between so that allows losly coupling.
On Thu, May 2, 2013 at 11:39 AM, anand_tech <an...@gmail.com> wrote:
> 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")
> }
>
> 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 ?
>
> Also if i change the direct component to seda, will it make any difference ?
>
> Also 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");
> }
>
> 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 ?
>
> TIA
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Back-to-Basics-Apache-Camel-Routes-and-Direct-Component-tp5731899.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen