入站通道适配器是通过一个轮询器来轮询根目录及其子目录中的文件。
e.g.
RootDir
|_abc.txt
|_subdirectory1
|_subdirfile1.doc
问题是入站通道适配器也以消息的形式读取目录。
@Bean
@InboundChannelAdapter(autoStartup = "false", value = "incomingchannel", poller = @Poller("custompoller"))
public MessageSource<File> fileReadingMessageSource(DirectoryScanner directoryScanner) {
FileReadingMessageSource sourceReader = new FileReadingMessageSource();
sourceReader.setScanner(directoryScanner);
}
@Bean
public DirectoryScanner directoryScanner() {
DirectoryScanner scanner = new RecursiveDirectoryScanner();
CompositeFileListFilter filter = new CompositeFileListFilter<>(
Arrays.asList(new AcceptOnceFileListFilter<>(), new RegexPatternFileListFilter(regex)));
scanner.setFilter(filter);
return scanner;
}
@Trasnformer(inputChannel="incomingchannel",....
torequest(Mesage<File> message) {
message.getPayload()
}
这里message.getpayLoad是打印子目录1,即目录也是作为一个文件来读取的message
我可以在trasnformer中明确地处理文件是否是目录并忽略,但想知道是否有任何方法可以在连接到入站通道适配器的递归目录扫描器中进行过滤?