Spring 集成元数据存储

Jes*_*gui 4 spring-integration

我在 spring boot + spring 集成应用程序中添加了一个名为 metadataStore 的 bean,并希望即使在服务器重新启动后,ftp 同步也会保持不变。尽管如此,我的早期测试表明并非如此。如果我启动服务器并让它拾取并处理 3 个测试文件,然后重新启动服务器,那么将再次拾取和处理这 3 个相同的文件 - 就好像根本没有定义持久性 metadataStore 一样。

我想知道我在设置数据存储时是否遗漏了一些配置细节......

@Configuration
public class MetadataStoreConfiguration {

    @Bean
    public PropertiesPersistingMetadataStore metadataStore() {
        PropertiesPersistingMetadataStore metadataStore = new PropertiesPersistingMetadataStore();
        return metadataStore;
    }
}
Run Code Online (Sandbox Code Playgroud)

另外,我在 spring-integration 参考手册中看到了一个关于如何设置幂等接收器和元数据存储的简短示例。这是我的实现所缺乏的吗?

如果是这样,如果我必须像示例中那样设置它,我应该在哪里定义我的 metadataStore.get 和 metadataStore.put 调用?我正在使用的出站适配器没有为我提供表达式属性......这是我在这方面的幼稚和不完整的尝试:

<int-file:inbound-channel-adapter id="inboundLogFile"
                                  auto-create-directory="true"
                                  directory="${sftp.local.dir}"
                                  channel="fileInboundChannel"
                                  prevent-duplicates="true">
    <int:poller fixed-rate="${setup.inbound.poller.rate}"/>
</int-file:inbound-channel-adapter>


<int:filter id="fileFilter" input-channel="fileInboundChannel"
                output-channel="idempotentServiceChannel"
                discard-channel="fileDiscardChannel"
                expression="@metadataStore.get(payload.name) == null"/>
Run Code Online (Sandbox Code Playgroud)

这是示例中使用的出站适配器:

<int:outbound-channel-adapter channel="idempotentServiceChannel" expression="@metadataStore.put(payload.name, '')"/>
Run Code Online (Sandbox Code Playgroud)

在我的 ftp 出站适配器中,我无法插入上述表达式 :(

<int-ftp:outbound-channel-adapter id="sdkOutboundFtp"
                                      channel="idempotentServiceChannel"
                                      session-factory="ftpsCachingSessionFactory"
                                      charset="UTF-8"
                                      auto-create-directory="true"
                                      use-temporary-file-name="false"
                                      remote-file-separator="/"
                                      remote-directory-expression="${egnyte.remote.dir}"
                                      * NO EXPRESSION POSSIBLE HERE *
                                      mode="REPLACE">
    </int-ftp:outbound-channel-adapter>
Run Code Online (Sandbox Code Playgroud)

Gar*_*ell 5

默认情况下,PropertiesPersistingMetadataStore只有在正常的应用程序关闭时才会保持状态;在此之前它一直保存在内存中。

在 4.1.2 中,我们将其更改为实现,Flushable以便用户可以随时刷新状态。

考虑在入站适配器上使用FileSystemPersistentAcceptOnceFileListFilterinlocal-filter代替单独的过滤器元素。有关更多信息,请参阅文档

与版本开始4.1.5这种过滤器有一个选项flushOnUpdate,以flush()在每次更新元数据存储。

其他使用外部服务器(Redis、Mongo、Gemfire)的元数据存储不需要刷新。