我试图使用spring集成来将不同目录中的一些文件sftp发送到我的本地目录。
现在我可以抓住我需要的3个文件,但应用程序永远不会结束,它似乎在事务循环中不断被卡住。我想我需要关闭轮询器,尽管这是猜测。我出错的任何想法?
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:int="http://www.springframework.org/schema/integration" xmlns:int-sftp="http://www.springframework.org/schema/integration/sftp" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/integration ttp://www.springframework.org/schema/integration/spring-integration.xsd http://www.springframework.org/schema/integration/sftp http://www.springframework.org/schema/integration/sftp/spring-integration-sftp.xsd">
<bean id="sftpDownloader" class="SftpDownloader" p:SftpChannel-ref="SftpChannel" p:SftpChannel1-ref="SftpChannel1" p:SftpChannel2-ref="SftpChannel2"/>
<int:channel id="SftpChannel">
<int:queue/>
</int:channel>
<int:channel id="SftpChannel1">
<int:queue/>
</int:channel>
<int:channel id="SftpChannel2">
<int:queue/>
</int:channel>
<bean id="sftpSessionFactory" class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory">
<property name="host" value="${sftp.host}"/>
<property name="user" value="${sftp.user}"/>
<property name="port" value="${sftp.port}"/>
<property name="privateKey" value="${sftp.privateKey}"/>
<property name="proxy" ref="httpProxy"/>
</bean>
<!---->
<bean id="httpProxy" class=" com.jcraft.jsch.ProxySOCKS4">
<constructor-arg index="0" value="${proxyHost}"/>
<constructor-arg index="1" value="${proxyPort}"/>
</bean>
<int-sftp:inbound-channel-adapter id="sftpInboundAdaptor" session-factory="sftpSessionFactory" local-directory="${local.dir}" auto-create-local-directory="true" auto-startup="false" channel="SftpChannel" remote-directory="${remote.dir}" filename-pattern="file1" delete-remote-files="false" charset="UTF-8" remote-file-separator="/" local-filename-generator-expression="#this">
<int:poller max-messages-per-poll="1" fixed-rate="30000"/>
</int-sftp:inbound-channel-adapter>
<int-sftp:inbound-channel-adapter id="1SftpInboundAdaptor" session-factory="sftpSessionFactory" local-directory="${local.dir}" auto-create-local-directory="true" auto-startup="false" channel="SftpChannel1" remote-directory="${1.remote.dir}" filename-pattern="file2" delete-remote-files="false" charset="UTF-8" remote-file-separator="/" local-filename-generator-expression="#this">
<int:poller max-messages-per-poll="1" fixed-rate="30000"/>
</int-sftp:inbound-channel-adapter>
<int-sftp:inbound-channel-adapter id="2SftpInboundAdaptor" session-factory="sftpSessionFactory" local-directory="${2.local.dir}" auto-create-local-directory="true" auto-startup="false" channel="SftpChannel2" remote-directory="${2.remote.dir}" filename-pattern="file3" delete-remote-files="false" charset="UTF-8" remote-file-separator="/" local-filename-generator-expression="#this">
<int:poller max-messages-per-poll="1" fixed-rate="30000"/>
</int-sftp:inbound-channel-adapter>
<bean id="fileNameGenerator" class="org.springframework.integration.file.DefaultFileNameGenerator"/>
</beans>
下面的代码片段来自同一个远程目录的2个不同文件。这是获取文件
后陷入循环的地方private static void sftpFiles(String party) throws Exception {
SourcePollingChannelAdapter 1Adapter = (SourcePollingChannelAdapter) applicationContext
.getBean("1SftpInboundAdaptor");
SourcePollingChannelAdapter 2Adapter = (SourcePollingChannelAdapter) applicationContext
.getBean("2SftpInboundAdaptor");
if (party.equals(Constants.1)) {
1Adapter.start();
} else if (party.equals(Constants.2)){
2Adapter.start();
}
SftpDownloader sftpProcessor = (SftpDownloader) applicationContext.getBean("sftpDownloader");
boolean fileDownloaded = sftpProcessor.receiveFile(party, "");
LOGGER.info((fileDownloaded ? "Successful" : "Failed") + " downloading file);
applicationContext.stop();
}
此代码段工作正常(sftps 1文件,不同的远程目录,并成功结束)
private static void sftpFile(String party) throws Exception {
SourcePollingChannelAdapter adapter = (SourcePollingChannelAdapter) applicationContext.getBean("sftpInboundAdaptor");
adapter.start();
SftpDownloader sftpProcessor = (SftpDownloader) applicationContext.getBean("sftpDownloader");
boolean fileDownloaded = sftpProcessor.receiveFile(party, "");
LOGGER.info((fileDownloaded ? "Successful" : "Failed") + " downloading);
}
sftpdownloader类只是检查消息的大小,告诉作业是否失败(如果文件大小为0)
正如我所说,它的工作原理是它会下载每个文件,但是当它尝试执行1/2时,会遇到以下不断循环的问题。
错误DEBUG 2017-07-12T06:51:10,686 [jmsContainer-4] [[]] org.springframework.transaction.jta.JtaTransactionManager - 启动 交易提交DEBUG 2017-07-12T06:51:10,687 [jmsContainer-2]
[[]] org.springframework.transaction.jta.JtaTransactionManager - 启动交易提交DEBUG 2017-07-12T06:51:10,687 [jmsContainer-7] [[]] org.springframework.transaction.jta.JtaTransactionManager - 启动 交易提交DEBUG 2017-07-12T06:51:10,719 [jmsContainer-7]
[[]] org.springframework.transaction.jta.JtaTransactionManager - 使用名称[jmsContainer]创建新事务: PROPAGATION_REQUIRED,ISOLATION_DEFAULT DEBUG 2017-07-12T06:51:10,719 [jmsContainer-4] [[]] org.springframework.transaction.jta.JtaTransactionManager - 创建 名为[jmsContainer]的新事务: PROPAGATION_REQUIRED,ISOLATION_DEFAULT DEBUG 2017-07-12T06:51:10,719 [jmsContainer-2] [[]] org.springframework.transaction.jta.JtaTransactionManager - 创建 名为[jmsContainer]的新事务: PROPAGATION_REQUIRED,ISOLATION_DEFAULT DEBUG 2017-07-12T06:51:10,839 [jmsContainer-9] [[]] org.springframework.transaction.jta.JtaTransactionManager - 启动 交易提交DEBUG 2017-07-12T06:51:10,839 [jmsContainer-6]
[[]] org.springframework.transaction.jta.JtaTransactionManager - 启动交易提交DEBUG 2017-07-12T06:51:10,839 [jmsContainer-5] [[]] org.springframework.transaction.jta.JtaTransactionManager - 启动 交易提交DEBUG 2017-07-12T06:51:10,839 [jmsContainer-1]
[[]] org.springframework.transaction.jta.JtaTransactionManager - 启动交易提交DEBUG 2017-07-12T06:51:10,845 [jmsContainer-1] [[]] org.springframework.transaction.jta.JtaTransactionManager - 创建 名为[jmsContainer]的新事务: PROPAGATION_REQUIRED,ISOLATION_DEFAULT DEBUG 2017-07-12T06:51:10,845 [jmsContainer-5] [[]] org.springframework.transaction.jta.JtaTransactionManager - 创建 名为[jmsContainer]的新事务: PROPAGATION_REQUIRED,ISOLATION_DEFAULT DEBUG 2017-07-12T06:51:10,846 [jmsContainer-9] [[]] org.springframework.transaction.jta.JtaTransactionManager - 创建 名为[jmsContainer]的新事务: PROPAGATION_REQUIRED,ISOLATION_DEFAULT DEBUG 2017-07-12T06:51:10,846 [jmsContainer-6] [[]] org.springframework.transaction.jta.JtaTransactionManager - 创建 名为[jmsContainer]的新事务: PROPAGATION_REQUIRED,ISOLATION_DEFAULT DEBUG 2017-07-12T06:51:11,161 [jmsContainer-3] [[]] org.springframework.transaction.jta.JtaTransactionManager - 启动 交易提交DEBUG 2017-07-12T06:51:11,161 [jmsContainer-8]
[[]] org.springframework.transaction.jta.JtaTransactionManager - 启动交易提交DEBUG 2017-07-12T06:51:11,161 [jmsContainer-10] [[]] org.springframework.transaction.jta.JtaTransactionManager - 启动 交易提交DEBUG 2017-07-12T06:51:11,169 [jmsContainer-8]
[[]] org.springframework.transaction.jta.JtaTransactionManager - 使用名称[jmsContainer]创建新事务: PROPAGATION_REQUIRED,ISOLATION_DEFAULT DEBUG 2017-07-12T06:51:11,169 [jmsContainer-3] [[]] org.springframework.transaction.jta.JtaTransactionManager - 创建 名为[jmsContainer]的新事务: PROPAGATION_REQUIRED,ISOLATION_DEFAULT DEBUG 2017-07-12T06:51:11,169 [jmsContainer-10] [[]] org.springframework.transaction.jta.JtaTransactionManager - 创建 名为[jmsContainer]的新事务: PROPAGATION_REQUIRED,ISOLATION_DEFAULT DEBUG 2017-07-12T06:51:11,721 [jmsContainer-7] [[]] org.springframework.transaction.jta.JtaTransactionManager - 启动 交易提交DEBUG 2017-07-12T06:51:11,721 [jmsContainer-4]
[[]] org.springframework.transaction.jta.JtaTransactionManager - 启动交易提交DEBUG 2017-07-12T06:51:11,721 [jmsContainer-2] [[]] org.springframework.transaction.jta.JtaTransactionManager - 启动 交易提交DEBUG 2017-07-12T06:51:11,726 [jmsContainer-7]
[[]] org.springframework.transaction.jta.JtaTransactionManager - 使用名称[jmsContainer]创建新事务: PROPAGATION_REQUIRED,ISOLATION_DEFAULT DEBUG 2017-07-12T06:51:11,726 [jmsContainer-2] [[]] org.springframework.transaction.jta.JtaTransactionManager - 创建 名为[jmsContainer]的新事务: PROPAGATION_REQUIRED,ISOLATION_DEFAULT DEBUG 2017-07-12T06:51:11,727 [jmsContainer-4] [[]] org.springframework.transaction.jta.JtaTransactionManager - 创建 名为[jmsContainer]的新事务: PROPAGATION_REQUIRED,ISOLATION_DEFAULT DEBUG 2017-07-12T06:51:11,847 [jmsContainer-1] [[]] org.springframework.transaction.jta.JtaTransactionManager - 启动 交易提交DEBUG 2017-07-12T06:51:11,848 [jmsContainer-5]
[[]] org.springframework.transaction.jta.JtaTransactionManager - 启动交易提交DEBUG 2017-07-12T06:51:11,848 [jmsContainer-9] [[]] org.springframework.transaction.jta.JtaTransactionManager - 启动 交易提交DEBUG 2017-07-12T06:51:11,848 [jmsContainer-6]
[[]] org.springframework.transaction.jta.JtaTransactionManager - 启动交易提交DEBUG 2017-07-12T06:51:11,863 [jmsContainer-9] [[]] org.springframework.transaction.jta.JtaTransactionManager - 创建 名为[jmsContainer]的新事务: PROPAGATION_REQUIRED,ISOLATION_DEFAULT DEBUG 2017-07-12T06:51:11,864 [jmsContainer-6] [[]] org.springframework.transaction.jta.JtaTransactionManager - 创建 名为[jmsContainer]的新事务: PROPAGATION_REQUIRED,ISOLATION_DEFAULT DEBUG 2017-07-12T06:51:11,864 [jmsContainer-1] [[]] org.springframework.transaction.jta.JtaTransactionManager - 创建 名为[jmsContainer]的新事务: PROPAGATION_REQUIRED,ISOLATION_DEFAULT DEBUG 2017-07-12T06:51:11,864 [jmsContainer-5] [[]] org.springframework.transaction.jta.JtaTransactionManager - 创建 名为[jmsContainer]的新事务: PROPAGATION_REQUIRED,ISOLATION_DEFAULT DEBUG 2017-07-12T06:51:11,918 [EES空闲连接监视器线程] [[]] org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager - 关闭 过期连接DEBUG 2017-07-12T06:51:11,918 [EES空闲连接 监控线程] [[]] org.apache.http.impl.conn.tsccm.ConnPoolByRoute - 关闭过期的连接DEBUG 2017-07-12T06:51:11,918 [EES空闲连接监视器线程] [[]] org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager - 关闭 连接空闲时间超过5秒SECUBDS DEBUG 2017-07-12T06:51:11,918 [EES空闲连接监视器线程] [[]] org.apache.http.impl.conn.tsccm.ConnPoolByRoute - 关闭连接 闲置时间超过5秒SECUBDS DEBUG 2017-07-12T06:51:12,171 [jmsContainer-8] [[]] org.springframework.transaction.jta.JtaTransactionManager - 启动 交易提交DEBUG 2017-07-12T06:51:12,171 [jmsContainer-10]
[[]] org.springframework.transaction.jta.JtaTransactionManager - 启动交易提交DEBUG 2017-07-12T06:51:12,171 [jmsContainer-3] [[]] org.springframework.transaction.jta.JtaTransactionManager - 启动 交易提交DEBUG 2017-07-12T06:51:12,177 [jmsContainer-8]
[[]] org.springframework.transaction.jta.JtaTransactionManager - 使用名称[jmsContainer]创建新事务: PROPAGATION_REQUIRED,ISOLATION_DEFAULT DEBUG 2017-07-12T06:51:12,177 [jmsContainer-10] [[]] org.springframework.transaction.jta.JtaTransactionManager - 创建 名为[jmsContainer]的新事务: PROPAGATION_REQUIRED,ISOLATION_DEFAULT DEBUG 2017-07-12T06:51:12,177 [jmsContainer-3] [[]] org.springframework.transaction.jta.JtaTransactionManager - 创建 名为[jmsContainer]的新事务: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
这些作为3个单独的作业运行,因此我的bashscript将选择要运行的作业,这反过来决定了我需要接收的文件。所以我得到了所有3个作业的文件,但找到文件2或3的作业将达到上述循环。
任何帮助都将不胜感激。