【问题标题】:Spring Integration Java DSL: Remote filter is not applied on handle methodSpring Integration Java DSL:远程过滤器不适用于句柄方法
【发布时间】:2019-12-17 12:16:49
【问题描述】:

我想从 SFTP 服务器读取特定文件并且只获取一次压缩文件。 处理消息时遇到问题,因为在远程服务器上定义的过滤器似乎没有应用在handle方法中。

依赖关系:

  • SpringBoot:2.2.1
  • 弹簧集成:5.2.1
  • spring-integration-jdbc: 5.2.1
  • spring-integration-sftp: 5.2.1
    public IntegrationFlow buildSftpInboundIntegrationFlow() {
        return IntegrationFlows
                .from(
                        Sftp
                        .inboundStreamingAdapter(buildSftpRemoteFileTemplate())
                        .remoteDirectory(getRemoteDirectoryPath())
                        .filter(buildRemoteFileFilter())
                        .remoteFileSeparator(
                                Optional
                                .ofNullable(getRemoteFileSeparator())
                                .orElse(DEFAULT_REMOTE_PATH_SEPARATOR))
                        .maxFetchSize(
                                Optional.ofNullable(getMaxFetchSize()).orElse(DEFAULT_MAX_FETCH_SIZE)),
                        sourcePollingChannelAdapterSpec -> sourcePollingChannelAdapterSpec
                        .id(getSftpInboundStreamingAdapterIdentifier())
                        .autoStartup(true)
                        .poller(buildPollerSpec()))
                .handle(handleMessage())
                .get();
    }

    /**
     * Allows to build a regex to filter files.
     *
     * @return a regex as a {@link String}.
     */
    private String buildRegexFileFilter() {
        return String.format(".*\\.%s", getFileExtensionToFilter());
    }

    /**
     * Allows to build an instance of {@link SftpRemoteFileTemplate}.
     *
     * @return an instance of {@link SftpRemoteFileTemplate}.
     */
    private SftpRemoteFileTemplate buildSftpRemoteFileTemplate() {
        final SftpRemoteFileTemplate sftpRemoteFileTemplate = new SftpRemoteFileTemplate(getSftpSessionFactory());
        sftpRemoteFileTemplate.setAutoCreateDirectory(true);

        return sftpRemoteFileTemplate;
    }

    /**
     * Allows to build the filters to apply to the remote files.
     *
     * @return an instance of {@link CompositeFileListFilter}.
     */
    @SuppressWarnings("resource")
    private CompositeFileListFilter<LsEntry> buildRemoteFileFilter() {
        return new ChainFileListFilter<LsEntry>() // NOSONAR
                .addFilters(
                        new SftpRegexPatternFileListFilter(buildRegexFileFilter()),
                        getSftpPersistentAcceptOnceFileListFilter());
    }

    /**
     * Allows to build the poller specifications.
     *
     * @return an instance of {@link PollerSpec}.
     */
    private PollerSpec buildPollerSpec() {
        return Pollers
                .fixedDelay(
                       Optional.ofNullable(getPollerDelayInSeconds()).orElse(DEFAULT_POLLER_DELAY_IN_SECONDS),
                        TimeUnit.SECONDS)
                .transactional()
                .transactionSynchronizationFactory(getTransactionSynchronizationFactory());
    }
...

你有什么想法可以推荐给我吗? 为什么在处理方法中我收到远程过滤器应该排除的文件? 这是一个错误?如何获得过滤的消息?

【问题讨论】:

    标签: java filter spring-integration dsl handle


    【解决方案1】:

    这是 5.2.1 版本的 spring-integration 和 spring-integration-sftp 模块中的一个错误。 它通过在版本 5.2.2 中升级这些依赖项来工作。 (2019 年 12 月 6 日)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-18
      • 2016-08-13
      • 2015-11-30
      • 1970-01-01
      • 2019-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多