Spring 如何使用驼峰sftp下载文件
我必须做的是:外部服务器定期生成3个文件:“FI.date.nnnnn”、“FS.date.nnnnn”和GO.date.nnnnn”。这3个文件与相同的日期和nnnnn(=序列号)相关联。每个“三元组”都是唯一的名称。当GO文件存在时,我必须下载这些文件。此GO文件为空 我使用驼峰路线:Spring 如何使用驼峰sftp下载文件,spring,apache-camel,Spring,Apache Camel,我必须做的是:外部服务器定期生成3个文件:“FI.date.nnnnn”、“FS.date.nnnnn”和GO.date.nnnnn”。这3个文件与相同的日期和nnnnn(=序列号)相关联。每个“三元组”都是唯一的名称。当GO文件存在时,我必须下载这些文件。此GO文件为空 我使用驼峰路线: from("sftp://user@url:port/OUTTEST-S?binary=true&connectTimeout=3000&delete=true&disconnect=
from("sftp://user@url:port/OUTTEST-S?binary=true&connectTimeout=3000&delete=true&disconnect=true&include=GO.*&knownHostsFile=.ssh/known_hosts&privateKeyFile=../id_rsa.ppk&stepwise=false&strictHostKeyChecking=no&timeout=3000).bean(afterReceiveGo).to("...")
我使用“include=GO.*”等待GO文件
在我的AfterReceiveGo中,我使用这样的ConsumerTemplate:
consumerTemplate.receiveBody(sftp://user@url:port/OUTTEST-S?binary=true&connectTimeout=3000&delete=true&disconnect=true&fileName=FO.20160810.00089&knownHostsFile=.ssh/known_hosts&privateKeyFile=../id_rsa.ppk&stepwise=false&strictHostKeyChecking=no&timeout=3000&useList=false, File.class)
因为我知道要下载的文件名,所以使用“fileName=”和useList=false”
但在日志中:
Will try again at next poll. Caused by: [org.apache.camel.component.file.GenericFileOperationFailedException - Cannot list directory: OUTTEST-S]: org.apache.camel.component.file.GenericFileOperationFailedException: Cannot list directory: OUTTEST-S
at org.apache.camel.component.file.remote.SftpOperations.listFiles(SftpOperations.java:617)
at org.apache.camel.component.file.remote.SftpConsumer.doPollDirectory(SftpConsumer.java:117)
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(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: 4:
at com.jcraft.jsch.ChannelSftp._stat(ChannelSftp.java:2208)
at com.jcraft.jsch.ChannelSftp._stat(ChannelSftp.java:2215)
at com.jcraft.jsch.ChannelSftp.ls(ChannelSftp.java:1565)
at com.jcraft.jsch.ChannelSftp.ls(ChannelSftp.java:1526)
at org.apache.camel.component.file.remote.SftpOperations.listFiles(SftpOperations.java:608)
... 12 more
Caused by: java.io.IOException: inputstream is closed
at com.jcraft.jsch.ChannelSftp.fill(ChannelSftp.java:2884)
at com.jcraft.jsch.ChannelSftp.header(ChannelSftp.java:2908)
at com.jcraft.jsch.ChannelSftp._stat(ChannelSftp.java:2189)
... 16 more
我使用Camel 2.17.2,所有的都是java配置,没有xml文件
怎么了?还有其他(也是最好的)方法吗
第二个问题:我想使用带有from(“sftp…”)的cron表达式每一小时执行一次,即我不能使用“?scheduler=spring&scheduler.cron=…”(或quartz2),因为我在部署中有错误(未找到构造函数)。因此,我使用:
cronScheduledRoutePolicy.startTime("cron expression");
from("sftp...").routePolicy(cronScheduledRoutePolicy).bean("...").to("...");
但我在日志文件中每秒都会看到一个连接。我能做什么?Camel的sftp组件具有定义自己的极化间隔的选项。无需配置/添加计划程序。以下是从中引用的两个选项 initialDelay:开始轮询文件/目录前的毫秒数。
延迟:在下一次轮询文件/目录之前的毫秒。Camel的sftp组件具有定义自己的轮询间隔的选项。无需配置/添加计划程序。以下是从中引用的两个选项 initialDelay:开始轮询文件/目录前的毫秒数。 延迟:文件/目录下一次轮询前的毫秒