sftpersistentacceptonfilelistfilter过滤掉新文件/修改过的文件

hl0ma9xz  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(386)

我在我的sftp出站网关上添加了SFTPersistentAcceptonFileListFilter,以筛选出我已处理的文件。

<int-sftp:outbound-gateway id="gateway"
  expression="payload"
  request-channel="request"
  remote-directory="main"
  command-options="-R"
  command="ls"
  session-factory="sessionFactory"
  filter="sftpPersistentAcceptOnceFileListFilter"
  reply-channel="reply">
</int-sftp:outbound-gateway>

 <bean name="metadataStore" class="org.springframework.integration.metadata.PropertiesPersistingMetadataStore">
    <property name="baseDirectory" value="/temp"/>
</bean>

 <bean id="sftpPersistentAcceptOnceFileListFilter" class="org.springframework.integration.sftp.filters.SftpPersistentAcceptOnceFileListFilter">
    <constructor-arg name="store" ref="metadataStore"/>
    <constructor-arg name="prefix" value="files/"/>
 </bean>

例如,我有以下目录:

main
  --directoryA
    --file1.txt
    --file2.txt
    --file3.txt

在第一次投票中,一切似乎都很顺利。检查元数据存储,文件1、文件2、文件3存储在那里。下一次轮询时,payload返回空,因为所有文件都已在存储中,并且它们都按预期由过滤器过滤掉。但是,当我尝试加载另一个文件时,它以某种方式被过滤掉,并且没有保存在元数据存储中。上传新版本的file1.txt时也会发生同样的情况。我希望它会通过过滤器,因为修改日期的变化,但不知为什么它没有。我错过一些配置了吗?

main
  --directoryA
    --file1.txt
    --file2.txt
    --file3.txt
  **--file4.txt**
ghhaqwfi

ghhaqwfi1#

我刚测试了一下,效果很好。

$ tree ~/main/
/.../main/
├── directoryA
│   ├── newOne
│   └── subdirectory1
│       └── bar
└── directoryB
    └── subdirectory1
        └── foo

4 directories, 3 files

我在第二次投票后加了一个新的:

GenericMessage [payload=[FileInfo [isDirectory=true, isLink=false, Size=96, ModifiedTime=Fri Feb 05 10:30:20 EST 2021, Filename=directoryA, RemoteDirectory=main/, Permissions=drwxr-xr-x], FileInfo [isDirectory=true, isLink=false, Size=96, ModifiedTime=Mon Feb 01 10:09:57 EST 2021, Filename=directoryA/subdirectory1, RemoteDirectory=main/, Permissions=drwxr-xr-x], FileInfo [isDirectory=false, isLink=false, Size=0, ModifiedTime=Mon Feb 01 10:09:57 EST 2021, Filename=directoryA/subdirectory1/bar, RemoteDirectory=main/, Permissions=-rw-r--r--], FileInfo [isDirectory=true, isLink=false, Size=96, ModifiedTime=Mon Feb 01 10:09:35 EST 2021, Filename=directoryB, RemoteDirectory=main/, Permissions=drwxr-xr-x], FileInfo [isDirectory=true, isLink=false, Size=96, ModifiedTime=Mon Feb 01 10:09:49 EST 2021, Filename=directoryB/subdirectory1, RemoteDirectory=main/, Permissions=drwxr-xr-x], FileInfo [isDirectory=false, isLink=false, Size=0, ModifiedTime=Mon Feb 01 10:09:49 EST 2021, Filename=directoryB/subdirectory1/foo, RemoteDirectory=main/, Permissions=-rw-r--r--]], headers={file_remoteHostPort=localhost:22, id=94154291-1640-7e9c-25a4-707844517008, file_remoteDirectory=main/, timestamp=1612539050536}]
GenericMessage [payload=[], headers={file_remoteHostPort=localhost:22, id=931d9c2d-6e09-7435-dc61-caa95f6659b5, file_remoteDirectory=main/, timestamp=1612539060927}]
GenericMessage [payload=[FileInfo [isDirectory=true, isLink=false, Size=128, ModifiedTime=Fri Feb 05 10:31:06 EST 2021, Filename=directoryA, RemoteDirectory=main/, Permissions=drwxr-xr-x], FileInfo [isDirectory=false, isLink=false, Size=0, ModifiedTime=Fri Feb 05 10:31:06 EST 2021, Filename=directoryA/newOne, RemoteDirectory=main/, Permissions=-rw-r--r--]], headers={file_remoteHostPort=localhost:22, id=ebee7a69-c351-7ca7-010d-e90937d61dfa, file_remoteDirectory=main/, timestamp=1612539071380}]
GenericMessage [payload=[], headers={file_remoteHostPort=localhost:22, id=097dae97-16d6-b8c4-62bb-d5581a27824e, file_remoteDirectory=main/, timestamp=1612539081806}]

但是,我注意到,我们只存储文件名,而不存储子目录,因此如果在多个位置有相同的文件名,它将无法按预期工作。
我为此提出了一个问题。
顺便说一句,您应该使用一个更健壮的元数据存储来进行生产(或者至少 filter.setFlushOnUpdate(true); 在过滤器上;否则,在应用程序完全关闭之前,它们不会被持久化)。
编辑
哦,但我发现这个没人接。。。

$ touch ~/main/directoryA/subdirectory1/andAnother

调查。
编辑2
问题是我们正在过滤子目录;当我加上 newOne 成功是因为 directoryA 的时间戳已更改。当我加上 andAnother ,子目录时间戳已更改,但 directoryA 他没有。
以下是解决方法:

SftpPersistentAcceptOnceFileListFilter filter = new SftpPersistentAcceptOnceFileListFilter(store, "foo") {

    @Override
    public boolean accept(LsEntry file) {
        if (file.getAttrs().isDir()) {
            return true;
        }
        else {
            return super.accept(file);
        }
    }

};
GenericMessage [payload=[FileInfo [isDirectory=false, isLink=false, Size=0, ModifiedTime=Fri Feb 05 10:31:06 EST 2021, Filename=directoryA/newOne, RemoteDirectory=main/, Permissions=-rw-r--r--], FileInfo [isDirectory=false, isLink=false, Size=0, ModifiedTime=Mon Feb 01 10:09:57 EST 2021, Filename=directoryA/subdirectory1/bar, RemoteDirectory=main/, Permissions=-rw-r--r--], FileInfo [isDirectory=false, isLink=false, Size=0, ModifiedTime=Mon Feb 01 10:09:49 EST 2021, Filename=directoryB/subdirectory1/foo, RemoteDirectory=main/, Permissions=-rw-r--r--]], headers={file_remoteHostPort=localhost:22, id=50faae38-5965-8655-102c-b263398e435b, file_remoteDirectory=main/, timestamp=1612541209839}]
GenericMessage [payload=[], headers={file_remoteHostPort=localhost:22, id=36cedd79-80e1-0c73-ba09-205528dccfca, file_remoteDirectory=main/, timestamp=1612541220313}]
GenericMessage [payload=[], headers={file_remoteHostPort=localhost:22, id=6a0826b4-f960-8b5b-a14e-1c205ca4f357, file_remoteDirectory=main/, timestamp=1612541230803}]
GenericMessage [payload=[FileInfo [isDirectory=false, isLink=false, Size=0, ModifiedTime=Fri Feb 05 11:07:11 EST 2021, Filename=directoryA/subdirectory1/andAnother, RemoteDirectory=main/, Permissions=-rw-r--r--]], headers={file_remoteHostPort=localhost:22, id=dcd9b6a4-5710-421c-1864-17b166d47a5a, file_remoteDirectory=main/, timestamp=1612541241217}]
GenericMessage [payload=[], headers={file_remoteHostPort=localhost:22, id=3eb67995-9ca1-6b8a-d9bd-02cd6d9ea894, file_remoteDirectory=main/, timestamp=1612541251695}]

相关问题