A channel adapter connects a Spring Integration message channel with an external system. An inbound adapter brings data into a flow; an outbound adapter sends the flow’s final message outward. section 10.2.8
Use channel adapters at the boundaries of an integration flow:
- Inbound adapters poll or receive data from sources such as counters, directories, and other external systems, then publish messages to a channel. section 10.2.8
- Outbound adapters consume the final message and hand it to an application or external system. section 10.2.8
- Endpoint modules provide ready-made inbound and outbound adapters for systems including files, email, HTTP, JDBC, Kafka, MQTT, Redis, and SFTP. section 10.2.9
Monitor a directory
A file-reading inbound adapter can watch an input directory, filter filenames by pattern, and publish matching files to file-channel. Java configuration uses FileReadingMessageSource with @InboundChannelAdapter and a fixed-delay poller; the Java DSL provides Files.inboundAdapter for the equivalent flow. section 10.2.8
@Bean
@InboundChannelAdapter(channel="file-channel",
poller=@Poller(fixedDelay="1000"))
public MessageSource<File> fileReadingMessageSource() {
FileReadingMessageSource sourceReader = new FileReadingMessageSource();
sourceReader.setDirectory(new File(INPUT_DIR));
sourceReader.setFilter(new SimplePatternFileListFilter(FILE_PATTERN));
return sourceReader;
}
Inspect the complete Java configuration for a directory-reading adapter, including its poll interval, directory, and filename filter. section 10.2.8
