Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

Explain the message channel types in Spring Integration (DirectChannel, QueueChannel, PublishSubscribeChannel, ExecutorChannel) and what inbound and outbound channel adapters and gateways are for.

In Spring Integration, a DirectChannel hands each message to a single subscriber in the sender's own thread, a QueueChannel buffers messages until a consumer polls them, a PublishSubscribeChannel delivers each message to every subscriber, and an ExecutorChannel hands it to one subscriber on a thread from a TaskExecutor. Inbound channel adapters bring external data such as files, JMS messages or HTTP requests into channels, outbound adapters send messages out without expecting a reply, and gateways put a whole flow behind a plain Java interface with a request and a reply.

Background to this question

Spring Integration is Spring's implementation of the enterprise integration patterns: messages flow through channels between small components such as filters, transformers and routers. The channel type is the most important choice in a flow, because it decides which thread runs the next step, whether a slow step blocks the sender, and whether messages can be lost on a crash. In this answer, we will recap messages and endpoints, go through the four channel types with code and their effect on threads, and then see what inbound adapters, outbound adapters and gateways do at the edges of a flow.

1A Quick Recap of Messages, Channels and Endpoints

A Spring Integration message has a payload, the data, and headers, such as an id and a timestamp. Components that do work, such as a transformer that converts a CSV line into an object or a service activator that calls one of our beans, are called endpoints. Endpoints never call each other directly. Each one reads from an input channel and writes to an output channel, and the channel decides how the message gets to the next endpoint.

That separation is the point: we can change a channel from synchronous to asynchronous, or from one consumer to many, without touching the endpoints on either side.

2DirectChannel: One Subscriber, Same Thread

A DirectChannel is the default. When a message is sent, the channel immediately calls one subscribed endpoint in the sender's thread, as if it were a method call. If several endpoints subscribe, the channel balances between them in round-robin order, but each message still goes to only one.

Java
@Bean
MessageChannel orders() { return new DirectChannel(); }
@ServiceActivator(inputChannel = "orders")
void handle(String order) {
System.out.println(Thread.currentThread().getName() + " " + order);
}
orders().send(new GenericMessage<>("o-1")); // prints: main o-1 (runs before send returns)

Because everything runs in one thread, a DirectChannel keeps transactions working across the steps: a transaction started by the sender covers the whole downstream flow. An exception in the subscriber is thrown back to the sender. There is no buffer, so nothing is held in memory and nothing is lost on a crash beyond the message being processed.

3QueueChannel, PublishSubscribeChannel and ExecutorChannel

A QueueChannel holds messages in an internal queue. Sending just adds the message and returns, and the consumer must poll the channel to take messages out, so its endpoint needs a poller that says how often and how many.

Java
@Bean
QueueChannel work() { return new QueueChannel(100); } // holds up to 100 messages
@ServiceActivator(inputChannel = "work", poller = @Poller(fixedDelay = "500", maxMessagesPerPoll = "10"))
void process(String job) { ... } // runs on a poller thread, not the sender's
@Bean
PublishSubscribeChannel orderEvents() { return new PublishSubscribeChannel(); } // every subscriber gets each message
@Bean
ExecutorChannel resize(TaskExecutor executor) { return new ExecutorChannel(executor); } // one subscriber, executor thread
Spring Integration channel types
ChannelDelivers toRuns onBuffer
DirectChannelone subscribersender's threadnone
QueueChannelone polling consumerpoller threadin memory or message store
PublishSubscribeChannelevery subscribersender's thread or executornone
ExecutorChannelone subscriberTaskExecutor threadexecutor's queue

A QueueChannel decouples the sender from a slower consumer, but the default queue is in memory, so messages waiting in it are lost if the application stops; a message store can back it when that matters. A PublishSubscribeChannel calls every subscriber, for example to send an order to both billing and auditing, by default one after the other in the sender's thread, or in parallel if given an executor. An ExecutorChannel is like a DirectChannel that hands each message to a thread pool instead of running it in the sender's thread, so the sender returns immediately without needing a poller. Notice the cost of both asynchronous channels: the sender's transaction does not follow the message, and exceptions go to an error channel instead of back to the sender.

4Inbound and Outbound Channel Adapters

Channels and endpoints only move messages inside the application. Adapters connect a flow to the outside world. An inbound channel adapter watches an external source and turns what it finds into messages on a channel: a file adapter polls a directory and sends one message per new file, a JMS adapter receives from a queue, an HTTP inbound adapter turns a request into a message. An outbound channel adapter does the reverse at the end of a flow: it writes the message to a file, a JMS destination, a Kafka topic or an HTTP endpoint, and expects no reply.

Java
@Bean
IntegrationFlow incomingInvoices() {
return IntegrationFlow
.from(Files.inboundAdapter(new File("/data/in")).patternFilter("*.csv"),
e -> e.poller(Pollers.fixedDelay(5000))) // inbound adapter: a message per file
.transform(Files.toStringTransformer())
.handle(Jms.outboundAdapter(connectionFactory).destination("invoices")) // outbound adapter: one way
.get();
}

When the external system answers, such as an HTTP call whose response we need, we use an outbound gateway instead of an outbound adapter, because a gateway waits for the reply and passes it on.

5Gateways: A Flow Behind a Java Interface

A messaging gateway goes the other way: it lets ordinary application code call a flow without knowing about messages. We declare an interface, and Spring Integration generates an implementation that turns each method call into a message on the request channel and, for methods that return a value, waits for the reply.

Java
@MessagingGateway(defaultRequestChannel = "quotes")
public interface QuoteService {
Price quote(QuoteRequest request); // request in, reply out
}
// in a controller or service
Price p = quoteService.quote(new QuoteRequest("P-1", 3)); // the flow behind "quotes" computes it

So the rest of the code depends on a plain interface it can mock in tests, and the flow behind it can use any channels and adapters. A gateway can also have a timeout for the reply and an error channel for failures.

6Follow-up questions

Which channel should a flow use by default?

DirectChannel, unless there is a reason to change. It is simple, keeps transactions and exceptions with the caller, and holds nothing in memory. We switch to an ExecutorChannel or QueueChannel only where a step must not block the sender, and accept the error-handling changes that come with it.

Where do exceptions go on an asynchronous channel?

Since the sender has already returned, the exception is wrapped in an ErrorMessage and sent to an error channel, by default the global errorChannel, which logs it. Flows that care should set their own error channel to handle, count and quarantine failures.

What is the difference between an outbound adapter and an outbound gateway?

An outbound adapter is one-way: it sends the message and the flow ends there. An outbound gateway sends a request and waits for the reply, which becomes the next message in the flow, for example the response of an HTTP call.

7Conclusion

In this answer, we saw that a DirectChannel calls one subscriber in the sender's thread, a QueueChannel buffers messages for a polling consumer, a PublishSubscribeChannel delivers to every subscriber, and an ExecutorChannel hands each message to a thread pool. Inbound adapters bring external data into channels, outbound adapters send messages out without a reply, and gateways expose a flow behind a plain Java interface with request and reply.

What to say in the interviewAbout 90 seconds aloud

Open with

In Spring Integration, endpoints never call each other directly; they're connected by channels, and the channel type decides threading and buffering. A DirectChannel is the default: send calls one subscriber immediately in the sender's thread, like a method call, so transactions and exceptions stay with the caller.

Then, if they want more

If several endpoints subscribe, it round-robins. A QueueChannel buffers messages, in memory by default or in a message store, and the consumer needs a poller to take them out, so it decouples a fast sender from a slow consumer, but buffered messages can be lost on shutdown unless it's backed by a store.

A PublishSubscribeChannel sends every message to all subscribers, in the sender's thread unless I give it an executor. An ExecutorChannel delivers to one subscriber but on a TaskExecutor thread, so the sender returns at once without a poller. With the async ones, the transaction doesn't follow the message and errors go to an error channel.

At the edges, inbound channel adapters turn external input like files, JMS messages or HTTP requests into messages, and outbound channel adapters send messages out one way, to a file, queue or topic. When I need a reply from outside, I use an outbound gateway.

And a messaging gateway lets my code call a flow through a plain Java interface, request in and reply out, so the rest of the app doesn't see messages at all.

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 Cloud Stream 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 "Explain the message channel types in Spring Integration (DirectChannel, QueueChannel...": https://scrivio-interview-library.netlify.app/spring-boot/spring-cloud-stream/d20d5b163a/