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 pageshowhide
explore
- Spring Messaging Abstraction15 questions
- Message & MessageHeaders5 questions
- MessageChannel & MessageHandler5 questions
- Messaging vs In-Process Application Events5 questions
- Spring Integration (EIP)25 questions
- Integration Message Channels5 questions
- Endpoints & Service Activators5 questions
- Channel Adapters & Messaging Gateways5 questions
- Integration Java DSL5 questions
- JMS Support20 questions
- JmsTemplate5 questions
- @JmsListener & Listener Containers5 questions
- JMS MessageConverter5 questions
- JMS Transactions5 questions
- Spring AMQP / RabbitMQ25 questions
- RabbitTemplate5 questions
- @RabbitListener & Containers5 questions
- Exchanges, Queues & Bindings5 questions
- Publisher Confirms & Returns5 questions
- Dead-Letter & Retry5 questions
- Spring for Apache Kafka31 questions
- KafkaTemplate & Producers6 questions
- @KafkaListener & Containers5 questions
- Error Handling & Dead-Letter Recovery5 questions
- Kafka Transactions & Exactly-Once5 questions
- Kafka Streams Support5 questions
- KafkaAdmin & Topic Provisioning5 questions
- WebSocket & STOMP Messaging15 questions
- Raw WebSocket Handling5 questions
- STOMP Over WebSocket5 questions
- SockJS Fallback & Messaging Security5 questions
- RSocket Messaging10 questions
- RSocket Security & Transports5 questions
questions
141 · 7 sectionsIn Spring Messaging, what are MessageChannel and MessageHandler, and how do they relate?
basics
~10 sMessageChannel 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.
What is Spring's Message<T> abstraction, and what are its two parts?
basics
~10 sMessage<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).
What is the difference between Spring's ApplicationEventPublisher / @EventListener and the messaging support in spring-messaging (Message / MessageChannel)?
basics
~10 sApplicationEventPublisher 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.
What is the difference between a SubscribableChannel and a PollableChannel (e.g. DirectChannel vs QueueChannel)?
basics
~10 sA 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).
How do you build a Message with custom headers, and why can't you just mutate headers on an existing message?
basics
~10 sUse 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.
In Spring Integration, what is a channel adapter, and what is the difference between an inbound and an outbound channel adapter?
basics
~20 sA 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).
What is a Spring Integration message channel, and what is the difference between point-to-point and publish-subscribe channels?
basics
~10 sA 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.
What does @Transformer do in Spring Integration, and how does a transformer endpoint fit into a message flow?
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.
What is a @ServiceActivator in Spring Integration, and what does it do?
basics
~20 sA @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.
What is the Spring Integration Java DSL and how do you define a basic flow with it?
basics
~10 sIt'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().
What is a JMS MessageConverter in Spring, and what does the default SimpleMessageConverter do?
basics
~10 sA 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.
What do @EnableJms and @JmsListener do, and what is the minimal setup to consume messages from a queue in Spring?
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.
What is Spring's JmsTemplate, and what do convertAndSend and receiveAndConvert do?
basics
~20 sJmsTemplate 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.
What does the sessionTransacted flag do on a JmsTemplate or a JMS listener container, and what is a transacted JMS Session?
basics
~20 sIt 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.
Compare DefaultMessageListenerContainer and SimpleMessageListenerContainer. When would you choose each, and how does concurrency differ?
basics
~20 sDefaultMessageListenerContainer (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.
What is dead-lettering in RabbitMQ/Spring AMQP, and how do you configure a dead-letter exchange on a queue?
basics
~10 sDead-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.
What are RabbitMQ publisher confirms in Spring AMQP, and what problem do they solve?
basics
~20 sBy 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.
What do @RabbitListener and @EnableRabbit do, and how do you turn a method into a RabbitMQ consumer with Spring AMQP?
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.
What is RabbitTemplate and what does convertAndSend(exchange, routingKey, payload) do?
basics
~10 sRabbitTemplate 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.
In Spring AMQP, what are an Exchange, a Queue, and a Binding, and how do you declare each as a Spring bean?
basics
~20 sA 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).
How do you make Spring create a Kafka topic automatically when the application starts?
basics
~10 sDeclare 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.
What is Spring Kafka's DefaultErrorHandler and how does it retry a failed record?
basics
~10 sDefaultErrorHandler 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.
What do @KafkaListener and @EnableKafka do, and how do they work together?
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.
How do you enable Kafka Streams in a Spring (Boot) application, and what does @EnableKafkaStreams actually wire up?
basics
~10 sPut @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.
What is KafkaTemplate and how do you use it to send a message to a Kafka topic in Spring?
basics
~10 sKafkaTemplate 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.
What is STOMP over WebSocket in Spring, and what does @EnableWebSocketMessageBroker set up?
basics
~20 sWebSocket 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.
How do you set up a raw (low-level) WebSocket endpoint in Spring, without STOMP?
basics
~10 sAdd @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").
Explain application vs broker destination prefixes and how @MessageMapping / @SendTo route messages.
basics
~20 sApplication 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.
Walk through the lifecycle callbacks of a WebSocketHandler / TextWebSocketHandler.
basics
~20 safterConnectionEstablished 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.
How do user destinations work in Spring STOMP messaging (@SendToUser, /user prefix, convertAndSendToUser)?
basics
~20 sUser 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.
What are the four RSocket interaction models, and how does each map to Reactor return types on a Spring @MessageMapping handler?
basics
~20 sRequest-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.
What does @EnableRSocketSecurity do, and how do you turn on security for an RSocket server in Spring?
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.
How do you build and use an RSocketRequester in Spring — establishing a connection, attaching route metadata, and choosing the interaction model?
basics
~10 sAutowire 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.
Explain the difference between securing the SETUP payload and securing REQUEST payloads in RSocket, and how you express each with RSocketSecurity.
basics
~10 sThe 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.
Explain request-channel in Spring RSocket: how the handler is shaped, how backpressure flows both ways, and when to choose it over request-stream.
basics
~20 sRequest-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.