You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by ekz <ek...@gmail.com> on 2015/04/08 09:04:18 UTC

FTP Reconnect attempt problem

Hi,
I have a route as below. My problem is about reconnect attempts.
I am waiting 1 min for the next poll from ftp with the parameter
"consumer.delay=60000" that is ok, but if the connection fails, expecting 2
min wait before next connection attempt but 
below code is still using 1 min delay for the next connection attempt. 
How can i achive this?
(camel version: 2.14.0)

from("sftp://user@host:port/?password=pw"
                                + "&*consumer.delay=60000*"
                                + "&passiveMode=true"
                                + "&consumer.bridgeErrorHandler=true"
                                + "&throwExceptionOnConnectFailed=true"
                                + "&maximumReconnectAttempts=0"
                                + "&*reconnectDelay=120000*" //reconnect
attempt every 2 min
                                + "&pollStrategy=#customPollStrategy")
.log("consuming file from ftp : ${headers.CamelFileName}");

and my custom poll strategy is as foolws:

public class CustomPollStrategy extends
RemoteFilePollingConsumerPollStrategy {

    @Override
    public synchronized boolean rollback(Consumer consumer, Endpoint
endpoint, int retryCounter, Exception cause) throws Exception {

        //retry 3 times
        if(retryCounter <= 2) {
            //force disconnect
            super.rollback(consumer, endpoint, retryCounter, cause);            
            return true;
        }
        else {
            //give up retry and wait for the next connection attempt.
			return false;
        }        
    }
}



--
View this message in context: http://camel.465427.n5.nabble.com/FTP-Reconnect-attempt-problem-tp5765466.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: FTP Reconnect attempt problem

Posted by ekz <ek...@gmail.com>.
Hi,

This is what i was looking for, Thanks Claus!
"backoff" saved my life.




--
View this message in context: http://camel.465427.n5.nabble.com/FTP-Reconnect-attempt-problem-tp5765466p5765523.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: FTP Reconnect attempt problem

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

The consumer is a single threaded scheduler so if you sleep it for a
long time, then it should not impact.

Mind that the consumer is scheduled polling consumer so it has some
options for backoff in case of error etc.
See
http://camel.apache.org/polling-consumer.html the table in
ScheduledPollConsumer Options

You may be able to use a backoff of 2 and backoffErrorThreshold=1 to
let it delay x2 instead.

On Thu, Apr 9, 2015 at 2:41 PM, ekz <ek...@gmail.com> wrote:
> Hi,
>
> How it is meaningful to put that "Thread.sleep(reconnectDelay)" to
> CustomPollStrategy instead of the one in SftpOperations class ?
>
> public class CustomPollStrategy extends
> RemoteFilePollingConsumerPollStrategy {
>
>     @Override
>     public synchronized boolean rollback(Consumer consumer, Endpoint
> endpoint, int retryCounter, Exception cause) throws Exception {
>
>         //retry 3 times
>         if(retryCounter <= 2) {
>             //force disconnect
>             super.rollback(consumer, endpoint, retryCounter, cause);
>             return true;
>         }
>         else {
>             //give up retry and wait for the next connection attempt.
>             *try {
>                 Thread.sleep(((RemoteFileEndpoint)
> endpoint).getReconnectDelay());
>             } catch (Exception e) {
>             }*
>             return false;
>         }
>     }
> }
>
> Does it have a negative impact on another place of the camel?
> Thanks in advance.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/FTP-Reconnect-attempt-problem-tp5765466p5765513.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/

Re: FTP Reconnect attempt problem

Posted by ekz <ek...@gmail.com>.
Hi,

How it is meaningful to put that "Thread.sleep(reconnectDelay)" to
CustomPollStrategy instead of the one in SftpOperations class ?

public class CustomPollStrategy extends
RemoteFilePollingConsumerPollStrategy { 

    @Override 
    public synchronized boolean rollback(Consumer consumer, Endpoint
endpoint, int retryCounter, Exception cause) throws Exception { 

        //retry 3 times 
        if(retryCounter <= 2) { 
            //force disconnect 
            super.rollback(consumer, endpoint, retryCounter, cause);             
            return true; 
        } 
        else { 
            //give up retry and wait for the next connection attempt. 
            *try {
                Thread.sleep(((RemoteFileEndpoint)
endpoint).getReconnectDelay());
            } catch (Exception e) {
            }*
            return false; 
        }         
    } 
}

Does it have a negative impact on another place of the camel?
Thanks in advance.



--
View this message in context: http://camel.465427.n5.nabble.com/FTP-Reconnect-attempt-problem-tp5765466p5765513.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: FTP Reconnect attempt problem

Posted by ekz <ek...@gmail.com>.
I think i found the problem, 
The code cannot reach to the sleep(reconnectDelay) because
getMaximumReconnectAttempts() is zero.
I need maximumReconnectAttempts=0 to work with customPollStrategy to caught
exceptions, 
but need to set reconnectDelay either.
Any ideas will be appreciated.

//From SftpOperations class:
                ...
                LOG.trace("Cannot connect due: {}", failed.getMessage());
                attempt++;
                if (attempt > *endpoint.getMaximumReconnectAttempts()*) {
                    throw failed;
                }
                if (*endpoint.getReconnectDelay()* > 0) {
                    try {
                        Thread.sleep(endpoint.getReconnectDelay());
                    } catch (InterruptedException ie) {
                        // we could potentially also be interrupted during
sleep
                        Thread.currentThread().interrupt();
                        throw new
GenericFileOperationFailedException("Interrupted during sleeping", ie);
                    }
                }
                ...



--
View this message in context: http://camel.465427.n5.nabble.com/FTP-Reconnect-attempt-problem-tp5765466p5765484.html
Sent from the Camel - Users mailing list archive at Nabble.com.