Spring Integration Message Adapters Interview Questions and Answers
Master Spring Integration Message Adapters with interview questions covering inbound adapters, outbound adapters, HTTP, File, FTP/SFTP, JDBC, JMS, Kafka, AMQP adapters, polling, and production best practices.
Introduction
Enterprise applications communicate with numerous external systems.
Examples include:
- REST APIs
- Databases
- Kafka
- RabbitMQ
- FTP/SFTP Servers
- File Systems
- JMS Brokers
- Email Servers
- Cloud Storage
Business services should never communicate directly with these systems.
Spring Integration provides Message Adapters that bridge external systems with the messaging infrastructure.
Adapters convert external events into Spring Integration messages and vice versa.
Message Adapter Architecture
flowchart LR
ExternalSystem --> InboundAdapter
InboundAdapter --> MessageChannel
MessageChannel --> IntegrationFlow
IntegrationFlow --> OutboundAdapter
OutboundAdapter --> ExternalSystem2
Q1. What is a Message Adapter?
Answer
A Message Adapter connects an external system with a Spring Integration flow.
It acts as a bridge between
- External protocols
- Spring Messages
Benefits
- Loose coupling
- Protocol abstraction
- Reusable integration flows
- Easier maintenance
Q2. What are the two types of Message Adapters?
Spring Integration provides
| Adapter | Purpose |
|---|---|
| Inbound Adapter | External System → Spring Integration |
| Outbound Adapter | Spring Integration → External System |
Adapter Flow
flowchart LR
ExternalSystem --> InboundAdapter
InboundAdapter --> IntegrationFlow
IntegrationFlow --> OutboundAdapter
OutboundAdapter --> ExternalSystem
Q3. What is an Inbound Adapter?
An Inbound Adapter receives data from external systems and converts it into Spring Messages.
Examples
- File Reader
- Kafka Consumer
- JMS Consumer
- FTP Poller
- HTTP Endpoint
Example
IntegrationFlows
.from(
Files.inboundAdapter(
inputDir))
Inbound Adapter
flowchart LR
FileSystem --> FileAdapter
FileAdapter --> MessageChannel
Q4. What is an Outbound Adapter?
An Outbound Adapter sends Spring Messages to external systems.
Examples
- Kafka Producer
- JMS Producer
- FTP Writer
- Email Sender
- HTTP Client
Example
.handle(
Kafka.outboundChannelAdapter())
Outbound Adapter
flowchart LR
MessageChannel --> KafkaAdapter
KafkaAdapter --> Kafka
Q5. What adapters are commonly used?
Popular adapters
| Adapter | Purpose |
|---|---|
| File | Read and write files |
| HTTP | REST communication |
| FTP/SFTP | File transfer |
| JDBC | Database integration |
| JMS | Messaging |
| Kafka | Event streaming |
| AMQP | RabbitMQ integration |
| Email integration | |
| TCP/UDP | Socket communication |
| WebSocket | Real-time communication |
Spring Integration offers adapters for most enterprise protocols.
Q6. How does a File Adapter work?
Inbound
File
↓
Message
Outbound
Message
↓
File
File Adapter
flowchart TD
Directory --> FileInboundAdapter
FileInboundAdapter --> Processing
Processing --> FileOutboundAdapter
FileOutboundAdapter --> Archive
Useful for
- CSV processing
- Batch imports
- ETL jobs
Q7. How does Kafka Adapter work?
Inbound
Kafka Topic
↓
Spring Message
Outbound
Spring Message
↓
Kafka Topic
Kafka Adapter
flowchart LR
Kafka --> KafkaInbound
KafkaInbound --> Channel
Channel --> KafkaOutbound
KafkaOutbound --> Kafka
Supports event-driven architectures.
Q8. What is Polling?
Some adapters continuously poll external systems.
Example
.poller(
Pollers
.fixedDelay(
5000))
The adapter checks for new data every five seconds.
Polling is commonly used with
- Files
- FTP
- JDBC
Q9. Adapter vs Gateway
| Adapter | Gateway |
|---|---|
| Connects external systems | Entry point into flow |
| Protocol conversion | Method invocation |
| Infrastructure component | Business interface |
| External communication | Internal communication |
Gateways expose Java methods.
Adapters communicate with external technologies.
Q10. Adapter Best Practices
Keep Adapters Thin
Perform protocol handling only.
Use Transformers
Convert external formats into domain objects.
Avoid Business Logic
Adapters should never contain business rules.
Configure Pollers Carefully
Avoid excessive polling frequency.
Handle Errors Centrally
Route failures to dedicated error channels.
Banking Example
flowchart TD
SFTPServer --> FileInboundAdapter
FileInboundAdapter --> PaymentChannel
PaymentChannel --> Transformer
Transformer --> PaymentService
PaymentService --> KafkaOutboundAdapter
KafkaOutboundAdapter --> Kafka
PaymentService --> Database
Database --> JDBCOutboundAdapter
The adapters isolate protocol-specific communication from business processing.
Common Interview Questions
- What is a Message Adapter?
- Inbound vs Outbound Adapter?
- File Adapter?
- HTTP Adapter?
- Kafka Adapter?
- JMS Adapter?
- JDBC Adapter?
- What is Polling?
- Adapter vs Gateway?
- Adapter best practices?
Quick Revision
| Adapter | Purpose |
|---|---|
| Inbound Adapter | External → Spring |
| Outbound Adapter | Spring → External |
| File Adapter | File integration |
| HTTP Adapter | REST integration |
| FTP/SFTP Adapter | File transfer |
| Kafka Adapter | Event streaming |
| JMS Adapter | Messaging |
| JDBC Adapter | Database integration |
| Poller | Scheduled retrieval |
| Gateway | Java interface |
Message Adapter Lifecycle
sequenceDiagram
External System->>Inbound Adapter: New Data
Inbound Adapter->>Message Channel: Spring Message
Message Channel->>Integration Flow: Process
Integration Flow->>Outbound Adapter: Result
Outbound Adapter->>External System: Send Data
Production Example – Banking Payment File Processing
A bank receives payment instruction files from corporate customers through SFTP.
Workflow
- An SFTP Inbound Adapter polls the server every minute.
- Downloaded files are converted into Spring messages.
- A Transformer converts CSV records into
PaymentRequestobjects. - A Service Activator validates and processes each payment.
- Successful transactions are published using a Kafka Outbound Adapter.
- Audit records are stored using a JDBC Outbound Adapter.
- A File Outbound Adapter archives processed files.
IntegrationFlows
.from(
Sftp.inboundAdapter(sessionFactory),
e -> e.poller(
Pollers.fixedDelay(60000)
)
)
.channel("paymentChannel");
flowchart LR
CorporateSFTP --> SFTPInboundAdapter
SFTPInboundAdapter --> PaymentChannel
PaymentChannel --> CSVTransformer
CSVTransformer --> PaymentService
PaymentService --> KafkaOutboundAdapter
KafkaOutboundAdapter --> Kafka
PaymentService --> JDBCOutboundAdapter
JDBCOutboundAdapter --> PostgreSQL
PaymentService --> FileOutboundAdapter
FileOutboundAdapter --> ArchiveFolder
This architecture isolates protocol-specific communication from business logic, enabling scalable, reusable, and maintainable enterprise integration.
Key Takeaways
- Message Adapters connect Spring Integration with external systems such as files, databases, messaging brokers, and REST services.
- Inbound Adapters convert external events into Spring messages, while Outbound Adapters send Spring messages to external systems.
- Spring Integration provides adapters for File, HTTP, FTP/SFTP, JDBC, JMS, Kafka, AMQP, Mail, TCP, and many other protocols.
- Polling is commonly used by inbound adapters that monitor external resources such as directories, FTP servers, and databases.
- Adapters should focus only on protocol conversion and communication, leaving business logic to Service Activators.
- Combining adapters with transformers, routers, and channels results in highly modular and reusable integration flows.
- Proper polling intervals, centralized error handling, and monitoring are essential for production deployments.
- Message Adapters are fundamental building blocks for integrating enterprise applications with diverse external systems.