Camel Router is blocked while waiting for response

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Camel Router is blocked while waiting for response

S.R.-2
For example, I have the following route:

// main route
from("jms:testQueue").to("jms:someOtherQueue");

// and test consumer for "jms:someOtherQueue"
from("jms:someOtherQueue").process(new Processor() {
       public void process(Exchange exchange) throws Exception {      
                Thread.sleep(10000);
                exchange.getOut().setBody("Reply");
       }
});

It's easy to see that when we send request message (with JMSReplyTo field set) to the jms:testQueue, the Camel Router is blocked until reply from jms:someOtherQueue consumer is received, therefore new incoming messages can't be processed/routed during this time.

Does Camel have some abilities or configuration settings to avoid this, and make this waiting asynchronous, so that other messages could be processed even if some of the previous messages hasn't been completely processed/routed yet?

Thank you,
Sergey
Reply | Threaded
Open this post in threaded view
|

RE: Camel Router is blocked when waiting for response

Claus Ibsen
Hi

The JMS stuff is really a James question but I dare to give the answer.

The JMS component has many options:
http://activemq.apache.org/camel/jms.html

The one you are looking for is concurrentConsumers
Default it is set to 1 so Camel will only allow one consumer at a time.

You can increase this value to be able to work in parallel.

I am working on a unit test that demonstrates this behavior:

Output from 5 threads sending a message to your route with: concurrentConsumers=2

Starting thread #0
Starting thread #1
Starting thread #2
Starting thread #4
Starting thread #3
Recived: Hello World #0
Recived: Hello World #4
Asserting response #4
Asserting response #0
Recived: Hello World #1
Recived: Hello World #2
Asserting response #2
Asserting response #1
Recived: Hello World #3
Asserting response #3

And of course with concurrentConsumers=5 they all run in parallel:
Starting thread #0
Starting thread #2
Starting thread #4
Starting thread #1
Starting thread #3
Recived: Hello World #2
Recived: Hello World #0
Recived: Hello World #4
Recived: Hello World #1
Recived: Hello World #3
Asserting response #1
Asserting response #2
Asserting response #3
Asserting response #0
Asserting response #4


    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            public void configure() throws Exception {
                from("activemq:a?concurrentConsumers=3").to("activemq:b?concurrentConsumers=3");

                from("activemq:b?concurrentConsumers=3").process(new Processor() {
                    public void process(Exchange exchange) throws Exception {
                        System.out.println("Recived: " + exchange.getIn().getBody(String.class));
                        Thread.sleep(1000);
                        exchange.getOut().setBody("Bye World");
                    }
                });
            }
        };
    }

Process finished with exit code 1

Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk
-----Original Message-----
From: S.R. [mailto:[hidden email]]
Sent: 8. juli 2008 13:04
To: [hidden email]
Subject: Camel Router is blocked when waiting for response


For example, I have the following route:

// main route
from("jms:testQueue").to("jms:someOtherQueue");

// and test consumer for "jms:someOtherQueue"
from("jms:someOtherQueue").process(new Processor() {
       public void process(Exchange exchange) throws Exception {      
                Thread.sleep(10000);
                exchange.getOut().setBody("Reply");
       }
});

It's easy to see that when we send request message (with JMSReplyTo field
set) to the jms:testQueue, the Camel Router is blocked until reply from
jms:someOtherQueue consumer is received, therefore new incoming messages
can't be processed/routed during this time.

Does Camel have some abilities or configuration settings to avoid this, and
make this waiting asynchronous, so that other messages could be processed
even if some of the previous messages hasn't been completely
processed/routed yet?

Thank you,
Sergey
--
View this message in context: http://www.nabble.com/Camel-Router-is-blocked-when-waiting-for-response-tp18336673s22882p18336673.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

RE: Camel Router is blocked when waiting for response

Claus Ibsen
See this unit test:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsConcurrentConsumersTest.java?view=markup


Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk

-----Original Message-----
From: Claus Ibsen [mailto:[hidden email]]
Sent: 8. juli 2008 18:54
To: [hidden email]
Subject: RE: Camel Router is blocked when waiting for response

Hi

The JMS stuff is really a James question but I dare to give the answer.

The JMS component has many options:
http://activemq.apache.org/camel/jms.html

The one you are looking for is concurrentConsumers
Default it is set to 1 so Camel will only allow one consumer at a time.

You can increase this value to be able to work in parallel.

I am working on a unit test that demonstrates this behavior:

Output from 5 threads sending a message to your route with: concurrentConsumers=2

Starting thread #0
Starting thread #1
Starting thread #2
Starting thread #4
Starting thread #3
Recived: Hello World #0
Recived: Hello World #4
Asserting response #4
Asserting response #0
Recived: Hello World #1
Recived: Hello World #2
Asserting response #2
Asserting response #1
Recived: Hello World #3
Asserting response #3

And of course with concurrentConsumers=5 they all run in parallel:
Starting thread #0
Starting thread #2
Starting thread #4
Starting thread #1
Starting thread #3
Recived: Hello World #2
Recived: Hello World #0
Recived: Hello World #4
Recived: Hello World #1
Recived: Hello World #3
Asserting response #1
Asserting response #2
Asserting response #3
Asserting response #0
Asserting response #4


    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            public void configure() throws Exception {
                from("activemq:a?concurrentConsumers=3").to("activemq:b?concurrentConsumers=3");

                from("activemq:b?concurrentConsumers=3").process(new Processor() {
                    public void process(Exchange exchange) throws Exception {
                        System.out.println("Recived: " + exchange.getIn().getBody(String.class));
                        Thread.sleep(1000);
                        exchange.getOut().setBody("Bye World");
                    }
                });
            }
        };
    }

Process finished with exit code 1

Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk
-----Original Message-----
From: S.R. [mailto:[hidden email]]
Sent: 8. juli 2008 13:04
To: [hidden email]
Subject: Camel Router is blocked when waiting for response


For example, I have the following route:

// main route
from("jms:testQueue").to("jms:someOtherQueue");

// and test consumer for "jms:someOtherQueue"
from("jms:someOtherQueue").process(new Processor() {
       public void process(Exchange exchange) throws Exception {      
                Thread.sleep(10000);
                exchange.getOut().setBody("Reply");
       }
});

It's easy to see that when we send request message (with JMSReplyTo field
set) to the jms:testQueue, the Camel Router is blocked until reply from
jms:someOtherQueue consumer is received, therefore new incoming messages
can't be processed/routed during this time.

Does Camel have some abilities or configuration settings to avoid this, and
make this waiting asynchronous, so that other messages could be processed
even if some of the previous messages hasn't been completely
processed/routed yet?

Thank you,
Sergey
--
View this message in context: http://www.nabble.com/Camel-Router-is-blocked-when-waiting-for-response-tp18336673s22882p18336673.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

RE: Camel Router is blocked when waiting for response

S.R.-2
Hi Claus,

Thank you very much!

That's really what I was looking for!

Sergey

Claus Ibsen wrote
See this unit test:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/JmsConcurrentConsumersTest.java?view=markup


Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk

-----Original Message-----
From: Claus Ibsen [mailto:ci@silverbullet.dk]
Sent: 8. juli 2008 18:54
To: camel-user@activemq.apache.org
Subject: RE: Camel Router is blocked when waiting for response

Hi

The JMS stuff is really a James question but I dare to give the answer.

The JMS component has many options:
http://activemq.apache.org/camel/jms.html

The one you are looking for is concurrentConsumers
Default it is set to 1 so Camel will only allow one consumer at a time.

You can increase this value to be able to work in parallel.

I am working on a unit test that demonstrates this behavior:

Output from 5 threads sending a message to your route with: concurrentConsumers=2

Starting thread #0
Starting thread #1
Starting thread #2
Starting thread #4
Starting thread #3
Recived: Hello World #0
Recived: Hello World #4
Asserting response #4
Asserting response #0
Recived: Hello World #1
Recived: Hello World #2
Asserting response #2
Asserting response #1
Recived: Hello World #3
Asserting response #3

And of course with concurrentConsumers=5 they all run in parallel:
Starting thread #0
Starting thread #2
Starting thread #4
Starting thread #1
Starting thread #3
Recived: Hello World #2
Recived: Hello World #0
Recived: Hello World #4
Recived: Hello World #1
Recived: Hello World #3
Asserting response #1
Asserting response #2
Asserting response #3
Asserting response #0
Asserting response #4


    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            public void configure() throws Exception {
                from("activemq:a?concurrentConsumers=3").to("activemq:b?concurrentConsumers=3");

                from("activemq:b?concurrentConsumers=3").process(new Processor() {
                    public void process(Exchange exchange) throws Exception {
                        System.out.println("Recived: " + exchange.getIn().getBody(String.class));
                        Thread.sleep(1000);
                        exchange.getOut().setBody("Bye World");
                    }
                });
            }
        };
    }

Process finished with exit code 1

Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk
-----Original Message-----
From: S.R. [mailto:srassokhin@gmail.com]
Sent: 8. juli 2008 13:04
To: camel-user@activemq.apache.org
Subject: Camel Router is blocked when waiting for response


For example, I have the following route:

// main route
from("jms:testQueue").to("jms:someOtherQueue");

// and test consumer for "jms:someOtherQueue"
from("jms:someOtherQueue").process(new Processor() {
       public void process(Exchange exchange) throws Exception {      
                Thread.sleep(10000);
                exchange.getOut().setBody("Reply");
       }
});

It's easy to see that when we send request message (with JMSReplyTo field
set) to the jms:testQueue, the Camel Router is blocked until reply from
jms:someOtherQueue consumer is received, therefore new incoming messages
can't be processed/routed during this time.

Does Camel have some abilities or configuration settings to avoid this, and
make this waiting asynchronous, so that other messages could be processed
even if some of the previous messages hasn't been completely
processed/routed yet?

Thank you,
Sergey
--
View this message in context: http://www.nabble.com/Camel-Router-is-blocked-when-waiting-for-response-tp18336673s22882p18336673.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: Camel Router is blocked when waiting for response

jstrachan
In reply to this post by S.R.-2
2008/7/8 S.R. <[hidden email]>:

>
> For example, I have the following route:
>
> // main route
> from("jms:testQueue").to("jms:someOtherQueue");
>
> // and test consumer for "jms:someOtherQueue"
> from("jms:someOtherQueue").process(new Processor() {
>       public void process(Exchange exchange) throws Exception {
>                Thread.sleep(10000);
>                exchange.getOut().setBody("Reply");
>       }
> });
>
> It's easy to see that when we send request message (with JMSReplyTo field
> set) to the jms:testQueue, the Camel Router is blocked until reply from
> jms:someOtherQueue consumer is received, therefore new incoming messages
> can't be processed/routed during this time.
>
> Does Camel have some abilities or configuration settings to avoid this, and
> make this waiting asynchronous, so that other messages could be processed
> even if some of the previous messages hasn't been completely
> processed/routed yet?

As Claus mentioned, you can use concurrent consumers so that you can
process things in parallel.

Camel tries very hard to do the right thing using convention over
configuration; when using a JMSReplyTo address the common convention
is to send a reply back - hence the blocking. If you want to avoid
blocking and sending a reply back you can configure the JMS/ActiveMQ
endpoint to ignore the JMSReplyTo address and just send the message on
as a one-way message (so that it is the downstream endpoints issue to
deal with :)

See the disableReplyTo property - just set that to true...
http://activemq.apache.org/camel/jms.html

--
James
-------
http://macstrac.blogspot.com/

Open Source Integration
http://open.iona.com