重试 SFTP 权限错误
Retry on SFTP Permission errors
我正在维护现有的 Spring 集成应用程序,该应用程序正在轮询第三方 SFTP 服务器以获取文件。它偶尔会抛出权限或 'not found' 错误,我怀疑这是由远程端的瞬态问题引起的。我希望应用程序重试获取这些错误,因为它可能会解决问题。 (我也有一个要求"retry on any problems",应该涵盖这种情况。)
例如
org.springframework.messaging.MessagingException: Problem occurred while synchronizing remote to local directory; nested exception is org.springframework.messaging.MessagingException: Failure occurred while copying from remote to local directory; nested exception is org.springframework.core.NestedIOException: failed to read file mypath/myfile.csv; nested exception is 3: Permission denied
at [snip]
Caused by: org.springframework.messaging.MessagingException: Failure occurred while copying from remote to local directory; nested exception is org.springframework.core.NestedIOException: failed to read file mypath/myfile.csv; nested exception is 3: Permission denied
at [snip]
Caused by: 3: Permission denied
at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2846) [snip]
经过广泛的谷歌搜索和兜兜转转后,我仍然无法弄清楚如何使用 Spring 集成来做到这一点。这是现有配置:
<bean id="myAcceptOnceFilter" class="org.springframework.integration.sftp.filters.SftpPersistentAcceptOnceFileListFilter">
<constructor-arg index="0" ref="myLocalFileStore"/>
<constructor-arg index="1" name="prefix" value="myprefix_"/>
<property name="flushOnUpdate" value="true"/>
</bean>
<bean id="myCompositeFilter" class="org.springframework.integration.file.filters.CompositeFileListFilter">
<constructor-arg>
<list>
<bean class="org.springframework.integration.sftp.filters.SftpSimplePatternFileListFilter">
<constructor-arg value="myprefix" />
</bean>
<ref bean="myAcceptOnceFilter"/>
</list>
</constructor-arg>
</bean>
<int-sftp:inbound-channel-adapter id="myInboundChannel"
session-factory="mySftpSessionFactory"
channel="myDownstreamChannel"
remote-directory="blah"
filter="myCompositeFilter"
local-directory="blah"
auto-create-local-directory="true"
>
<int:poller fixed-rate="10000" max-messages-per-poll="-1">
<int:transactional transaction-manager="transactionManager" synchronization-factory="syncFactory" />
</int:poller>
</int-sftp:inbound-channel-adapter>
编辑:我认为问题出在 myCompositeFilter 上。抛出异常时,看起来不像是在 myAcceptOnceFilter 内部调用了 rollback()。如果我只是使用 myAcceptOnceFilter 而没有复合,那么代码将按预期工作(即调用 rollback() )。现在的问题是:如何继续使用 CompositeFilter,它会在其所有子项上调用回滚?
我研究过在轮询器中放置一个重试适配器(编辑:我现在知道这是无关紧要的):
<bean id="retryAdvice" class="org.springframework.integration.handler.advice.RequestHandlerRetryAdvice"/>
<int:poller fixed-rate="10000" max-messages-per-poll="-1">
<int:advice-chain>
<tx:advice transaction-manager="transactionManager"/>
<int:ref bean="retryAdvice"/>
</int:advice-chain>
</int:poller>
...但这会引发警告
This advice org.springframework.integration.handler.advice.RequestHandlerRetryAdvice can only be used for MessageHandlers
简而言之,我卡住了。非常感谢收到有关让它重试这种 sftp 异常的任何帮助。谢谢!
编辑:在提及 SftpPersistentAcceptOnceFileListFilter 时添加。
编辑:添加了对 CompositeFileLIstFilter 的讨论,现在看起来像是问题所在。
重试建议用于使用端点(推送重试)。
不清楚为什么需要在此处添加重试 - 轮询器将在下一次轮询时自动重试。
我正在维护现有的 Spring 集成应用程序,该应用程序正在轮询第三方 SFTP 服务器以获取文件。它偶尔会抛出权限或 'not found' 错误,我怀疑这是由远程端的瞬态问题引起的。我希望应用程序重试获取这些错误,因为它可能会解决问题。 (我也有一个要求"retry on any problems",应该涵盖这种情况。)
例如
org.springframework.messaging.MessagingException: Problem occurred while synchronizing remote to local directory; nested exception is org.springframework.messaging.MessagingException: Failure occurred while copying from remote to local directory; nested exception is org.springframework.core.NestedIOException: failed to read file mypath/myfile.csv; nested exception is 3: Permission denied
at [snip]
Caused by: org.springframework.messaging.MessagingException: Failure occurred while copying from remote to local directory; nested exception is org.springframework.core.NestedIOException: failed to read file mypath/myfile.csv; nested exception is 3: Permission denied
at [snip]
Caused by: 3: Permission denied
at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2846) [snip]
经过广泛的谷歌搜索和兜兜转转后,我仍然无法弄清楚如何使用 Spring 集成来做到这一点。这是现有配置:
<bean id="myAcceptOnceFilter" class="org.springframework.integration.sftp.filters.SftpPersistentAcceptOnceFileListFilter">
<constructor-arg index="0" ref="myLocalFileStore"/>
<constructor-arg index="1" name="prefix" value="myprefix_"/>
<property name="flushOnUpdate" value="true"/>
</bean>
<bean id="myCompositeFilter" class="org.springframework.integration.file.filters.CompositeFileListFilter">
<constructor-arg>
<list>
<bean class="org.springframework.integration.sftp.filters.SftpSimplePatternFileListFilter">
<constructor-arg value="myprefix" />
</bean>
<ref bean="myAcceptOnceFilter"/>
</list>
</constructor-arg>
</bean>
<int-sftp:inbound-channel-adapter id="myInboundChannel"
session-factory="mySftpSessionFactory"
channel="myDownstreamChannel"
remote-directory="blah"
filter="myCompositeFilter"
local-directory="blah"
auto-create-local-directory="true"
>
<int:poller fixed-rate="10000" max-messages-per-poll="-1">
<int:transactional transaction-manager="transactionManager" synchronization-factory="syncFactory" />
</int:poller>
</int-sftp:inbound-channel-adapter>
编辑:我认为问题出在 myCompositeFilter 上。抛出异常时,看起来不像是在 myAcceptOnceFilter 内部调用了 rollback()。如果我只是使用 myAcceptOnceFilter 而没有复合,那么代码将按预期工作(即调用 rollback() )。现在的问题是:如何继续使用 CompositeFilter,它会在其所有子项上调用回滚?
我研究过在轮询器中放置一个重试适配器(编辑:我现在知道这是无关紧要的):
<bean id="retryAdvice" class="org.springframework.integration.handler.advice.RequestHandlerRetryAdvice"/>
<int:poller fixed-rate="10000" max-messages-per-poll="-1">
<int:advice-chain>
<tx:advice transaction-manager="transactionManager"/>
<int:ref bean="retryAdvice"/>
</int:advice-chain>
</int:poller>
...但这会引发警告
This advice org.springframework.integration.handler.advice.RequestHandlerRetryAdvice can only be used for MessageHandlers
简而言之,我卡住了。非常感谢收到有关让它重试这种 sftp 异常的任何帮助。谢谢!
编辑:在提及 SftpPersistentAcceptOnceFileListFilter 时添加。 编辑:添加了对 CompositeFileLIstFilter 的讨论,现在看起来像是问题所在。
重试建议用于使用端点(推送重试)。
不清楚为什么需要在此处添加重试 - 轮询器将在下一次轮询时自动重试。