liveBook · Manning

Inbound channel adapter

As explained in Spring in Action, Sixth Edition

An inbound channel adapter is a Spring Integration endpoint that receives data from an external system and supplies messages to an integration flow.

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

How Spring in Action, Sixth Edition covers it

How deep it goes
Works through annotated and Java DSL declarations, polling, and file filtering; stops short of adapter implementation internals.
Examples
Uses an incrementing counter, a filtered directory reader, and an IMAP-to-order flow.
What it assumes
Builds on Spring bean configuration while defining the adapter’s entry-point role before showing implementations.
What you can do after
Build it from scratch with Java configuration or the Java DSL to poll a source into an integration flow.
How it connects
Connects message channels and pollers to MessageSource, integration flows, transformers, and message handlers.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.