Spring integration: How processing files sequentially

泄露秘密 提交于 2019-12-06 02:50:18

That is the default behavior as long as

  1. The poller does not have a task-executor (which yours doesn't).
  2. Only DirectChannels (the default) are used downstream of the adapter - this means no QueueChannels or ExecutorChannel (i.e. no task-executor or <queue/> on the channels).

In that scenario, the next poll is not even considered until the current one finishes - the flow runs on the poller thread and only one poll can be in process at once.

The fixed-delay does not start until the current file is completely processed.

EDIT

If you need to use async processing on the flow, you need to use a Conditional Poller or a simple PollSkipAdvice.

You would provide a PollSkipStrategy implementation that would return false until the file is complete.

That way, subsequent polls will be skipped until you decide.

EDIT2

Something like this...

/*
 * Copyright 2015 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.springframework.integration.scheduling;

/**
 * @author Gary Russell
 * @since 4.3
 *
 */
public class SimplePollSkipStrategy implements PollSkipStrategy {

    private volatile boolean skip;

    @Override
    public boolean skipPoll() {
        return this.skip;
    }

    public void skipPolls() {
        this.skip = true;
    }

    public void reset() {
        this.skip = false;
    }
}
  • Add it as a <bean/> to your context.
  • Add it to the poller's advice chain with a PollSkipAdvice
  • When you want to skip polls, call skipPolls().
  • When you've finished with a file, call reset().
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!