An inbound channel adapter is an entry point to a Spring Integration flow. It takes data from a source and supplies it as messages for the flow to process. An outbound channel adapter does the reverse: it hands a message off at the end of a flow. section 10.2.8
Choose an adapter for the source you need to read:
- For a simple generated source, an @InboundChannelAdapter bean can poll a MessageSource<Integer> and send each new number to numberChannel. section 10.2.8
- For files, FileReadingMessageSource can watch a directory, filter filenames, and send discovered files to file-channel. The Java DSL offers Files.inboundAdapter() for the same kind of entry point. section 10.2.8
- For email, the mail endpoint module supplies an IMAP inbound adapter that polls a mailbox. section 10.3
@Bean
@InboundChannelAdapter(
poller=@Poller(fixedRate="1000"), channel="numberChannel")
public MessageSource<Integer> numberSource(AtomicInteger source) {
return () -> {
return new GenericMessage<>(source.getAndIncrement());
};
}
The @Poller sets a 1,000 ms fixed rate; channel names the destination. Each poll obtains the next AtomicInteger value and wraps it in a GenericMessage. 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;
}
This file-reading bean shows how the source directory and filename filter are configured before files enter the channel. section 10.2.8
Poll an inbox for orders
An email-order flow starts with IntegrationFlows.from(Mail.imapInboundAdapter(emailProps.getImapUrl()), e -> e.poller(Pollers.fixedDelay(emailProps.getPollRate()))). The configured IMAP URL identifies the mailbox, and the poll rate controls how often it is checked. Later steps turn incoming email into order objects and pass them to a handler that posts orders to a REST API. The adapter's job is to get the email into the flow; the transformer and handler do the subsequent work. section 10.3
