ddelizia
ddelizia

Reputation: 1571

Camel PollingConsumer - Deleting orphaned lock file, but original file is not deleted

I have a simple route that is getting files ending in .fin which have as body the name of the file that I have to send to an ftp server. This is the route:

<route id="sendToFtp">
    <from uri="file:{{tmp.files.location}}/export/pr?delete=true&amp;include=.*.txt.fin"/>
    <process ref="getFileProcess" />
    <log message="Sending message ${file:name}"/>
    <setHeader headerName="CamelFileName">
        <simple>${file:name.noext}</simple>
    </setHeader>
    <delay>
        <constant>10000</constant>
    </delay>
    <to uri="{{export.feed.ftp}}{{export.feed.ftp.folder}}?username={{export.feed.ftp.username}}&amp;password={{export.feed.ftp.password}}&amp;passiveMode=true&amp;connectTimeout={{feed.interval}}&amp;timeout={{feed.interval}}&amp;soTimeout={{feed.interval}}&amp;disconnect=true" />
</route>

I'm using the polling consumer in the file in order to retrieve the local file to send to the ftp. Here is the process:

@Override
public void process(Exchange exchange) throws Exception {
    final String filename = exchange.getIn().getBody(String.class);

    Endpoint endpoint = exchange.getContext().getEndpoint("file:{{powerreviews.tmp.files.location}}/export/pr?delete=true&fileName="+filename);

    PollingConsumer consumer = endpoint.createPollingConsumer();

    consumer.start();
    Exchange ex = consumer.receive(60000);

    if (ex==null){
        exchange.getIn().setBody("");
    }else {
        exchange.getIn().setBody(ex.getIn().getBody());
    }
    consumer.stop();
}

when I execute the route it seems that the exchanges are not closed after the end of the route cause my files .fin and the one that i consume with the pollingConsume are not deleted, when I explicitly have in the endpoint delete=true parameter. Anyway the file is correctly sent to the ftp.

In the log I have the following:

2014-06-27 20:23:03,765 | WARN  | roduct/export/pr | kerFileExclusiveReadLockStrategy | 100 - org.apache.camel.camel-core - 2.10.7 | Deleting orphaned lock file: tmp/product/export/pr/the.txt.fin.camelLock
2014-06-27 20:28:08,041 | WARN  | roduct/export/pr | kerFileExclusiveReadLockStrategy | 100 - org.apache.camel.camel-core - 2.10.7 | Deleting orphaned lock file: tmp/product/export/pr/the.txt.camelLock

Upvotes: 1

Views: 1795

Answers (1)

Claus Ibsen
Claus Ibsen

Reputation: 55540

The file is not deleted because the onCompletion on the Exchange ex the consumer template returned is not executed. The javadoc documentation documents this in much more details.

But as you want to delete the filter later, so you can upload it to the FTP server first, you need to handover the onCompletions from Exchange ex to Exchange exchange, so add this code at the end of that method

    }
    consumer.stop();

    // handover from me to the incoming exchange
    // so we will delete the file at the end of the route
    ex.handoverCompletions(exchange);
}

Upvotes: 2

Related Questions