2

我正在维护一个现有的 Spring Integration 应用程序,该应用程序正在轮询第三方 SFTP 服务器以获取文件。它偶尔会抛出权限或“未找到”错误,我怀疑这是由远程端的暂时性问题引起的。我希望应用程序重试获取这些错误,因为它可能会解决问题。(我还要求“重试任何问题”,这应该涵盖这种情况。)

例如

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 Integration 做到这一点。这是现有的配置:

<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 的讨论,现在看起来像是问题的位置。

4

1 回答 1

1

重试建议用于使用端点(推送重试)。

目前尚不清楚为什么需要在此处添加重试 - 轮询器将在下一次轮询时重试。

于 2016-05-10T12:33:02.740 回答