1. ํ์ ์ฌ์ ์ค์น ์๊ฑด & ๊ฐ๋ฐ ํ๊ฒฝ ๊ตฌ์ฑ (Prerequisites)
๐ป ์์คํ ์ค์น ๋ฐ ์คํ ์๊ตฌ์ฌ์ (System Requirements)
| ํญ๋ชฉ | ์ต์ ์ฌ์ (Minimum) | ๊ถ์ฅ ์ฌ์ (Recommended) | ์ฐธ๊ณ ๋ฐ ๋น๊ณ |
|---|---|---|---|
| ์ด์์ฒด์ (OS) | Windows 10/11, macOS 11+, Linux | Ubuntu 22.04 LTS / macOS Sonoma / Windows 11 | ๋ชจ๋ ํ์ค JVM ํ๊ฒฝ ์ง์ |
| CPU | 2 ์ฝ์ด ์ด์ | 4 ์ฝ์ด ~ 8 ์ฝ์ด ์ด์ | ๋์ฉ๋ ๋ฉ์์ง ๋ฐฐ์น ๋ถํ /์ง๊ณ ๋ฐ ๋ฉํฐ์ค๋ ๋ ํด๋ฌ ์ฒ๋ฆฌ |
| ๋ฉ๋ชจ๋ฆฌ (RAM) | 2 GB ์ด์ | 4 GB ~ 8 GB ์ด์ | ํ ์ฑ๋(QueueChannel) ์ธ๋ฉ๋ชจ๋ฆฌ ๋ฒํผ๋ง ๋ฐ JVM ํ ๊ณต๊ฐ |
| ๋์คํฌ (Storage) | 500 MB ์ด์ ์ฌ์ ๊ณต๊ฐ | 5 GB ์ด์ (SSD ๊ถ์ฅ) | ํ์ผ/SFTP ์ด๋ํฐ ๋ก์ปฌ ์์ ์์ ๋๋ ํ ๋ฆฌ |
| ์๋ฐ & ๋ฐํ์ | Java 17 LTS ์ด์ | Java 21 LTS | Spring Boot 3.x ๋ฐ Spring Integration 6.x ํธํ |
| ๋น๋ ๋๊ตฌ | Gradle 8.x+ ๋๋ Maven 3.8+ | Gradle 8.5+ (Kotlin/Groovy DSL) | spring-boot-starter-integration ์์กด์ฑ |
2. ํต์ฌ ๋ฉํ ๋ชจ๋ธ: ์ํฐํ๋ผ์ด์ฆ ํตํฉ ํจํด(EIP) ํ์ดํ๋ผ์ธ (Mental Model & Architecture)
Spring Integration์ Gregor Hohpe์ ์ํฐํ๋ผ์ด์ฆ ํตํฉ ํจํด(EIP) ์ ์คํ๋ง ํ๋ ์์ํฌ ๊ธฐ๋ฐ์ผ๋ก ๊ตฌํํ์ฌ, ์์คํ ๊ฐ์ ๊ฒฐํฉ๋๋ฅผ ๋ฎ์ถ๊ณ ๋ฉ์์ง ๊ธฐ๋ฐ์ ์ด๋ฒคํธ ํ์ดํ๋ผ์ธ์ ๊ตฌ์ถํฉ๋๋ค.
+-----------------------------------------------------------------------------------+
| Message Producer / Inbound Adapter |
| File Watcher, HTTP Inbound, Kafka Topic, or @MessagingGateway ํธ์ถ |
+-----------------------------------------------------------------------------------+
โ
โผ
+-----------------------------------------------------------------------------------+
| Spring Message Structure (๋ถ๋ณ ๊ฐ์ฒด) |
| - Message Headers: ID, Timestamp, CorrelationId, ReplyChannel, CustomHeaders |
| - Message Payload: <T> (์ค์ ๋น์ฆ๋์ค ๋ฐ์ดํฐ ๊ฐ์ฒด ๋๋ byte[] / String) |
+-----------------------------------------------------------------------------------+
โ
โผ
+-----------------------------------------------------------------------------------+
| Message Channel (๋ฉ์์ง ์ ์ก ํต๋ก) |
| [DirectChannel] ๋จ์ผ ์ค๋ ๋ ๋๊ธฐ์ Point-to-Point (๊ธฐ๋ณธ๊ฐ) |
| [QueueChannel] ์ธ๋ฉ๋ชจ๋ฆฌ FIFO ๋ฒํผ๋ง ๋น๋๊ธฐ ์ฑ๋ (Backpressure) |
| [PublishSubscribeChannel] 1:N ๋ธ๋ก๋์บ์คํธ ๋ธ๋ก๋์บ์คํ
์ฑ๋ |
+-----------------------------------------------------------------------------------+
โ
EIP Core Endpoints (๋ณํ, ํํฐ๋ง, ๋ผ์ฐํ
, ๋ถํ & ์ง๊ณ)
โผ
+โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ+
| .filter(...) --> ์กฐ๊ฑด์ ๋ง์ง ์๋ ๋ถ๋ ๋ฉ์์ง ํ๊ธฐ ๋๋ discardChannel ํ |
| .transform(...) --> ๋ฐ์ดํฐ ํฌ๋งท ๋ณํ (JSON <-> DTO, ๋ณตํธํ, ๋์๋ฌธ์) |
| .split(...) --> ๋ฆฌ์คํธ/๋ฐฐ์ด ํ์ด๋ก๋๋ฅผ ๋จ์ผ ๋ฉ์์ง๋ค๋ก ์ชผ๊ฐ๊ธฐ |
| .aggregate(...) --> ์๊ด๊ด๊ณ(CorrelationId) ๊ธฐ๋ฐ์ผ๋ก ์ฒ๋ฆฌ ๊ฒฐ๊ณผ ๋ฌถ๊ธฐ |
| .route(...) --> ํค๋/ํ์ด๋ก๋ ์กฐ๊ฑด์ ๋ฐ๋ผ ๋ชฉ์ ์ง ์ฑ๋ ๋์ ๋ถ๊ธฐ |
+โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ+
โ
โผ
+-----------------------------------------------------------------------------------+
| Service Activator / Outbound Channel Adapter |
| ๋น์ฆ๋์ค ์๋น์ค ๋ฉ์๋ ์คํ, DB ์์ํ, ์ธ๋ถ REST API ๋๋ ํ์ผ ์ ์ฅ |
+-----------------------------------------------------------------------------------+
3. ๋จ๊ณ๋ณ ์ค์ต ๊ฐ์ด๋ (Step-by-Step Walkthrough)
[์ด๋ณด์ 1๋จ๊ณ] ํฌ๋ก์๋: IntegrationFlow์ ๊ฒ์ดํธ์จ์ด ํ์ดํ๋ผ์ธ
๋จ์ํ๊ณ ์ง๊ด์ ์ธ Java DSL๋ก ๋ฉ์์ง๋ฅผ ์์ ํ์ฌ ๋๋ฌธ์๋ก ๋ณํํ ๋ค ๋ก๊น ํ๋ ํ์ดํ๋ผ์ธ์ ๊ตฌ์ถํฉ๋๋ค.
1) ๋น๋ ์์กด์ฑ ์ถ๊ฐ (build.gradle)
// build.gradle
plugins {
id 'java'
id 'org.springframework.boot' version '3.3.4'
id 'io.spring.dependency-management' version '1.1.6'
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-integration'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.integration:spring-integration-test'
}
2) ๋ฉ์์ง ๊ฒ์ดํธ์จ์ด ์ธํฐํ์ด์ค ์ ์
ํด๋ผ์ด์ธํธ ์ฝ๋๊ฐ ์คํ๋ง ์ธํฐ๊ทธ๋ ์ด์ ์ ๋ด๋ถ ๋ณต์ก๋๋ฅผ ๋ชฐ๋ผ๋ ์๋ฐ ๋ฉ์๋ ํธ์ถ์ฒ๋ผ ์ฌ์ฉํ ์ ์๊ฒ ํด์ฃผ๋ ์ง์ ์ ์ ๋๋ค.
package com.lucky.integration;
import org.springframework.integration.annotation.Gateway;
import org.springframework.integration.annotation.MessagingGateway;
@MessagingGateway
public interface TextOrderGateway {
// textInputChannel๋ก ๋ฉ์์ง๋ฅผ ๋ฐํํ๊ณ ์ต์ข
๊ฒฐ๊ณผ๋ฅผ ๋๊ธฐ์์ผ๋ก ๋ฐํ๋ฐ์
@Gateway(requestChannel = "textInputChannel")
String processText(String rawText);
}
3) Java DSL ๊ธฐ๋ฐ IntegrationFlow ๊ตฌ์ฑ ๋ฐ ๋ฉ์ธ ์คํ ํด๋์ค
package com.lucky.integration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.integration.annotation.IntegrationComponentScan;
import org.springframework.integration.dsl.IntegrationFlow;
import org.springframework.integration.dsl.MessageChannels;
import org.springframework.messaging.MessageChannel;
@SpringBootApplication
@IntegrationComponentScan
public class SpringIntegrationApplication {
private static final Logger log = LoggerFactory.getLogger(SpringIntegrationApplication.class);
public static void main(String[] args) {
SpringApplication.run(SpringIntegrationApplication.class, args);
}
// 1. ์ง์
์ DirectChannel ๋น ๋ฑ๋ก
@Bean
public MessageChannel textInputChannel() {
return MessageChannels.direct().getObject();
}
// 2. ๋จ์ผ Java DSL ํ์ดํ๋ผ์ธ ํ๋ฆ ์ ์
@Bean
public IntegrationFlow uppercaseFlow() {
return IntegrationFlow.from(textInputChannel())
// 1๋จ๊ณ: ๋ฌธ์์ด ํ์ด๋ก๋๋ฅผ ๋๋ฌธ์๋ก ๋ณํ (Transformer)
.<String, String>transform(String::toUpperCase)
// 2๋จ๊ณ: ๋ก๊ทธ ์ถ๋ ฅ ๋ฐ ์ต์ข
๊ฒฐ๊ณผ ๋ฐํ (Service Activator)
.handle((payload, headers) -> {
log.info("์ต์ข
์ฒ๋ฆฌ๋ ํ์ด๋ก๋: {}", payload);
return "PROCESSED: " + payload;
})
.get();
}
// 3. ๊ธฐ๋ ์ฆ์ ํ
์คํธ ๋ฉ์์ง ๋ฐํ
@Bean
public CommandLineRunner runner(TextOrderGateway gateway) {
return args -> {
String result = gateway.processText("hello luckytechworld integration");
log.info("๊ฒ์ดํธ์จ์ด ๋ฐํ๊ฐ: {}", result);
};
}
}
์์ ์ฝ์ ์ถ๋ ฅ ๋ก๊ทธ(Output):
[main] c.l.i.SpringIntegrationApplication : ์ต์ข
์ฒ๋ฆฌ๋ ํ์ด๋ก๋: HELLO LUCKYTECHWORLD INTEGRATION
[main] c.l.i.SpringIntegrationApplication : ๊ฒ์ดํธ์จ์ด ๋ฐํ๊ฐ: PROCESSED: HELLO LUCKYTECHWORLD INTEGRATION
[2๋จ๊ณ] ํต์ฌ EIP ํจํด: ๋ผ์ฐํ (Router), ๋ถํ (Splitter) & ์ง๊ณ(Aggregator)
์ค๋ฌด์์ ์์ฃผ ์ฐ์ด๋ ์ฃผ๋ฌธ ๋ฐ์ดํฐ ๋ถํ ์ฒ๋ฆฌ ๋ฐ ์ฐ์ ์์ ๋ผ์ฐํ ํจํด์ ๋๋ค.
package com.lucky.integration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.dsl.IntegrationFlow;
import org.springframework.integration.dsl.MessageChannels;
import java.util.List;
@Configuration
public class AdvancedEipFlowConfig {
private static final Logger log = LoggerFactory.getLogger(AdvancedEipFlowConfig.class);
public record OrderItem(String id, int amount, String category) {}
@Bean
public IntegrationFlow orderBatchFlow() {
return IntegrationFlow.from("orderBatchInputChannel")
// [Splitter] List<OrderItem> ๋ชฉ๋ก์ ๊ฐ๊ฐ์ ๋จ์ผ OrderItem ๋ฉ์์ง๋ก ์ชผ๊ฐฌ
.split()
// [Filter] 1000์ ์ดํ์ ๋ฌดํจ ์ฃผ๋ฌธ์ ํ๊ธฐ
.<OrderItem>filter(item -> item.amount() > 1000,
f -> f.discardChannel("discardLogChannel"))
// [Router] ์นดํ
๊ณ ๋ฆฌ์ ๋ฐ๋ผ ์๋ก ๋ค๋ฅธ ์ฒ๋ฆฌ ์ฑ๋๋ก ๋์ ๋ถ๊ธฐ
.<OrderItem, String>route(
OrderItem::category,
mapping -> mapping
.subFlowMapping("VIP", sf -> sf.handle(m -> log.info("[VIP ํน๊ธ ๋ฐฐ์ก] {}", m.getPayload())))
.subFlowMapping("NORMAL", sf -> sf.handle(m -> log.info("[์ผ๋ฐ ๋ฐฐ์ก] {}", m.getPayload())))
.defaultOutputToParentFlow()
)
// [Aggregator] ๋ถํ ๋์๋ ์ฃผ๋ฌธ ํญ๋ชฉ๋ค์ ๋ค์ ๋จ์ผ ๋ฆฌ์คํธ๋ก ๋ณํฉ
.aggregate()
.handle(m -> log.info("๋ฐฐ์น ์ฃผ๋ฌธ ์ ์ฒด ์ง๊ณ ์๋ฃ: ์ด {}๊ฑด", ((List<?>) m.getPayload()).size()))
.get();
}
@Bean
public IntegrationFlow discardLogFlow() {
return IntegrationFlow.from(MessageChannels.direct("discardLogChannel"))
.handle(m -> log.warn("์ต์ ๊ธ์ก ๋ฏธ๋ฌ๋ก ์ฃผ๋ฌธ ํ๊ธฐ: {}", m.getPayload()))
.get();
}
}
[3๋จ๊ณ] ์ค๋ฌด ์์ฉ ํจํด: ํ์ผ ์์คํ ํด๋ง ์ด๋ํฐ & ๊ธ๋ก๋ฒ ์๋ฌ ํธ๋ค๋ง
ํน์ ๋๋ ํ ๋ฆฌ์ ์๋ก์ด ํ์ผ์ด ์์ฑ๋๋ฉด ๊ฐ์งํ์ฌ ์ฝ๊ณ , ์คํจ ์ errorChannel๋ก ๊ฒฉ๋ฆฌํ๋ ํ๋ก๋์
ํจํด์
๋๋ค.
package com.lucky.integration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.dsl.IntegrationFlow;
import org.springframework.integration.dsl.Pollers;
import org.springframework.integration.file.dsl.Files;
import org.springframework.messaging.MessageHandlingException;
import java.io.File;
@Configuration
public class FilePollerFlowConfig {
private static final Logger log = LoggerFactory.getLogger(FilePollerFlowConfig.class);
// 1. ๋ก์ปฌ ๋๋ ํ ๋ฆฌ ๊ฐ์ ์ธ๋ฐ์ด๋ ํ์ผ ์ด๋ํฐ
@Bean
public IntegrationFlow fileReadingFlow() {
return IntegrationFlow.from(
Files.inboundAdapter(new File("/data/incoming-orders"))
.patternFilter("*.csv")
.preventDuplicates(true),
// 3์ด ์ฃผ๊ธฐ๋ก ํด๋งํ๋ฉฐ ์ต๋ 10๊ฐ ํ์ผ์ฉ ๋ฐฐ์น ์ฒ๋ฆฌ
e -> e.poller(Pollers.fixedDelay(3000).maxMessagesPerPoll(10))
)
// ํ์ผ ๋ด์ฉ์ ๋ฌธ์์ด๋ก ์๋ ๋ณํ
.transform(Files.toStringTransformer())
.handle(message -> {
String content = (String) message.getPayload();
log.info("CSV ์์ ์๋ฃ (๊ธธ์ด: {}์)", content.length());
if (content.contains("ERROR_TRIGGER")) {
throw new IllegalArgumentException("๋ถ๋ ์ฃผ๋ฌธ ํ์ผ ๊ฐ์ง!");
}
})
.get();
}
// 2. ํ์ดํ๋ผ์ธ ์์ธ ๋ฐ์ ์ ํธ์ถ๋๋ ๊ธ๋ก๋ฒ ์๋ฌ ์ฑ๋
@Bean
public IntegrationFlow globalErrorHandlingFlow() {
return IntegrationFlow.from("errorChannel")
.handle(message -> {
MessageHandlingException ex = (MessageHandlingException) message.getPayload();
log.error("ํตํฉ ํ์ดํ๋ผ์ธ ์ฅ์ ๋ฐ์! ์คํจ ๋ฉ์์ง: {}, ์์ธ: {}",
ex.getFailedMessage(), ex.getMessage());
// ๊ด๋ฆฌ์ ์๋ฆผ ๋๋ Dead Letter Queue(DLQ) ์ ์ฌ ๋ก์ง ์ํ
})
.get();
}
}
4. ์ค๋ฌด ์ฃผ์์ฌํญ & ํ๋ก๋์ ์ฒดํฌ๋ฆฌ์คํธ
| ์ ๊ฒ ํญ๋ชฉ | ๊ถ์ฅ ์ง์นจ ๋ฐ ํด๊ฒฐ์ฑ | ์๋ฐ ์ ์ ์ฌ ์ํ |
|---|---|---|
| ์ธ๋ฐ์ด๋ ์ด๋ํฐ Poller ๋๋ฝ | Files.inboundAdapter ๋ฑ ์๊ทน์ ์์ ์ปดํฌ๋ํธ๋ ๋ฐ๋์ poller() ์ค์ ๋ช
์ | ์ ํ๋ฆฌ์ผ์ด์
๊ธฐ๋ ์ IllegalArgumentException: No poller has been defined ์๋ฌ๋ก ์ปจํ
์คํธ ๋ก๋ฉ ์คํจ |
DirectChannel vs QueueChannel | I/O ์ง์ฐ์ด ํฐ ์์
์ QueueChannel + TaskExecutor๋ก ๋ฐฑํ๋ ์
๋ฒํผ ๋ถ๋ฆฌ | ๋ชจ๋ ์์ ์ด ํธ์ถ์ ์ค๋ ๋(DirectChannel)์์ ๋๊ธฐ ์คํ๋์ด ์น ์์ฒญ ์ค๋ ๋ ํ ๊ณ ๊ฐ |
| ๋ฉ์์ง ๋ถ๋ณ์ฑ(Immutability) ์ค์ | ๊ธฐ์กด ๋ฉ์์ง์ ํค๋๋ ํ์ด๋ก๋๋ฅผ ์์ ํ ๋๋ ๋ฐ๋์ MessageBuilder.fromMessage(m) ํ์ฉ | ๋ฉ์์ง ๊ฐ์ฒด๋ฅผ ์ง์ ์์ ํ๋ ค๊ณ ์๋ ์ ์ํ ์๊ณก ๋ฐ ๋ฉํฐ์ค๋ ๋ ๋์์ฑ ๋ฒ๊ทธ ๋ฐ์ |
๊ธ๋ก๋ฒ errorChannel ๊ตฌ์ฑ | ๋ชจ๋ ๋น๋๊ธฐ ์ฑ๋ ํ๋ฆ์๋ ๋ฐ๋์ errorChannel ๊ตฌ๋
๋ฆฌ์ค๋ ๋ฑ๋ก | ๋น๋๊ธฐ ํ ์ค๋ ๋์์ ๋ฐ์ํ ์์ธ๊ฐ ์คํํธ๋ ์ด์ค ์์ด ์ฆ๋ฐํ์ฌ ์ฅ์ ์์ธ ๋ถ์ ๋ถ๊ฐ |
| ๋ฉฑ๋ฑ์ฑ(Idempotent) ์ค๋ณต ์์ ๋ฐฉ์ง | ํ์ผ/๋ฉ์์ง ์์ ์ IdempotentReceiverInterceptor ๋๋ ์ค๋ณต ๋ฐฉ์ง ํํฐ ์ ์ฉ | ๋์ผ ํ์ผ์ด๋ ์ค๋ณต ์ด๋ฒคํธ ์์ ์ ๊ฒฐ์ /์ฃผ๋ฌธ์ด ์ค๋ณต ์ฒ๋ฆฌ๋๋ ์ฌ๊ฐํ ๋น์ฆ๋์ค ์ค๋ฅ ๋ฐ์ |
์๊ฒฌ ๋ฐ ์ง๋ฌธ
0์์ง ๋ฑ๋ก๋ ์๊ฒฌ์ด ์์ต๋๋ค. ์ฒซ ๋ฒ์งธ ๋๊ธ์ ๋จ๊ฒจ๋ณด์ธ์!
๋๊ธ ์์
๋๊ธ ์ญ์