liveBook · Manning

Channel adapter

As explained in Spring in Action, Sixth Edition

A channel adapter is a Spring Integration component that connects a message channel to an external system by receiving or sending messages.

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

How Spring in Action, Sixth Edition covers it

How deep it goes
Explains inbound and outbound roles, polling, file adapters, annotations, endpoint modules, and Java DSL alternatives.
Examples
Uses incrementing numbers, directory monitoring, filesystem writing, and endpoint modules for email and other transports.
What it assumes
Assumes Spring Integration flows, message channels, and basic Java configuration while introducing adapter roles and endpoint modules.
What you can do after
Builds inbound and outbound adapters with Java configuration or the Java DSL for filesystem and other external integrations.
How it connects
Connects message channels, integration flows, message gateways, service activators, endpoint modules, transformers, routers, splitters, and aggregators.

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.