CamelContext
. Camel의 핵심 런타임 API로 컴포넌트, 프로세서, Endpoint, 데이터타입, 라우팅 등을 관리
. CamelContext에 의해서 다양한 모듈이 로딩되고 관리된다.
. RouteBuilder가 Route를 객체화하여 Context에 binding
** Registry: JNDI registry로, Spring으로 camel을 사용하면 ApplicationContext가 되고 OSGI 컨테이너에 camel을 탑재해 사용하면 OSGI registry가 됨
Route
. 컴포넌트, 프로세서들의 연속적인 메시지 연결 정의
. 송신 Component → Proceessor → 수신 Comonent로 하나의 Route가 정의됨
. 1:1 혹은 1:N, N:1 등 다양하게 정의될 수 있다
. https://camel.apache.org/manual/routes.html
Component
. 일종의 아답터 개념
. Endpoint URL을 가지는 Camel이 메시지를 라우팅 할 수 있는 프로그램 단위
. 통신 프로토콜을 구현한 컴포넌트, 파일시스템 연동을 구현한 컴포넌트 등 자주 사용되는 거의 대부분의 기술에 대해 이미 제작되어있는 Component를 지원함
. 맞춤 Component 작성 기능도 제공
. 동일한 접근법과 구문을 사용하여 서로 다른 기술에 대한 인터페이스 제공 → 어떤 종류의 Transport가 사용되는지에 관계없이 동일한 API로 작업할 수 있게 해줌
. https://camel.apache.org/components/next/
Processor
. Camel 내부에서 메시지를 생성, 형식 변환, 수정, 검증, 필터링 등의 작업을 하여 다른 컴포넌트로 라우팅하는 모듈
. Camel은 EIP 패턴에 기반한 메시지 프로세싱을 지원한다
. Java 인터페이스를 구현해 메시지에 대한 거의 모든 처리를 구현할 수 있음
. https://camel.apache.org/manual/processor.html
CamelContext 생성 예시
https://www.tutorialspoint.com/apache_camel/apache_camel_camelcontext.htm
1) with simple route/simple filter
CamelContext context = new DefaultCamelContext(); // CarnmelContext 생성
try {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception { // 하나의 configure 매소드에 여러 route 설정 가능
from("direct:DistributeOrderDSL") // .xml을 사용한 Spring DSL이나 Scala DSL 등도 사용 가능
.split(xpath("//order[@product = 'soaps']/items")) // 상품이 "비누"인 경우만 filter
.to("stream:out"); } }
} );
2) with simple route/multiple-predicates filter
from("direct:DistributeOrderDSL")
.choice()
.when(header("order").isEqualTo("oil"))
.to("direct:oil")
.when(header("order").isEqualTo("milk"))
.to("direct:milk")
.otherwise()
.to("direct:d");
3) with simple route/simple filter/custom processor
Processor myCustomProcessor = new Processor() {
public void process(Exchange exchange) {
// implement your custom processing
}
};
CamelContext context = new DefaultCamelContext();
try {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:DistributeOrderDSL")
.split(xpath("//order[@product = 'soaps']/items"))
.process(myProcessor);}
} );
DSL(Domain Specific Language)
. 컴포넌트와 프로세서를 통해 라우트 구성을 정의하기 위해 사용하는 언어
. DSL을 통해 다양한 동적 라우팅 및 메시지 변환 등 프로그래밍 요소를 삽입 가능
. DSL은 Route의 Processor 부분을 정의하는데 주로 사용되는데, 송/수신 Component만 정의되면 사실상 시스템 연계에서 구현해야 되는 부분은 거의 Processor이며
Processor의 로직 대부분은 메세지 처리/변환/라우팅에 해당하는 내용이기 때문에 특수 목적의 DSL을 사용할 수 있으며 DSL 사용을 통해서 개발 생산성이나 코드양을 획기적으로 줄일 수 있음
. http://camel.apache.org/dsl.html
EndPoint
. Camel에서 라우팅을 위해 URI 형태로 기술한 컴포넌트 주소
. 웹 서비스 URI, 대기열(queue) URI, 파일, 전자 메일 주소 등을 참조 가능
. DSL에서 from() 안에 사용되는 엔드포인트를 Consumer 엔드포인트, to() 안에 사용되는 것을 Producer 엔드포인트라고 함
. https://camel.apache.org/manual/endpoint.html
Producer
. Endpoint에 메시지를 생성, 전달하는 개체(송신측)
Consumer
. Producer에 의해 생성된 메시지를 수신하는 개체(수신측)
. 수신 후 Exchange를 생성하여 라우터에 던져준다
'~2022 > Apache Camel' 카테고리의 다른 글
[Apache Camel] Feature (0) | 2022.03.12 |
---|---|
[Apache Camel] Overview (0) | 2022.03.12 |