Camel 아키텍처 전체 그림
Apache Camel은 몇 가지 핵심 개념들이 유기적으로 연결되어 동작합니다. 이 구조를 이해하면 Camel로 어떤 통합 시나리오도 설계할 수 있게 됩니다.
CamelContext – 모든 것의 중심
CamelContext는 Camel 런타임의 핵심입니다. 마치 Spring의 ApplicationContext처럼, Camel에서 사용하는 모든 자원을 관리합니다.
- 라우트 등록 및 생명주기 관리
- 컴포넌트 레지스트리
- 타입 컨버터 레지스트리
- 데이터 포맷 레지스트리
- 언어(Language) 레지스트리
// CamelContext 직접 접근 (Spring Boot에서)
@Autowired
CamelContext camelContext;
// 라우트 목록 조회
camelContext.getRoutes().forEach(r -> System.out.println(r.getId()));
Component – 기술 통합의 단위
Component는 특정 기술이나 프로토콜에 대한 통합 기능을 제공하는 플러그인입니다. 예를 들어:
camel-http: HTTP 통신camel-jms: JMS 메시징camel-kafka: Apache Kafkacamel-aws-s3: Amazon S3
각 Component는 URI 스킴(scheme)으로 식별됩니다. http://...이면 HTTP 컴포넌트, jms:queue:...이면 JMS 컴포넌트가 사용됩니다.
Endpoint – 통신 채널의 구체적인 주소
Endpoint는 시스템에 대한 구체적인 연결 지점입니다. URI로 표현됩니다.
// Endpoint URI 구조
scheme:contextPath?option1=value1&option2=value2
// 예시들
"file:orders/inbox?noop=true"
"jms:queue:payments?concurrentConsumers=5"
"http://api.example.com/data?bridgeEndpoint=true"
"timer:tick?period=1000&delay=500"
Route – 데이터 흐름의 정의
Route는 메시지가 어디서 시작해서 어떤 처리를 거쳐 어디로 가는지를 정의합니다. RouteBuilder로 구성하며, 하나의 CamelContext는 여러 Route를 가질 수 있습니다.
@Component
public class OrderRoute extends RouteBuilder {
@Override
public void configure() {
from("file:orders/inbox?noop=true")
.routeId("order-processor") // 라우트 ID 지정
.log("주문 파일 수신: ${header.CamelFileName}")
.to("jms:queue:orders");
from("jms:queue:orders")
.routeId("order-handler")
.log("주문 처리 시작")
.to("direct:process");
}
}
Processor – 메시지 처리의 기본 단위
Processor는 Exchange를 받아 처리하는 함수형 인터페이스입니다. 라우트의 각 단계에서 사용됩니다.
public class OrderProcessor implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
String body = exchange.getIn().getBody(String.class);
// 커스텀 처리 로직
exchange.getIn().setBody(body.toUpperCase());
}
}
아키텍처 관계 요약
- CamelContext → Component들을 관리
- Component → Endpoint를 생성
- Endpoint → Consumer(수신) 또는 Producer(발신)를 생성
- Route → Consumer + Processor 체인 + Producer로 구성
- Exchange → Route를 따라 Processor들을 통과하며 흐름
이 개념들이 Camel의 근간입니다. 다음 파트에서는 실제 라우팅을 깊이 있게 다룹니다.