liveBook · Manning

Integration flow

As explained in Spring in Action, Sixth Edition

An integration flow is an ordered sequence of messaging components that receives, transforms, routes, or sends data between an application and external resources.

An integration flow is a pipeline that moves messages between an application and an external resource. Each component has a job: a gateway can accept data from application code, channels carry messages between components, and a channel adapter connects the flow to an external system. Along the way, components can transform, route, or otherwise process the data. section 10.0 section 10.2

Write application text to a file

Suppose an application needs to write text to the filesystem. A method call on a messaging gateway sends a message to an input channel. A transformer converts its payload to uppercase and passes it to a second channel. A file-writing component then writes the payload using the filename in the message header. The flow can append a new line when the file already exists. section 10.1 section 10.1.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);
 
}

The gateway interface shows how an ordinary method call enters the flow: @MessagingGateway names the request channel, while @Header supplies the output filename. section 10.1

In Java configuration, @Transformer connects the uppercase transformer to its input and output channels. @ServiceActivator connects the output channel to a FileWritingMessageHandler. The named channels can be created automatically. Because writing the file produces no reply, configure the handler not to expect one; otherwise, the pipeline works but logs missing-reply-channel errors. XML can define the same flow, while a Java DSL offers another configuration style. section 10.1.2 section 10.1.1 section 10.4

Turn incoming email into orders

A flow can also start outside the application. An inbound email adapter polls an IMAP mailbox, a transformer parses messages into order objects, and a handler submits those orders to a REST API. Mailbox credentials, location, and polling rate are configuration properties rather than fixed details of the flow. section 10.3

Choose components to match the work between entry and exit: filters conditionally pass messages, routers choose channels, splitters produce multiple messages, and aggregators combine them. Channels connect these steps so each can perform a distinct task. section 10.2

How Spring in Action, Sixth Edition covers it

How deep it goes
Works through filesystem and email flows, including configuration and component roles, without attempting a comprehensive Spring Integration treatment.
Examples
Uses an uppercase file writer and an IMAP-to-REST order pipeline as concrete flows.
What it assumes
Introduces gateway and component roles through examples while assuming a Spring application that can accept dependencies and configuration.
What you can do after
Build it from scratch with Spring Integration using XML, Java configuration, or the Java DSL.
How it connects
Connects message channels, gateways, channel adapters, transformers, service activators, 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.