Spring集成-Files.inboundAdapter,服务器错误打开的文件太多
您好,我是spring integration的新手,我有下面的代码流读取/扫描目录中的文件,我遇到服务器错误,打开的文件太多。。我想知道是否是以下原因导致了问题? 轮询器是否每次都打开新文件而不关闭以前的文件 谢谢你的帮助Spring集成-Files.inboundAdapter,服务器错误打开的文件太多,spring,spring-boot,spring-integration,spring-integration-dsl,Spring,Spring Boot,Spring Integration,Spring Integration Dsl,您好,我是spring integration的新手,我有下面的代码流读取/扫描目录中的文件,我遇到服务器错误,打开的文件太多。。我想知道是否是以下原因导致了问题? 轮询器是否每次都打开新文件而不关闭以前的文件 谢谢你的帮助 @Bean public IntegrationFlow jsonFileRefreshFlow(){ return IntegrationFlows.from(Files.inboundAdapter(new File(filePath)) .autoCreate
@Bean
public IntegrationFlow jsonFileRefreshFlow(){
return IntegrationFlows.from(Files.inboundAdapter(new File(filePath))
.autoCreateDirectory(true)
.patternFilter("*.json")
.watchEvents(FileReadingMessageSource.WatchEventType.CREATE,
FileReadingMessageSource.WatchEventType.MODIFY)
.useWatchService(true)
.scanEachPoll(true)
.preventDuplicates(false)
e -> e.poller(Pollers.fixedDelay(1000, TimeUnit.MILLISECONDS)
.maxMessagesPerPoll(Integer.MAX_VALUE)))
.<File, Resource>transform(p -> new FileSystemResource(p))
.<Resource>handle((p,h) -> {
try{
// process payload
}catch (IOException ioEx){
log.error("Error refreshing json specs {}", ioEx);
}finally {
try {
p.getInputStream().close();
} catch (IOException e) {
log.error("error closing stream");
}
}
return null;
}).get();
@Bean
公共集成流JSonfilleRefreshFlow(){
返回IntegrationFlows.from(Files.inboundAdapter(新文件(文件路径))
.autoCreateDirectory(true)
.patternFilter(“*.json”)
.watchEvents(FileReadingMessageSource.WatchEventType.CREATE,
FileReadingMessageSource.WatchEventType.MODIFY)
.useWatchService(真)
.scanEachPoll(真)
.防止重复(错误)
e->e.poller(Pollers.fixedDelay(1000,时间单位毫秒)
.maxMessagesPerPoll(整数.MAX_值)))
.transform(p->newfilesystemresource(p))
.手柄((p,h)->{
试一试{
//进程有效负载
}捕获(IOException ioEx){
error(“刷新json规范{}时出错”,ioEx);
}最后{
试一试{
p、 getInputStream().close();
}捕获(IOE异常){
log.error(“错误关闭流”);
}
}
返回null;
}).get();
框架不会打开文件;可能是您的.handle()
方法打开了文件;因此它负责关闭文件