Spring Integration’s Java DSL defines a message-processing pipeline with a fluent Java API. Instead of declaring a bean for every component, you can return the whole flow from one @Bean method. It is an alternative to XML configuration and annotation-based Java configuration. section 10.1.2 section 10.1.3
A file-writing flow follows four steps:
- Start at textInChannel with IntegrationFlows.from(...). If no channel bean with that name exists, Spring Integration creates it. section 10.1.3
- Call transform(...) to uppercase each text payload. section 10.1.3
- Call handle(...) with a Files outbound adapter to write the result, then get() to build the IntegrationFlow. section 10.1.3
- Add channel(...) when the connection between components needs an explicit name or configuration; otherwise, the flow need not name it. section 10.1.3
@Bean
public IntegrationFlow fileWriterFlow() {
return IntegrationFlows
.from(MessageChannels.direct("textInChannel"))
.<String, String>transform(t -> t.toUpperCase())
.channel(MessageChannels.direct("FileWriterChannel"))
.handle(Files
.outboundAdapter(new File("/tmp/sia6/files"))
.fileExistsMode(FileExistsMode.APPEND)
.appendNewLine(true))
.get();
}
The complete file-writing flow shows where an explicit channel fits between the transformer and outbound adapter. section 10.1.3
The same API handles branching and service calls. route(...) selects subflows, split(...) turns one message into several, and handle(...) invokes a handler. A terminal GenericHandler should return null when there is no output channel; returning a payload instead can produce a no-output-channel error. Keep longer fluent flows readable with indentation, extracted methods, or subflows. section 10.2.4 section 10.2.5 section 10.2.6 section 10.1.3
Email orders
A separate application can poll an IMAP mailbox, transform each email into an order, and pass that order to a handler that POSTs it to a REST API. The flow combines Mail.imapInboundAdapter(...), a configured fixed-delay poller, transform(...), and handle(...); the mail adapter requires the Spring Integration mail dependency. section 10.3
