繁体   English   中英

尽管设置为无限制,但 Spring 集成 (SFTP) 消息源每次轮询获取的文件不超过 1 个

[英]Spring Integration (SFTP) message source isn't getting more than 1 file per poll despite setting to unlimited

我有以下代码从 sftp 服务器作为 InputStream 读取 xml 文件:

@Configuration
public class SftpConfig {
    ...

    @Bean
    @InboundChannelAdapter(channel = "stream", poller = @Poller(fixedDelay="60000"))
    public MessageSource<InputStream> messageSource() {
        SftpStreamingMessageSource messageSource = new SftpStreamingMessageSource(template());
        messageSource.setRemoteDirectory(sftpProperties.getBaseDir());
        messageSource.setFilter(new SftpSimplePatternFileListFilter("*.xml"));
        // messageSource.setMaxFetchSize(-1); no matter what i set this to, it only fetches one file
        return messageSource;
    }

    @ServiceActivator(inputChannel = "stream", adviceChain = "after")
    @Bean
    public MessageHandler handle() {
        return message -> {
            Assert.isTrue(message.getPayload() instanceof InputStream, "Payload must be of type $InputStream");
            String filename = (String) message.getHeaders().get(FileHeaders.REMOTE_FILE);
            InputStream is = (InputStream) message.getPayload();
            log.info("I am here"); // each poll only prints this once
        };
    }
    ...
}

当我调试或检查MessageHanlder$handleMessage的日志时,我一直只看到一条消息(文件对象)通过。 并且有不止一个.xml文件位于 sftp 服务器上,我可以通过在下一次投票中看到文件来验证。 文件说

    /**
     * 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.
     */
    void setMaxFetchSize(int maxFetchSize);

所以我摆弄了不同的数字,但无济于事。 我在这里想念什么?

抱歉误导,但fetch并不意味着poll fetch 选项只是在第一次轮询时将尽可能多的远程实体带到本地缓存,并且每个后续轮询只是从该缓存中获取条目,直到它被耗尽。

每次轮询的最大消息数选项属于该@Poller配置。 请参阅相应的选项:

/**
 * @return The maximum number of messages to receive for each poll.
 * Can be specified as 'property placeholder', e.g. {@code ${poller.maxMessagesPerPoll}}.
 * Defaults to -1 (infinity) for polling consumers and 1 for polling inbound channel adapters.
 */
String maxMessagesPerPoll() default "";

注意1 for polling inbound channel adapters 这就是您看到只有一条消息通过的方式。

然而,逻辑就像只向频道推送一条消息。 您现在有多少文件没有批处理。 fetch perPoll ,只有一条消息被发送到通道。 尽管我同意使用无限perPoll ,所有消息都在同一个线程和同一个轮询周期中发送。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM