- DirectChannel (단순한 동기 채널)
@Bean
public MessageChannel mqttOutboundChannel() {
return new DirectChannel();
}
- 싱글 스레드 동작
- 메시지를 즉시 다음 컴포넌트(예: mqttOutbound()) 로 전달
- 동기 방식(메시지를 보낸 쪽에서 처리가 끝날 때까지 기다림.
- 단순한 로직에서 사용하기 좋음.
- QueueChannel (비동기 메시지 큐)
@Bean
public MessageChannel mqttOutboundChannel() {
return new QueueChannel();
}
- 비동기 처리 가능
- 내부적으로 큐를 사용해서 메시지를 저장 후 순차 처리
- 여러 개의 스레드가 처리할 수 있음.
- 대량의 메시지를 처리해야 하거나, 부하 분산이 필요할 때 유용
- PublishSubscribeChannel (브로드캐스트 방식)
@Bean
public MessageChannel mqttOutboundChannel() {
return new PublishSubscribeChannel();
}
| 개념 | 설명 |
|---|
MessageChannel (Spring Integration 내부 채널) | Spring Integration 내에서 컴포넌트 간 메시지를 전달하는 역할 |
| (ex. Controller → Service) | |
| MQTT Topic (브로커 내에서 메시지 라우팅) | MQTT 브로커에서 클라이언트 간 메시지를 전달하는 용도 |
| (ex. IoT 기기 ↔ 서버) | |
- ExecutorChannel (비동기 + 스레드 풀)
@Bean
public MessageChannel mqttOutboundChannel() {
return new ExecutorChannel(Executors.newCachedThreadPool());
}
- 스레드 풀을 사용해서 메시지를 비동기 처리
- QueueChannel과 달리 대기 없이 바로 작업을 다른 스레드에서 실행.
- 고성능 애플리케이션에서 비동기 처리가 필요한 경우 적합.
- PriorityChannel (우선순위 큐)
@Bean
public MessageChannel mqttOutboundChannel() {
return new PriorityChannel();
}
- 우선순위가 높은 메시지를 먼저 처리
- QueueChannel과 비슷하지만, 메시지를 정렬해서 처리
| 채널 종류 | 동기/비동기 | 특징 | 언제 사용? |
|---|
DirectChannel | 동기 | 즉시 전달 | 기본적인 메시지 처리 |
QueueChannel | 비동기 | 큐를 사용 | 메시지 저장 후 처리 |
PublishSubscribeChannel | 동기/비동기 | 브로드캐스트 | 여러 개의 리스너에게 전달 |
ExecutorChannel | 비동기 | 스레드 풀 사용 | 빠른 비동기 처리 필요할 때 |
PriorityChannel | 비동기 | 우선순위 메시지 처리 | 중요한 메시지를 먼저 처리 |