skip to content

Messaging & Integration

Spring's messaging and integration support: the generic Message abstraction, Spring Integration's EIP toolkit, JMS, RabbitMQ, Kafka, WebSocket with STOMP, and RSocket. Interviewers use it to see whether you can move work off the request thread and across process boundaries deliberately.

part ofSpring Frameworkoverview, primer and where to startread it →
on this pageshow

explore

questions

141 · 7 sections

In Spring Messaging, what are MessageChannel and MessageHandler, and how do they relate?

level: juniorimportance: must knowfreq 40%
basics
~10 s

MessageChannel is a pipe you send messages into via send(). MessageHandler is code that receives one message via handleMessage(). A producer sends to a channel; a handler subscribed to that channel processes what arrives.

open as a page

What is Spring's Message<T> abstraction, and what are its two parts?

level: juniorimportance: must knowfreq 70%
basics
~10 s

Message<T> is Spring's generic container for something being sent. It has two parts: a payload (the body of type T) and MessageHeaders (a map of metadata like an id and timestamp).

open as a page

What is the difference between Spring's ApplicationEventPublisher / @EventListener and the messaging support in spring-messaging (Message / MessageChannel)?

level: juniorimportance: must knowfreq 60%
basics
~10 s

ApplicationEventPublisher with @EventListener sends events between beans inside one running JVM. spring-messaging (Message, MessageChannel) is a broader abstraction for passing messages, often across process boundaries through a broker like Kafka or RabbitMQ.

open as a page

What is the difference between a SubscribableChannel and a PollableChannel (e.g. DirectChannel vs QueueChannel)?

level: middleimportance: must knowfreq 45%
basics
~10 s

A SubscribableChannel pushes each message to handlers that subscribed to it (DirectChannel). A PollableChannel buffers messages in a queue and a consumer must pull them with receive() (QueueChannel).

open as a page

How do you build a Message with custom headers, and why can't you just mutate headers on an existing message?

level: middleimportance: must knowfreq 65%
basics
~10 s

Use MessageBuilder: MessageBuilder.withPayload(body).setHeader("key", value).build(). You can't mutate an existing message's headers because MessageHeaders is immutable — instead you build a new message, optionally copying the old headers.

open as a page

In Spring Integration, what is a channel adapter, and what is the difference between an inbound and an outbound channel adapter?

level: juniorimportance: must knowfreq 60%
basics
~20 s

A channel adapter connects an external system to a Spring Integration message channel. Inbound adapters bring external data IN as messages; outbound adapters send message payloads OUT to an external system. Both are one-way (no reply).

open as a page

What is a Spring Integration message channel, and what is the difference between point-to-point and publish-subscribe channels?

level: juniorimportance: must knowfreq 62%
basics
~10 s

A message channel is the pipe connecting components; producers send messages to it and consumers receive from it. Point-to-point delivers each message to exactly one consumer; publish-subscribe broadcasts each message to every subscriber.

open as a page

What does @Transformer do in Spring Integration, and how does a transformer endpoint fit into a message flow?

level: juniorimportance: must knowfreq 60%
basics
~20 s

@Transformer marks a method that takes an incoming message (or its payload) and returns a changed version — a new payload or modified headers. It sits between two channels, reading from one and writing the result to the other.

open as a page

What is a @ServiceActivator in Spring Integration, and what does it do?

level: juniorimportance: must knowfreq 35%
basics
~20 s

A @ServiceActivator marks a method (or bean) that consumes messages from an input channel, runs your business logic, and optionally sends the return value to an output channel. It connects a message channel to plain application code.

open as a page

What is the Spring Integration Java DSL and how do you define a basic flow with it?

level: juniorimportance: must knowfreq 60%
basics
~10 s

It's a fluent Java API for building Spring Integration message pipelines instead of XML. You define an IntegrationFlow bean starting with IntegrationFlow.from(a source), then chain steps like .transform() and .handle().

open as a page

What is a JMS MessageConverter in Spring, and what does the default SimpleMessageConverter do?

level: juniorimportance: must knowfreq 55%
basics
~10 s

A MessageConverter turns your Java objects into a jakarta.jms.Message (and back), so you send objects instead of raw messages. The default, SimpleMessageConverter, maps String, byte[], Map, and Serializable to matching message types automatically.

open as a page

What do @EnableJms and @JmsListener do, and what is the minimal setup to consume messages from a queue in Spring?

level: juniorimportance: must knowfreq 55%
basics
~10 s

@EnableJms turns on scanning for @JmsListener methods. You put @JmsListener(destination = "queue") on a bean method; Spring runs it for each incoming message. You also need a ConnectionFactory and a listener container factory bean.

open as a page

What is Spring's JmsTemplate, and what do convertAndSend and receiveAndConvert do?

level: juniorimportance: must knowfreq 70%
basics
~20 s

JmsTemplate is a Spring helper that hides raw JMS boilerplate (opening connections, sessions, producers). convertAndSend turns a Java object into a JMS message and sends it; receiveAndConvert reads a message and converts it back to a Java object.

open as a page

What does the sessionTransacted flag do on a JmsTemplate or a JMS listener container, and what is a transacted JMS Session?

level: juniorimportance: must knowfreq 55%
basics
~20 s

It makes the JMS Session transacted: sends/receives are buffered and only take effect when the session commits, or are undone on rollback. On a listener, a failed message is rolled back and redelivered instead of lost.

open as a page

Compare DefaultMessageListenerContainer and SimpleMessageListenerContainer. When would you choose each, and how does concurrency differ?

level: middleimportance: must knowfreq 50%
basics
~20 s

DefaultMessageListenerContainer (DMLC) is the flexible default: it supports transactions, error recovery, and dynamic scaling of consumer threads (concurrency "lower-upper"). SimpleMessageListenerContainer (SMLC) is lightweight with a fixed number of consumers and no external transaction support. Use DMLC almost always.

open as a page

What is dead-lettering in RabbitMQ/Spring AMQP, and how do you configure a dead-letter exchange on a queue?

level: juniorimportance: must knowfreq 70%
basics
~10 s

Dead-lettering routes messages that can't be processed to a separate exchange instead of losing them. You set the queue arguments x-dead-letter-exchange (and optionally x-dead-letter-routing-key) when declaring the queue.

open as a page

What are RabbitMQ publisher confirms in Spring AMQP, and what problem do they solve?

level: juniorimportance: must knowfreq 62%
basics
~20 s

By default, sending a message via RabbitTemplate doesn't tell you if the broker actually received it. Publisher confirms make the broker send back an async ack (or nack) per message, so the producer knows the send succeeded.

open as a page

What do @RabbitListener and @EnableRabbit do, and how do you turn a method into a RabbitMQ consumer with Spring AMQP?

level: juniorimportance: must knowfreq 78%
basics
~20 s

@RabbitListener on a method makes it consume messages from a queue. @EnableRabbit (auto-configured by Spring Boot) switches on the machinery that scans for those annotations and starts listener containers that deliver each message to your method.

open as a page

What is RabbitTemplate and what does convertAndSend(exchange, routingKey, payload) do?

level: juniorimportance: must knowfreq 70%
basics
~10 s

RabbitTemplate is Spring AMQP's helper for sending and receiving RabbitMQ messages. convertAndSend takes a Java object, converts it to a message, and publishes it to the named exchange with the given routing key.

open as a page

In Spring AMQP, what are an Exchange, a Queue, and a Binding, and how do you declare each as a Spring bean?

level: juniorimportance: must knowfreq 70%
basics
~20 s

A Queue holds messages. An Exchange receives published messages and routes them. A Binding links an exchange to a queue with a routing rule. In Spring you declare each as a @Bean (Queue, DirectExchange, Binding).

open as a page

How do you make Spring create a Kafka topic automatically when the application starts?

level: juniorimportance: must knowfreq 45%
basics
~10 s

Declare a NewTopic as a @Bean (usually built with TopicBuilder). Spring's KafkaAdmin bean scans the context for NewTopic beans at startup and creates any that don't yet exist on the broker.

open as a page

What is Spring Kafka's DefaultErrorHandler and how does it retry a failed record?

level: juniorimportance: must knowfreq 70%
basics
~10 s

DefaultErrorHandler is the container's default handler when a @KafkaListener throws. It re-delivers the failed record several times (using a BackOff for delays), and if all attempts fail it hands the record to a recoverer.

open as a page

What do @KafkaListener and @EnableKafka do, and how do they work together?

level: juniorimportance: must knowfreq 78%
basics
~10 s

@KafkaListener marks a method to consume messages from a Kafka topic. @EnableKafka turns on Spring's infrastructure that finds those methods and starts listener containers to feed them records.

open as a page

How do you enable Kafka Streams in a Spring (Boot) application, and what does @EnableKafkaStreams actually wire up?

level: juniorimportance: must knowfreq 62%
basics
~10 s

Put @EnableKafkaStreams on a @Configuration class and provide a KafkaStreamsConfiguration bean named defaultKafkaStreamsConfig that sets the application.id and bootstrap.servers. Spring then creates a StreamsBuilderFactoryBean that builds and starts Kafka Streams.

open as a page

What is KafkaTemplate and how do you use it to send a message to a Kafka topic in Spring?

level: juniorimportance: must knowfreq 78%
basics
~10 s

KafkaTemplate is Spring's helper for producing messages. You inject it and call template.send("topic", key, value). Spring Boot auto-configures it from application.properties, so you just autowire and send.

open as a page

What is STOMP over WebSocket in Spring, and what does @EnableWebSocketMessageBroker set up?

level: juniorimportance: must knowfreq 70%
basics
~20 s

WebSocket is a raw two-way connection; STOMP is a simple text messaging protocol layered on top that adds destinations (like topics). @EnableWebSocketMessageBroker turns on Spring's message-broker support so clients can subscribe and publish over WebSocket.

open as a page

How do you set up a raw (low-level) WebSocket endpoint in Spring, without STOMP?

level: juniorimportance: must knowfreq 55%
basics
~10 s

Add @EnableWebSocket on a config class that implements WebSocketConfigurer, then override registerWebSocketHandlers to map your handler (a TextWebSocketHandler subclass) to a URL path with registry.addHandler(handler, "/ws").

open as a page

Explain application vs broker destination prefixes and how @MessageMapping / @SendTo route messages.

level: middleimportance: must knowfreq 68%
basics
~20 s

Application prefixes (like /app) route incoming client messages to your @MessageMapping controller methods. Broker prefixes (like /topic, /queue) go straight to the broker for subscription/fan-out. @SendTo names the broker destination the method's return value is published to.

open as a page

Walk through the lifecycle callbacks of a WebSocketHandler / TextWebSocketHandler.

level: middleimportance: must knowfreq 50%
basics
~20 s

afterConnectionEstablished runs when a client connects; handleMessage (or handleTextMessage in TextWebSocketHandler) runs per incoming frame; handleTransportError on I/O errors; afterConnectionClosed when the socket closes. You typically track sessions in the first and remove them in the last.

open as a page

How do user destinations work in Spring STOMP messaging (@SendToUser, /user prefix, convertAndSendToUser)?

level: middleimportance: must knowfreq 65%
basics
~20 s

User destinations let you send to one specific user, not everyone. The client subscribes to /user/queue/... and the server sends via convertAndSendToUser(user, "/queue/...", payload) or returns from a @MessageMapping method annotated @SendToUser. Spring maps it to a session-unique queue.

open as a page

What are the four RSocket interaction models, and how does each map to Reactor return types on a Spring @MessageMapping handler?

level: juniorimportance: must knowfreq 70%
basics
~20 s

Request-response (one in, one out), fire-and-forget (one in, no reply), request-stream (one in, many out), request-channel (many in, many out). In Spring: return Mono for the first two, Flux for streams; a Flux parameter means channel.

open as a page

What does @EnableRSocketSecurity do, and how do you turn on security for an RSocket server in Spring?

level: juniorimportance: must knowfreq 45%
basics
~10 s

@EnableRSocketSecurity turns on Spring Security for RSocket and gives you an RSocketSecurity builder. You use it to create a PayloadSocketAcceptorInterceptor bean that defines who can connect and which routes require authentication.

open as a page

How do you build and use an RSocketRequester in Spring — establishing a connection, attaching route metadata, and choosing the interaction model?

level: middleimportance: should knowfreq 55%
basics
~10 s

Autowire the RSocketRequester.Builder, connect with tcp()/websocket() to get an RSocketRequester. Then call route("path"), data(payload), and a terminal like retrieveMono(), retrieveFlux(), or send() — the terminal picks the interaction model.

open as a page

Explain the difference between securing the SETUP payload and securing REQUEST payloads in RSocket, and how you express each with RSocketSecurity.

level: middleimportance: should knowfreq 35%
basics
~10 s

The SETUP payload authenticates the connection once, when the client establishes it. REQUEST payloads authenticate individual messages/routes. In the authorizePayload DSL you use .setup() for the connection and .route(...)/.anyRequest() for per-message rules.

open as a page

Explain request-channel in Spring RSocket: how the handler is shaped, how backpressure flows both ways, and when to choose it over request-stream.

level: seniorimportance: should knowfreq 35%
basics
~20 s

Request-channel is a two-way stream. The @MessageMapping handler takes a Flux parameter (inbound stream) and returns a Flux (outbound stream); the client passes a Flux to data() and calls retrieveFlux(). Both directions are independent, backpressured Reactive Streams. Choose it when the client must keep sending while receiving.

open as a page