Scrivio Interview library
ConceptFoundations7 min read · updated 12 November 2026

What problem does Spring Integration solve? Explain message, message channel, endpoint and the IntegrationFlow Java DSL with a small example that reads files from a directory, transforms each line and sends it to a channel.

Spring Integration brings the Enterprise Integration Patterns into a Spring application, so we connect files, queues, databases and other systems by configuring a pipeline instead of writing plumbing code. Data travels as messages, a payload plus headers, through message channels between endpoints such as transformers, filters, routers, splitters and service activators. The IntegrationFlow Java DSL declares such a pipeline as a @Bean, for example reading CSV files, splitting them into lines and sending each transformed line to a channel.

Why this question is asked

Most business systems spend a surprising amount of code moving data between other systems: picking up files, reading from queues, calling HTTP endpoints, writing to databases. Written by hand, each integration has its own polling loop, error handling and threading. Spring Integration gives these problems a common model and ready-made adapters. Interviewers ask about it to see whether we understand that model, because the same ideas, messages, channels and endpoints, appear in every messaging system. In this answer, we will recap the problem it solves, explain messages, channels and endpoints, look at the channel types, build the file example with the Java DSL, and see how errors are handled.

1The Problem Spring Integration Solves

Enterprise Integration Patterns is a well-known catalogue of solutions for connecting systems with messages: splitting a large message into small ones, routing messages by content, transforming formats, filtering, aggregating and so on. Spring Integration implements these patterns as Spring components, so we compose them instead of writing the logic each time.

The benefit is that each piece does one thing and the pipeline is visible as configuration. Reading files, splitting lines and sending them somewhere becomes three declared steps, and swapping the file source for an SFTP or a Kafka source changes one line. Adapters exist for files, FTP and SFTP, JMS, AMQP, Kafka, HTTP, JDBC, mail and more, so most integration code becomes configuration.

2Messages, Channels and Endpoints

A message is the unit of data. It has a payload, the actual content such as a String, a File or an order object, and headers, a map of metadata such as an id, a timestamp, the original file name or a correlation id. Messages are immutable; a step that changes the data produces a new message.

A message channel is the pipe between two steps. The sender puts a message into the channel and the receiver takes it out, so the two steps do not know about each other. Notice that this is what makes the pipeline easy to change: we can add a filter between two steps without touching either one.

An endpoint is a step that does something with messages. A transformer changes the payload, a filter drops messages that do not match, a router sends each message to one of several channels, a splitter turns one message into many, and a service activator calls a method of our own bean. Channel adapters are endpoints at the edges that connect the pipeline to an external system.

Step throughThe parts of a Spring Integration flow
  1. Inbound channel adapterreads from a file, queue or API and creates messages
  2. Message channelcarries messages; decides threading
  3. Endpointstransformer, filter, router, splitter, service activator
  4. Message channelcarries the results onward
  5. Outbound channel adapterwrites to a file, queue, database or API

5 layers, from the top down. Step through them one at a time.

3Choosing a Channel Type

The channel type decides which thread runs the next step and whether messages can pile up. A DirectChannel, the default, calls the subscriber directly on the sender's thread, so the whole flow runs synchronously and an exception travels back to the sender. A QueueChannel buffers messages in a queue, and the consumer polls it on its own schedule, which separates the producer from the consumer and gives a place to hold a burst; with a bounded capacity, a full queue makes the sender wait, which is a simple form of back pressure. A PublishSubscribeChannel delivers each message to every subscriber. An ExecutorChannel hands each message to a thread pool, so the next step runs asynchronously with one subscriber chosen per message.

Message channel types
ChannelThreadingBufferingTypical use
DirectChannelsender's threadnonedefault, simple synchronous steps
QueueChannelconsumer polls on its owna queue, can be boundeddecouple a slow consumer, absorb bursts
PublishSubscribeChannelsender's thread or an executornonesend one message to several steps
ExecutorChannela thread poolthe pool's queueparallel processing of messages

4The File Example With the Java DSL

Now let us build the example: read CSV files from a directory, split each file into lines, turn each line to upper case and send it to a channel called lines. A second flow consumes that channel.

Java
@Configuration
class CsvFlows {
@Bean
IntegrationFlow readCsvFiles() {
return IntegrationFlow
.from(Files.inboundAdapter(new File("/data/in")).patternFilter("*.csv"),
e -> e.poller(Pollers.fixedDelay(1000))) // look for new files every second
.split(Files.splitter()) // one message per line
.<String, String>transform(String::toUpperCase) // "apple,3" -> "APPLE,3"
.channel("lines") // a DirectChannel, created if missing
.get();
}
@Bean
IntegrationFlow printLines() {
return IntegrationFlow.from("lines")
.handle(m -> System.out.println(m.getPayload()))
.get();
}
}
// /data/in/fruit.csv contains: apple,3 and pear,5
// APPLE,3
// PEAR,5

Let us read it step by step. Files.inboundAdapter creates a message source that lists the directory, and patternFilter keeps only .csv files. Because a directory is not something that pushes messages, the adapter needs a poller, here one that checks every 1000 milliseconds. Each new file becomes a message whose payload is a java.io.File, and by default the adapter remembers files it has already seen in memory so it does not read them twice during one run.

Files.splitter() opens the file and emits one message per line, with the line as a String payload. The transform step changes each payload; the type parameters tell the DSL that a String comes in and a String goes out. Finally channel("lines") sends the result to the lines channel, and the second flow subscribes to it with a service activator, here a simple lambda. Spring Boot auto-configures Spring Integration when the starter is on the classpath, so registering the flows as @Bean methods is all we need.

5How Errors Are Handled

When a flow starts from a poller, there is no caller to throw an exception back to. So Spring Integration wraps the exception in an ErrorMessage and sends it to a channel named errorChannel, which exists by default and logs the error. If the flow starts from a gateway, a caller-facing entry point, the exception goes back to the caller instead.

We can set a custom error channel per flow, for example on the poller, and subscribe our own handler to it to record the failure, move the file to an error directory or raise an alert.

Java
e -> e.poller(Pollers.fixedDelay(1000).errorChannel("csvErrors"))
@Bean
IntegrationFlow csvErrorFlow() {
return IntegrationFlow.from("csvErrors")
.handle(m -> log.error("CSV failed", ((ErrorMessage) m).getPayload()))
.get();
}
// a bad line now logs: CSV failed ... MessageHandlingException ...

6Follow-up questions

When would you use QueueChannel instead of DirectChannel?

When the producer and consumer should not run on the same thread or at the same speed. A QueueChannel lets a fast producer, such as a file splitter, hand lines to a slower consumer, such as a step calling an external API, which polls at its own rate. A bounded queue also stops memory from growing without limit by making the producer wait. The cost is that the call is no longer synchronous: exceptions no longer reach the sender, and messages in the queue are lost if the process stops, unless the queue is backed by a persistent message store.

Is Spring Integration a message broker?

No. It runs inside our application and moves messages between components in memory, unless we use persistent channels or adapters. It connects to brokers such as Kafka or RabbitMQ through adapters, but it does not replace them.

How does it compare with writing a Kafka consumer by hand?

For one simple consumer, plain Spring for Apache Kafka is often enough. Spring Integration pays off when a flow combines several patterns or protocols, such as file pickup, splitting, routing and writing to several targets, because the pipeline stays declarative and each step is testable on its own.

7Conclusion

In this answer, we saw that Spring Integration implements the Enterprise Integration Patterns in Spring. Messages carry a payload and headers through channels between endpoints, and the channel type decides threading and buffering. With the IntegrationFlow Java DSL we built a flow that polls a directory for CSV files, splits them into lines, transforms each line and sends it to a channel, and we saw that poller errors go to the errorChannel unless we set our own.

What to say in the interviewAbout 80 seconds aloud

Open with

Spring Integration solves the plumbing problem of connecting systems. It implements the Enterprise Integration Patterns inside a Spring application, so instead of hand-writing polling loops and error handling, I compose a pipeline.

Then, if they want more

Data moves as messages, which are a payload plus headers. Messages travel through channels, which decouple the steps, and endpoints do the work: transformers, filters, routers, splitters and service activators, with channel adapters at the edges for files, SFTP, JMS, Kafka, HTTP, JDBC and more.

The channel type decides threading: DirectChannel runs the next step on the same thread, QueueChannel buffers and the consumer polls, publish-subscribe broadcasts, and ExecutorChannel hands off to a pool.

For the file example I write an IntegrationFlow bean: from Files.inboundAdapter on the directory with a pattern filter for csv files and a poller with a fixed delay of one second, then split with Files.splitter so each line is a message, then transform each line to upper case, then send it to the lines channel, which another flow or service activator consumes.

Errors from poller-driven flows go to the default errorChannel, which logs them, and I can set a custom error channel on the poller to handle them myself.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Spring Boot reference
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What problem does Spring Integration solve? Explain message, message channel, endpoint...": https://scrivio-interview-library.netlify.app/spring-boot/spring-projects/e8b2a0167c/