【问题标题】:Spring Integration - Unable to send the files with same name for second timeSpring Integration - 无法第二次发送具有相同名称的文件
【发布时间】:2017-07-11 12:55:21
【问题描述】:

我可以将本地目录中的文件 Document.txt 发送到远程目录,但是如果我在远程删除文件并尝试再次从本地发送,则无法通过 FTP 传输相同的文件。轮询器工作正常,因为如果我将不同的文件放在同一个文件夹中,它就会启动。我可以对此有所了解吗?

enter code here





    <!-- Inbound adapter channels for reading the local directory files in    processed folder -->
<file:inbound-channel-adapter id="inboundProcessed"
                                channel="processedChannel" 
                                filename-pattern="*.txt"
                                directory="$dina-communication.batch-{localDirectory}"
                                                                >
    <int:poller fixed-rate="10000" />
</file:inbound-channel-adapter>

<int:channel id="processedChannel"></int:channel>

        <!-- Outbound adapter channels for FTP the files in processed folder to remote directory -->    
    <int-ftp:outbound-channel-adapter id="ftpProcessed"
                                channel="processedChannel" 
                                session-factory="ftpClientFactory"
                                remote-directory="$dina-communication.batch-{remoteDirectory}"
                                >

     <int-ftp:request-handler-advice-chain>
     <bean class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice">
        <property name="onSuccessExpression" value="payload.delete()" />
      </bean>
</int-ftp:request-handler-advice-chain>                     

    </int-ftp:outbound-channel-adapter>

【问题讨论】:

标签: ftp spring-integration


【解决方案1】:

&lt;file:inbound-channel-adapter 默认使用AcceptOnceFileListFilter,它通过路径名的hashCode 比较传入文件:

/**
 * Computes a hash code for this abstract pathname.  Because equality of
 * abstract pathnames is inherently system-dependent, so is the computation
 * of their hash codes.  On UNIX systems, the hash code of an abstract
 * pathname is equal to the exclusive <em>or</em> of the hash code
 * of its pathname string and the decimal value
 * <code>1234321</code>.  On Microsoft Windows systems, the hash
 * code is equal to the exclusive <em>or</em> of the hash code of
 * its pathname string converted to lower case and the decimal
 * value <code>1234321</code>.  Locale is not taken into account on
 * lowercasing the pathname string.
 *
 * @return  A hash code for this abstract pathname
 */
public int hashCode() {
    return fs.hashCode(this);
}

因此,当一个新文件具有相同的名称时,它会被忽略并且不能顺流而下。

要解决这个问题,您应该使用FileSystemPersistentAcceptOnceFileListFilter,它使用lastModified 来比较文件是否已更新:http://docs.spring.io/spring-integration/reference/html/files.html#file-reading

【讨论】:

  • 当然,我会尝试并保持发布!!
  • 我实际上尝试使用为出站创建另一个 FTP 客户端工厂,它解决了这个问题,因为项目中有很多 FTP'e 会话,尝试了这种方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-26
  • 2011-01-27
  • 2014-05-13
  • 1970-01-01
  • 2023-04-01
相关资源
最近更新 更多