我有一个文档服务器应用程序。对于从ftp文件夹中拾取并放入本地目录的文件,可以使用单独的流。第二个流程用于拾取文件并将其放入FTP位置。我为自己和自定义模式匹配器添加了一个AcceptOnceFileListFilter,在两种情况下都是相同的(某些东西)。本地目录以及ftp文件夹与此不同。
我需要在拾取后让源文件存在,因此我删除了deletesourcefiles属性。
有了这个,我面临着重复进入过滤器并进行处理的文件问题。如何使用AcceptOnceFileListFilter实现这一点?我无论如何都需要避免重复处理相同的文件。
这是我的整个配置。
<bean id="fileNameGenerator" class="com.polling.util.FileNameGenerator"/>
<int-file:inbound-channel-adapter id="filesIn" directory="file:${paths.root}" channel="abc" filter="compositeFilter" prevent-duplicates="true" >
<int:poller id="poller" fixed-rate="500" error-channel="errorChannel" />
</int-file:inbound-channel-adapter>
<int:service-activator input-channel="errorChannel" ref="errorLogger" method="logError"/>
<bean id="errorLogger" class="com.polling.util.ErrorLogger" />
<int:channel id="abc"/>
<bean id="compositeFilter" class="org.springframework.integration.file.filters.CompositeFileListFilter">
<constructor-arg>
<list>
<!-- Ensures that the file is whole before processing it -->
<bean class="org.springframework.integration.file.filters.AcceptOnceFileListFilter" />
<bean class="com.polling.util.CustomFileFilter"/>
<!-- Ensures files are picked up only once from the directory -->
</list>
</constructor-arg>
</bean>
<int-file:outbound-channel-adapter channel="abc" id="filesOut"
directory-expression="@outPathBean.getPath()"
delete-source-files="true" filename-generator="fileNameGenerator" temporary-file-suffix=".writinginprog">
<int-file:request-handler-advice-chain>
<bean class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice">
<property name="onSuccessExpression" value="payload.delete()" />
</bean>
</int-file:request-handler-advice-chain>
</int-file:outbound-channel-adapter>
<bean id="ftpClientFactory"
class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
<property name="host" value="${ftp.ip}"/>
<property name="port" value="${ftp.port}"/>
<property name="username" value="${ftp.username}"/>
<property name="password" value="${ftp.password}"/>
<property name="clientMode" value="0"/>
<property name="fileType" value="2"/>
<property name="bufferSize" value="100000"/>
</bean>
<int:channel id="ftpChannel1"/>
<int-ftp:inbound-channel-adapter id="ftpInbound1"
channel="ftpChannel1"
session-factory="ftpClientFactory"
charset="UTF-8"
local-directory="file:${paths.downloadroot}"
delete-remote-files="true"
temporary-file-suffix=".write"
remote-directory="."
preserve-timestamp="true"
auto-startup="true"
local-filter="compositeFilterLocal"
>
<int:poller fixed-rate="1000" error-channel="errorChannel"/>
</int-ftp:inbound-channel-adapter>
<int-ftp:outbound-channel-adapter id="ftpOutbound1"
channel="ftpChannel1"
session-factory="ftpClientFactory"
charset="UTF-8"
remote-file-separator="/"
auto-create-directory="true"
remote-directory="${file.ftpdownloadfolder}"
use-temporary-file-name="true"
temporary-file-suffix=".write">
<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>
<int:channel id="ftpChannel"/>
<!--filter="compositeFilterRemote" filename-pattern="*~*" filename-pattern="*~*"-->
<int-ftp:inbound-channel-adapter id="ftpInbound"
channel="ftpChannel"
session-factory="ftpClientFactory"
charset="UTF-8"
local-directory="file:${paths.root}"
filter="compositeFilterRemote"
temporary-file-suffix=".writing"
remote-directory="${file.ftpfolder}"
delete-remote-files="true"
preserve-timestamp="true"
auto-startup="true">
<int:poller fixed-rate="1000" error-channel="errorChannel"/>
</int-ftp:inbound-channel-adapter>
<int-ftp:outbound-channel-adapter id="ftpOutbound"
channel="ftpChannel"
session-factory="ftpClientFactory"
charset="UTF-8"
remote-file-separator="/"
auto-create-directory="true"
remote-directory="${file.ftpfolder}"
use-temporary-file-name="true"
temporary-file-suffix=".writing">
<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>
<bean id="compositeFilterLocal" class="org.springframework.integration.file.filters.CompositeFileListFilter">
<constructor-arg>
<list>
<!-- Ensures that the file is whole before processing it -->
<bean class="org.springframework.integration.file.filters.AcceptAllFileListFilter" />
<bean class="com.polling.util.CustomFileFilterLocal"/>
<!-- Ensures files are picked up only once from the directory -->
</list>
</constructor-arg>
</bean>
<bean id="compositeFilterRemote" class="org.springframework.integration.file.filters.CompositeFileListFilter">
<constructor-arg>
<list>
<!-- Ensures that the file is whole before processing it -->
<bean class="org.springframework.integration.file.filters.AcceptAllFileListFilter" />
<bean class="com.polling.util.CustomFileFilterRemote"/>
<!-- Ensures files are picked up only once from the directory -->
</list>
</constructor-arg>
</bean>
编辑:
将配置从固定速率更改为固定延迟。我不记得为什么我上个月把它改成了固定费率!无论如何,到目前为止解决了大文件问题。但是,acceptoncefilter仍然没有完成它的工作。文件入站适配器拾取后,不会从本地目录中删除该文件。
还有另一个问题。有两个ftp通道具有不同的远程文件夹和不同的本地文件夹。我希望每个人都是单向的。意味着一个人应该从远程目录中获取文件并将其放在本地文件中,另一个应该反之亦然。由于上述问题,文件仍然在本地目录中,并被其他流程接收并放回远程目录!也不能使其中一个dir无效。请指导我,因为必须不删除远程目录上的文件。