You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by "ravi.4indra" <ra...@gmail.com> on 2012/10/26 02:29:44 UTC

Camel Timeout on a route

Hi,

Is there a way to specify timeout on a route.

Example
from(direct:route1)
.to(bean:dosomething)
.to(direct:commonRoute)

now if the commonRoute takes more than n milliseconds i want to get a
timeout exception. 

FYI I tried seda component I got the timeout exception after n seconds but
the commonRoute continued its processing(may be it runs on  different
thread).


Any help is appreciated.

Thanks
R



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Timeout-on-a-route-tp5721576.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel Timeout on a route

Posted by "ravi.4indra" <ra...@gmail.com>.
Thanks for your help willem. I got that working, chaged my code a bit and it
worked.


Thanks
Ravi



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Timeout-on-a-route-tp5721576p5721753.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel Timeout on a route

Posted by "ravi.4indra" <ra...@gmail.com>.
I am not getting any errors but the second webservice call is not picking up
the timeout I have set.Its always taking the value the timeout that was set
to the first webservice call.

Thanks
Ravi



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Timeout-on-a-route-tp5721576p5721743.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel Timeout on a route

Posted by Willem jiang <wi...@gmail.com>.
I just wrote a test and verified I can set the timeout value on the second cxf endpoint without any trouble.
What's the error did you get?

BTW, you should get the socket read time out as you set the receive time out to 1 mill second. 

-- 
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.javaeye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang 
Weibo: willemjiang





On Monday, October 29, 2012 at 2:16 PM, ravi.4indra wrote:

> I am still having that problem.I had removed responseContext,RequestContext
> from the inMessage and added a requestContext with a new ClientPolicy .Do i
> to remove any other headers?
> 
> below is the code snippet 
> 
> exchange.getIn().removeHeader(Client.RESPONSE_CONTEXT);
> exchange.getIn().removeHeader(Client.REQUEST_CONTEXT);
> Map<String, Object> requestContext = new HashMap<String, Object>();
> HTTPClientPolicy clientPolicy = new HTTPClientPolicy();
> clientPolicy.setReceiveTimeout(1);
> requestContext.put(HTTPClientPolicy.class.getName(), clientPolicy);
> exchange.getIn().setHeader(Client.REQUEST_CONTEXT , requestContext);
> 
> Thanks
> Ravi
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-Timeout-on-a-route-tp5721576p5721692.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).




Re: Camel Timeout on a route

Posted by "ravi.4indra" <ra...@gmail.com>.
I am still having that problem.I had removed responseContext,RequestContext
from the inMessage and added a requestContext with a new ClientPolicy .Do i
to remove any other headers?

below is the code snippet 

exchange.getIn().removeHeader(Client.RESPONSE_CONTEXT);
exchange.getIn().removeHeader(Client.REQUEST_CONTEXT);
 Map<String, Object> requestContext = new HashMap<String, Object>();
 HTTPClientPolicy clientPolicy = new HTTPClientPolicy();
 clientPolicy.setReceiveTimeout(1);
 requestContext.put(HTTPClientPolicy.class.getName(), clientPolicy);
exchange.getIn().setHeader(Client.REQUEST_CONTEXT , requestContext);

Thanks
Ravi



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Timeout-on-a-route-tp5721576p5721692.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel Timeout on a route

Posted by "Willem.Jiang" <wi...@gmail.com>.
I think it should work.
Please let me if you still stuck with it.

Willem



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Timeout-on-a-route-tp5721576p5721691.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel Timeout on a route

Posted by "ravi.4indra" <ra...@gmail.com>.
Hi Willem,

Thanks for sharing the information. I have two webservices call in a camel
route. I am noticing that the timeout i have set for the first call is being
used for the second web service call. even though i have changed the timeout
in 3 step to less than the default timeout it is always taking the timeout
that is set first step.

1 to(bean:addTimeout)
2 to(cxf:webservice1)
3 to(bean:changeTimeout)
4 to(cxf:webservice2)

to change the timeout for the second web service call I removed the request
context from the header and added back the request context(client Policy)
with new timeout value. 

can you please suggest?

Thanks
Ravi



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Timeout-on-a-route-tp5721576p5721690.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel Timeout on a route

Posted by Willem jiang <wi...@gmail.com>.
Hi, 
It dependents on how you setup the  client request context header.
You may need to clean up the header if you don't want to the setting affect the next camel-cxf producer.

By default camel-cxf endpoint will copy the message headers from the in message to the out message,
 which means the client request header will still effect on the second camel-cxf endpoint.

-- 
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.javaeye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang 
Weibo: willemjiang





On Monday, October 29, 2012 at 11:19 AM, ravi.4indra wrote:

> Also i dont have any default configuration. so the first time i set the
> timeout it will remain as my default timeout for all the endpoints? 
> 
> bean(mapper,"changeTimeOut")
> to(cxf://webservice1)
> bean(mapper,"changeTimeOut")
> to(cxf://webservice2)
> 
> I noticed that webservice2 is using the timeout value set during the first
> step. can you explain this behaviour?
> 
> Thanks
> Ravi
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-Timeout-on-a-route-tp5721576p5721684.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).




Re: Camel Timeout on a route

Posted by "ravi.4indra" <ra...@gmail.com>.
Also i dont have any default configuration. so the first time i set the
timeout it will remain as my default timeout for all the endpoints? 

bean(mapper,"changeTimeOut")
to(cxf://webservice1)
bean(mapper,"changeTimeOut")
to(cxf://webservice2)

I noticed that webservice2 is using the timeout value set during the first
step. can you explain this behaviour?

Thanks
Ravi



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Timeout-on-a-route-tp5721576p5721684.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel Timeout on a route

Posted by Willem jiang <wi...@gmail.com>.
Hi Ravi,

The default connection timeout is 30000(ms), default receive timeout is 60000(ms).
You can find more information here[1]
And you can change the default setting like this[2]

[1]http://cxf.apache.org/docs/client-http-transport-including-ssl-support.html#ClientHTTPTransport%28includingSSLsupport%29-The%7B%7Bclient%7D%7Delement
[2]https://svn.apache.org/repos/asf/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/cxfConduitTimeOutContext.xml


-- 
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.javaeye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang 
Weibo: willemjiang





On Monday, October 29, 2012 at 11:08 AM, ravi.4indra wrote:

> Thanks willem. I think by default timeout is 30000 (ms). Can you point me to
> way to set a default timeout on cxf endpoint?
> 
> Thanks
> Ravi
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-Timeout-on-a-route-tp5721576p5721683.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).




Re: Camel Timeout on a route

Posted by "ravi.4indra" <ra...@gmail.com>.
Thanks willem. I think by default timeout is 30000 (ms). Can you point me to
way to set a default timeout on cxf endpoint?

Thanks
Ravi



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Timeout-on-a-route-tp5721576p5721683.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel Timeout on a route

Posted by Willem jiang <wi...@gmail.com>.
Oh, there is a thing I didn't point out ,  when we set the time out value on through the message header, CXF will do a merge with the default configuration and take the min one.
So it could be better you setup a big time out  value on the default.

-- 
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.javaeye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang 
Weibo: willemjiang





On Monday, October 29, 2012 at 5:52 AM, ravi.4indra wrote:

> Hi,
> 
> I am using camel-CXF component.I am suspecting that the request context is
> being cached somewhere in the cxf/camel code thats the reason new timeout
> value is not honored.
> 
> can you please provide a solution for this?
> 
> Thanks
> Ravi
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-Timeout-on-a-route-tp5721576p5721678.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).




Re: Camel Timeout on a route

Posted by "ravi.4indra" <ra...@gmail.com>.
Hi,

I am using camel-CXF component.I am suspecting that the request context is
being cached somewhere in the cxf/camel code thats the reason new timeout
value is not honored.

can you please provide a solution for this?

Thanks
Ravi



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Timeout-on-a-route-tp5721576p5721678.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel Timeout on a route

Posted by "ravi.4indra" <ra...@gmail.com>.
Hi Willem,

I was able to set the timeout Dynamically FirstTime. But when i tried change
the client policy somwhere in  my route its not picking up the new value.

is this the expected behaviour?

Tanks
Ravi



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Timeout-on-a-route-tp5721576p5721675.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel Timeout on a route

Posted by Willem jiang <wi...@gmail.com>.
Hi, 

I just add an unit test to show how to set the HttpClientPolicy dynamically.
You can set the receive timeout through the message header like this[1]

http://svn.apache.org/viewvc?rev=1402926&view=rev 

-- 
Willem Jiang

Red Hat, Inc.
FuseSource is now part of Red Hat
Web: http://www.fusesource.com | http://www.redhat.com
Blog: http://willemjiang.blogspot.com (http://willemjiang.blogspot.com/) (English)
          http://jnn.javaeye.com (http://jnn.javaeye.com/) (Chinese)
Twitter: willemjiang 
Weibo: willemjiang





On Sunday, October 28, 2012 at 12:18 AM, ravi.4indra wrote:

> Hi,
> 
> Is there a way to set timeout dynamically in camel-cxf component?.
> 
> So do the total timeout of 60 seconds, if the first webservice call took 10
> seconds then the timeout of second webservice call is 60-10 seconds.
> 
> for this i need to set the timeout using exchange header. is it possible to
> do? 
> 
> Thanks
> Ravi
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-Timeout-on-a-route-tp5721576p5721640.html
> Sent from the Camel - Users mailing list archive at Nabble.com (http://Nabble.com).




Re: Camel Timeout on a route

Posted by "ravi.4indra" <ra...@gmail.com>.
Hi,

Is there a way to set timeout dynamically in camel-cxf component?.

So do the total timeout of 60 seconds, if the first webservice call took 10
seconds then the timeout of second webservice call is 60-10 seconds.

for this i need to set the timeout using exchange header. is it possible to
do? 

Thanks
Ravi



--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Timeout-on-a-route-tp5721576p5721640.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel Timeout on a route

Posted by "ravi.4indra" <ra...@gmail.com>.
Hi Raul,

can you please provide your inputs on the below piece of code. 

This method the uses the producer template asyncCallback to call the
commonRoute.and i used the future handle to get the response.

  public void getDataUsingProducerTemplate(Exchange exchange) throws
TimeoutException, InterruptedException, ExecutionException {
    	ProducerTemplate template = camelContext.createProducerTemplate();
    	Future<Exchange> future = template.asyncCallback("direct:commonRoute",
exchange, new  SynchronizationImpl());
    	// Retrieve the reply from the main thread, specifying a timeout
    	try {
			future.get(2, TimeUnit.SECONDS);
		}catch (TimeoutException e) {
			//exchange.setException(e);
			future.cancel(true);
Thread.sleep(1000)
			throw e;			
		}
}

Without the thread sleep my global exception handler (On Exception) is not
able to catch the exception.

Thanks
Ravi




--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Timeout-on-a-route-tp5721576p5721623.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel Timeout on a route

Posted by Raul Kripalani <ra...@evosent.com>.
Hi Ravi,

You should use set timeouts on the outgoing CXF invocations, where the sum
of the CXF timeouts is a tad lower than the timeout you set on the SEDA
call to commonRoute. I call this the "cascading timeouts" pattern.

So if timeout(webservice1) + timeout(webservice2) + timeout(webservice3) =
10000ms, you can turn direct:commonRoute into a SEDA endpoint and set the
"timeout" option of the SEDA producer to 11000ms, for example.

Here's an example that shows how to set timeouts on CXF producers [1].

[1]
https://svn.apache.org/repos/asf/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/cxfConduitTimeOutContext.xml
.

Regards,

*Raúl Kripalani*
Apache Camel Committer
Enterprise Architect, Program Manager, Open Source Integration specialist
http://about.me/raulkripalani | http://www.linkedin.com/in/raulkripalani
http://blog.raulkr.net | twitter: @raulvk <http://twitter.com/raulvk>

On Fri, Oct 26, 2012 at 5:38 AM, ravi.4indra <ra...@gmail.com> wrote:

> Thanks for your reply!!
> common route makes a series of webservices calls
>
> like
>
> to(cxf://webservice1)
> .bean(processresponse)
> to(cxf://webservice2)
> .bean(processresponse)
> to(cxf://webservice3)
> .bean(processresponse)
>
> Thanks
> Ravi
>
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Camel-Timeout-on-a-route-tp5721576p5721581.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Camel Timeout on a route

Posted by "ravi.4indra" <ra...@gmail.com>.
Thanks for your reply!!
common route makes a series of webservices calls

like 

to(cxf://webservice1)
.bean(processresponse)
to(cxf://webservice2)
.bean(processresponse)
to(cxf://webservice3)
.bean(processresponse)

Thanks
Ravi
      




--
View this message in context: http://camel.465427.n5.nabble.com/Camel-Timeout-on-a-route-tp5721576p5721581.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Camel Timeout on a route

Posted by Raul Kripalani <ra...@evosent.com>.
Many Camel components support specifying timeouts, e.g. JMS, CXF, Jetty,
etc.

What does commonRoute do? Could you post its code so we can help you
further?

Thanks.

Sent from a mobile device
On 26 Oct 2012 01:32, "ravi.4indra" <ra...@gmail.com> wrote:

> Hi,
>
> Is there a way to specify timeout on a route.
>
> Example
> from(direct:route1)
> .to(bean:dosomething)
> .to(direct:commonRoute)
>
> now if the commonRoute takes more than n milliseconds i want to get a
> timeout exception.
>
> FYI I tried seda component I got the timeout exception after n seconds but
> the commonRoute continued its processing(may be it runs on  different
> thread).
>
>
> Any help is appreciated.
>
> Thanks
> R
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Camel-Timeout-on-a-route-tp5721576.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>