liveBook · Manning

Spring Integration

As explained in Spring in Action, Sixth Edition

Spring Integration is a Spring framework project for implementing message-based integration flows between applications and application components.

Spring Integration is a Spring framework project for connecting applications and application components through real-time message-based integration flows. Messages move through pipelines of components that can transform, split, aggregate, route, or process data. section 1.4.5 section 10.4

A flow connects an application to resources such as files, email, external APIs, or databases. Message gateways and channel adapters provide entry and exit points, while message channels act as the pipes between processing steps. section 10.0 section 10.4

Common building blocks include:

  • Message gateways turn method calls into messages; @MessagingGateway can cause Spring Integration to generate the implementation at runtime. section 10.1
  • Message channels connect components and determine how messages are delivered, queued, prioritized, or dispatched across threads. section 10.2.1
  • Endpoint modules connect flows to external systems; the file endpoint can read files into a flow or write flow data to the filesystem. section 10.1

Writing data to a file

Add the Spring Integration starter and file endpoint dependency, define a FileWriterGateway with defaultRequestChannel="textInChannel", and expose writeToFile(filename, data). Calls to that method become messages and enter the flow, where a file endpoint writes the data to the filesystem. section 10.1

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-integration</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.integration</groupId>
    <artifactId>spring-integration-file</artifactId>
</dependency>

Use the dependency listing to add the Spring Integration starter and filesystem endpoint module to a Maven project. section 10.1

Listing 10.1 Message gateway interface to transform method invocations into messages
package sia6;
 
import org.springframework.integration.annotation.MessagingGateway;
import org.springframework.integration.file.FileHeaders;
import org.springframework.messaging.handler.annotation.Header;
 
@MessagingGateway(defaultRequestChannel="textInChannel")   #1
public interface FileWriterGateway {
 
  void writeToFile(
      @Header(FileHeaders.FILENAME) String filename,       #2
      String data);
 
}

Use the gateway listing as a concrete pattern for converting a Java method invocation into a message with a filename header and text payload. section 10.1

How Spring in Action, Sixth Edition covers it

How deep it goes
Defines pipelines, gateways, adapters, channels, and message operations without detailing their internal implementation.
Examples
Uses a filesystem-writing flow and channel examples including publish-subscribe, queue, direct, executor, priority, rendezvous, and reactive channels.
What you can do after
Build integration flows that receive, process, and send data through gateways, channels, adapters, and external endpoints.
How it connects
Connects message gateways, channel adapters, message channels, service activators, Java DSL, XML configuration, and Enterprise Integration Patterns.

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.