【问题标题】:How to processing multiples large files at same time with multiples instances using Spring Batch Integration?如何使用 Spring Batch Integration 同时处理多个大文件和多个实例?
【发布时间】:2021-07-28 12:15:45
【问题描述】:

我为处理多个文件创建了一个 Spring Batch Integration 项目,它的工作原理非常棒。

在我写这个问题时,我有 四个 Pod 正在运行,但行为并不像我预期的那样,我预计同时处理 20 个文件(每个 Pod 五个) .

我的 pooler 设置使用以下参数:

    poller-delay: 10000
    max-message-per-poll: 5

我也使用 Redis 来存储文件和过滤:

    private CompositeFileListFilter<S3ObjectSummary> s3FileListFilter() {
        return new CompositeFileListFilter<S3ObjectSummary>().addFilter(
                new S3PersistentAcceptOnceFileListFilter(new RedisMetadataStore(redisConnectionFactory), "prefix-"))
                .addFilter(new S3RegexPatternFileListFilter(".*\\.csv$"));
    }

似乎每个 pod 只处理一个文件,另一种奇怪的行为是其中一个 pod 注册了 Redis 中的所有文件,所以其他 pod 只获取新文件。

同时处理多个文件的最佳做法是什么以及如何解决这个问题?

【问题讨论】:

    标签: spring-batch spring-integration spring-batch-integration


    【解决方案1】:

    S3InboundFileSynchronizingMessageSource 上查看此选项:

    /**
     * Set the maximum number of objects the source should fetch if it is necessary to
     * fetch objects. Setting the
     * maxFetchSize to 0 disables remote fetching, a negative value indicates no limit.
     * @param maxFetchSize the max fetch size; a negative value means unlimited.
     */
    @ManagedAttribute(description = "Maximum objects to fetch")
    void setMaxFetchSize(int maxFetchSize);
    

    这里是文档:https://docs.spring.io/spring-integration/docs/current/reference/html/ftp.html#ftp-max-fetch

    【讨论】:

    • 感谢您的关注,我读到这正是我所需要的。我在这里想只是为了了解在我的情况下,我的 pooler 每 10 秒运行一次,并且 max-message 为 5。因此,如果我将例如 maxFetchSize 设置为 2,pooler 将运行但如果消息池仅获得 2 个新文件少于 5 条消息?
    • 不,那不是。它肯定会轮询 5 条消息。 Fetch 是关于一次从源系统中获取多少并将它们缓存在内存中以供后续轮询。但是由于您希望它在许多实例上并行,所以最好不要获取所有现有条目。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多