You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by desenfoque <cs...@gmail.com> on 2017/05/03 18:45:55 UTC

TimeOut in ConsumerTemplate not working (Takes forever)

Hi.

I have a processor with this ConsumerTemplate:

ConsumerTemplate consumerCorr =
exchange.getContext().createConsumerTemplate();
String URI_CORR = http://10.100.7.4:8080/ServiciosRest/rest/correlativo/get

*String respCorr = consumerCorr.receiveBody(URI_CORR,10000,String.class);*


I'm expecting a 10 seconds timeout, but I have to wait a lot (several
minutes) and I get this Exception

*org.apache.camel.RuntimeCamelException: java.net.ConnectException:
Connection timed out

  at
org.apache.camel.component.http.HttpPollingConsumer.doReceive(HttpPollingConsumer.java:97)[org.apache.camel:camel-http:2.15.1.redhat-620133]*


but I was expecting a *null * because the documentation says that:

<String> String org.apache.camel.ConsumerTemplate.receiveBody(String
endpointUri, long timeout, Class<String> type)

Receives from the endpoint, waiting until there is a response or the timeout
occurs
Type Parameters:
<T>
Parameters:endpointUri the endpoint to receive from
timeout timeout in millis to wait for a response
type the expected response type

*Returns:the returned response body, or null if no response*


What is happening? I'm using the ComsumerTemplate wrong??



--
View this message in context: http://camel.465427.n5.nabble.com/TimeOut-in-ConsumerTemplate-not-working-Takes-forever-tp5798621.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: TimeOut in ConsumerTemplate not working (Takes forever)

Posted by desenfoque <cs...@gmail.com>.
ah! That explains why Timeout works with File component but no with http.
Thanks...

I'm using a ConsumerTemplate because I can't use pollEnrich in the way I
want (I'm using camel 2.15). 





--
View this message in context: http://camel.465427.n5.nabble.com/TimeOut-in-ConsumerTemplate-not-working-Takes-forever-tp5798621p5798752.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: TimeOut in ConsumerTemplate not working (Takes forever)

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Its not a hard timeout. The timout is passed down to the component
being used if possible and it tries to honor that. In this case its a
timeout for the socket connection

       // set optional timeout in millis
        if (timeout > 0) {
            method.getParams().setSoTimeout(timeout);
        }

And you should not use ConsumerTemplate with a http endpoint, as it
does not make so much sense. Use the producer template to make a HTTP
call. You can use the api that returns a future where you can use its
api for a timeout.

We should probably deprecate the http polling consumer

On Wed, May 3, 2017 at 2:45 PM, desenfoque <cs...@gmail.com> wrote:
> Hi.
>
> I have a processor with this ConsumerTemplate:
>
> ConsumerTemplate consumerCorr =
> exchange.getContext().createConsumerTemplate();
> String URI_CORR = http://10.100.7.4:8080/ServiciosRest/rest/correlativo/get
>
> *String respCorr = consumerCorr.receiveBody(URI_CORR,10000,String.class);*
>
>
> I'm expecting a 10 seconds timeout, but I have to wait a lot (several
> minutes) and I get this Exception
>
> *org.apache.camel.RuntimeCamelException: java.net.ConnectException:
> Connection timed out
>
>   at
> org.apache.camel.component.http.HttpPollingConsumer.doReceive(HttpPollingConsumer.java:97)[org.apache.camel:camel-http:2.15.1.redhat-620133]*
>
>
> but I was expecting a *null * because the documentation says that:
>
> <String> String org.apache.camel.ConsumerTemplate.receiveBody(String
> endpointUri, long timeout, Class<String> type)
>
> Receives from the endpoint, waiting until there is a response or the timeout
> occurs
> Type Parameters:
> <T>
> Parameters:endpointUri the endpoint to receive from
> timeout timeout in millis to wait for a response
> type the expected response type
>
> *Returns:the returned response body, or null if no response*
>
>
> What is happening? I'm using the ComsumerTemplate wrong??
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/TimeOut-in-ConsumerTemplate-not-working-Takes-forever-tp5798621.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2