[英]Spring integration ftp adapter and batch processing
我需要輪詢 FTP 服務器並處理新的或更改的文件。 我將 Spring Integration 5.3.2 與入站 FTP 適配器和固定速率為 5 秒的輪詢器一起使用。 所有文件立即下載到本地目錄中,但集成流程底層處理程序每 5 秒為每個文件調用一次。 我想在並發線程中立即處理下載的文件列表,但在流程結束后每 5 秒輪詢一次 ftp。 我該怎么做?
@Bean
fun ftpInboundFlow(): IntegrationFlow {
return IntegrationFlows.from(Ftp.inboundAdapter(ftpSessionFactory())
.preserveTimestamp(true)
.maxFetchSize(ftpProperties.maxFetchSize)
.remoteDirectory(ftpProperties.remoteDirectory)
.localDirectory(File(ftpProperties.downloadDirectory))
.filter(FtpPersistentAcceptOnceFileListFilter(SimpleMetadataStore(), "ftp-"))
.regexFilter(".*\\.zip$")
) { e -> e.poller(Pollers.fixedRate(Duration.ofSeconds(5))) }
.channel(MessageChannels.executor(Executors.newWorkStealingPool()))
.transform(unZipTransformer())
.handle { m -> LOGGER.info("Unzipped {}", m.headers[FileHeaders.FILENAME]) }
.get()
}
設置maxMessagesPerPoll
- 默認為 1; -1 表示無窮大。
Pollers.fixedRate(Duration.ofSeconds(5)).maxMessagesPerPoll(-1)
聽起來更像是您想使用來自FtpOutboundGateway
的MGET
命令。 因此,您仍然可以使用帶有空字符串有效負載的普通輪詢器來發送,例如IntegrationFlows.from(() -> "")
和所需的輪詢器選項。
使用針對遠程目錄的MGET
命令調用Ftp.outboundGateway()
將為您提供List<File>
作為回復消息。 因此,您可以批量處理您的文件。
有關更多信息,請參閱文檔: https : //docs.spring.io/spring-integration/docs/5.3.2.RELEASE/reference/html/ftp.html#ftp-outbound-gateway
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.