Hello Claus!
Now we solved it. We have used a customized poll strategy and therefore the
option maximumReconnectAttempts
and reconnectDelay respectively were without effect. We could make the
reconnect work by restart the consumer
in the poll strategy implementation's rollback() method:
public class DN1PollingConsumerPollStrategy implements
PollingConsumerPollStrategy {
...
@Override
public boolean rollback(Consumer consumer, Endpoint endpoint, int
retryCounter, Exception cause)
throws Exception {
LOG.error("Polling consumer failed: " + cause.getMessage(), cause);
if (cause.getMessage().contains("User cannot log")) {
throw new
DN1TransferException(
"The user cannot log in!");
}
LOG.info("Consumer is going to restart!");
consumer.stop();
consumer.start();
return false;
}
}
The code snippet above stops the route if the ftp login failed but otherwise
always tries to reconnect
when a established connection was disruppted.
Because the ftp polling consumer route is a dynamic one we also check if the
server is
reachable before the dynamic route is added to the camel context:
private boolean checkConnection(String host, Integer port) {
Socket socket = new Socket();
InetSocketAddress endPoint = new InetSocketAddress(host, port);
boolean isConnectionValid = false;
if (endPoint.isUnresolved()) {
return isConnectionValid;
} else {
try {
socket.connect(endPoint, 2000);
isConnectionValid = true;
} catch (IOException ioe) {
return isConnectionValid;
} finally {
if (socket != null) {
try {
socket.close();
}
catch (IOException ioe) {
LOG.error("Error occured by closing the ftp
connection", ioe);
}
}
}
}
return isConnectionValid;
}
By this we have the chance to react accordingly when the server is out of range
or the
ftp login failed, but more importantly otherwise the reconnect stays intact.
Cheers
Hilde
________________________________
Von: Claus Ibsen <[email protected]>
An: [email protected]; Hildegard Schedthelm <[email protected]>
Gesendet: 11:34 Donnerstag, 29.November 2012
Betreff: Re: ftp-consumer: recovering a previous established connection
On Thu, Nov 29, 2012 at 10:12 AM, Hildegard Schedthelm
<[email protected]> wrote:
> Hello Claus!
>
> Thanks a lot for
helping.
>
>
> I cannot conceive how a different poll interval can help to start polling at
> all.
>
> The ftp component derived from the file component that has the batch consumer
>
> implemented to poll multiple exchanges. When I start downloading e.g. about
> 10 files from
>
> a ftp server I'd infer that polling occurs just once. That might be the
> reason the re-connect
>
> doesn't trigger as a consequence no polling occurs any more. Are theses
> notions correct?
>
If you download 4 files, and have problem with the 5th, then the
consumer will fail.
And on next scheduled poll, it will re-connect and start again, but as
the previous 4 files has been downloaded,
then it will start with the 5th file.