Spring Integration Metadatastore

时间:2015-06-12 09:18:25

标签: 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;
    }
}

另外,我在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"/>

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

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

在我的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>

1 个答案:

答案 0 :(得分:4)

默认情况下,PropertiesPersistingMetadataStore仅在正常的应用程序关闭时保持状态;它一直存在记忆中。

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

考虑在入站适配器的FileSystemPersistentAcceptOnceFileListFilter中使用local-filter而不是单独的过滤器元素。有关详细信息,请参阅the documentation

从版本4.1.5开始,每次更新时都会filter has an option flushOnUpdateflush()元数据存储。

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