我有一个SFTP路由(在Spring XML中),它的路径以每日更改的目录(即./yyyyMMdd)结尾,并且当所有路径都在autoCreate=true
或目录在路线开始时存在。但是如果不存在,我不允许创建目录!骆驼 - 当消费目录不存在时停止路由
当目录存在时,路由获取文件并自行终止。
当目录不存在时,路由将永久轮询并出现警告(即org.apache.camel.component.file.GenericFileOperationFailedException: Cannot change directory to: 20160917
),并且永不停止。
如何避免此行为(例如,将警告转换为空的消息或异常或...)?我已经完成了对startingDirectoryMustExist,consumer.bridgeErrorHandler和其他许多项目的实验,但没有取得任何成功。
简化路线(开始前,填补了elmu.sftp.importDir属性与实际为准):
<from
uri="sftp://{{elmu.sftp.host}}:{{elmu.sftp.port}}{{elmu.sftp.importDir}}?username={{elmu.sftp.userName}}&password={{elmu.sftp.password}}&
autoCreate=false&preferredAuthentications=password&binary=true&include={{elmu.importMask}}&initialDelay=100&
noop=true&sortBy=file:name&sendEmptyMessageWhenIdle=true"/>
<choice>
<when>
<simple>${body} != null</simple>
... a lot of stuff ...
<to uri="bean:shutdownRoute" />
</when>
<otherwise>
<to uri="bean:shutdownRoute" />
</otherwise>
</choice>
随着directoryMustExist=true and startingDirectoryMustExist=true
结果是一个无限循环(调查)有这样的警告:
08:30:14,658 WARN SftpConsumer - Consumer Consumer[sftp://xxx.xxx.xx:22/DBHtest/ELMUteszt/Kiadott_adatok/20160918?autoCreate=false&binary=true&directoryMustExist=true&include=%5E.*%24&initialDelay=100&noop=true&password=xxxxxx&preferredAuthentications=password&sendEmptyMessageWhenIdle=true&sortBy=file%3Aname&startingDirectoryMustExist=true&username=xxx] failed polling endpoint: Endpoint[sftp://xxx:22/DBHtest/ELMUteszt/Kiadott_adatok/20160918?autoCreate=false&binary=true&directoryMustExist=true&include=%5E.*%24&initialDelay=100&noop=true&password=xxxxxx&preferredAuthentications=password&sendEmptyMessageWhenIdle=true&sortBy=file%3Aname&startingDirectoryMustExist=true&username=xxx]. Will try again at next poll. Caused by: [org.apache.camel.component.file.GenericFileOperationFailedException - Cannot change directory to: 20160918]
org.apache.camel.component.file.GenericFileOperationFailedException: Cannot change directory to: 20160918
at org.apache.camel.component.file.remote.SftpOperations.doChangeDirectory(SftpOperations.java:576)
at org.apache.camel.component.file.remote.SftpOperations.changeCurrentDirectory(SftpOperations.java:564)
at org.apache.camel.component.file.remote.SftpConsumer.doPollDirectory(SftpConsumer.java:107)
at org.apache.camel.component.file.remote.SftpConsumer.pollDirectory(SftpConsumer.java:79)
at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:131)
at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:175)
at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:102)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.runAndReset(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: 2: No such file
at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2846)
at com.jcraft.jsch.ChannelSftp._realpath(ChannelSftp.java:2340)
at com.jcraft.jsch.ChannelSftp.cd(ChannelSftp.java:342)
at org.apache.camel.component.file.remote.SftpOperations.doChangeDirectory(SftpOperations.java:574)
... 13 more
它不stepwise=false
工作:
11:52:19,210 WARN SftpConsumer - Consumer Consumer[sftp://xxx:22/DBHtest/ELMUteszt/Kiadott_adatok/20160918?autoCreate=false&binary=true&directoryMustExist=true&include=%5E.*%24&initialDelay=100&noop=true&password=xxxxxx&preferredAuthentications=password&sendEmptyMessageWhenIdle=true&sortBy=file%3Aname&startingDirectoryMustExist=true&stepwise=false&username=xxx] failed polling endpoint: Endpoint[sftp://xxx:22/DBHtest/ELMUteszt/Kiadott_adatok/20160918?autoCreate=false&binary=true&directoryMustExist=true&include=%5E.*%24&initialDelay=100&noop=true&password=xxxxxx&preferredAuthentications=password&sendEmptyMessageWhenIdle=true&sortBy=file%3Aname&startingDirectoryMustExist=true&stepwise=false&username=xxx]. Will try again at next poll. Caused by: [org.apache.camel.component.file.GenericFileOperationFailedException - Cannot list directory: DBHtest/ELMUteszt/Kiadott_adatok/20160918]
org.apache.camel.component.file.GenericFileOperationFailedException: Cannot list directory: DBHtest/ELMUteszt/Kiadott_adatok/20160918
更新(根据@ ruffp的回答):
我试图设置一个自定义的PollingConsumerPollStrategy,但我不能阻止它的路线。只有第三条(注释行)停止路线,但我有几条路线,我不知道实际路线的名称。我怎么才能得到它?
@Override
public boolean rollback(Consumer consumer, Endpoint endpoint, int retryCounter, Exception cause) throws Exception {
consumer.getEndpoint().stop(); // 1
consumer.stop(); // 2
consumer.getEndpoint().getCamelContext().stopRoute(route???); // 3
return false;
}
你可以分享你的路线吗? –
我已经分享了路线。 –
您是否尝试添加directoryMustExist = true和startingDirectoryMustExist = true?添加它们之后,你能显示你得到的日志输出吗? –