Gregor Hohpe와 Bobby Woolf가 정의한 엔터프라이즈 통합 패턴(EIP)은 메시지 기반 통합의 모범 사례들을 패턴으로 정리한 것입니다. Apache Camel은 이 패턴들을 직접 구현합니다. 이번 글에서는 가장 자주 사용되는 두 패턴을 살펴봅니다.
메시지의 내용이나 헤더 값에 따라 다른 목적지로 전달하는 패턴입니다. Camel에서는 choice()로 구현합니다.
from("direct:orderInput")
.choice()
.when(simple("${body.orderType} == 'VIP'"))
.log("VIP 주문: ${body.customerId}")
.to("direct:vipOrderProcess")
.when(simple("${body.amount} > 1000000"))
.log("대용량 주문")
.to("direct:largeOrderProcess")
.when(header("region").isEqualTo("OVERSEAS"))
.to("direct:overseasOrderProcess")
.otherwise()
.to("direct:normalOrderProcess")
.end()
.log("라우팅 완료"); // Simple 언어
.when(simple("${header.status} == 'APPROVED'"))
// XPath (XML 메시지)
.when(xpath("/order/status = 'approved'"))
// JSONPath (JSON 메시지)
.when(jsonpath("$.order.status == 'approved'"))
// Java Predicate
.when(exchange -> exchange.getIn().getHeader("amount", Integer.class) > 50000)
// SpEL
.when(spel("#{request.headers['priority'] == 'HIGH'"}))
// 정규식
.when(simple("${body} regex '.*URGENT.*'")) 조건을 만족하지 않는 메시지를 완전히 걸러내는 패턴입니다. filter()로 구현합니다.
from("jms:queue:allOrders")
.filter(simple("${body.amount} >= 10000")) // 1만원 이상만 처리
.log("처리 대상 주문: ${body.orderId}")
.to("direct:processOrder");
// 조건 불만족 메시지는 조용히 버려짐 // 복잡한 필터 조건
from("direct:events")
.filter(exchange -> {
String type = exchange.getIn().getHeader("eventType", String.class);
int priority = exchange.getIn().getHeader("priority", 0, Integer.class);
return "ORDER".equals(type) && priority > 5;
})
.to("direct:highPriorityOrders"); 원본 흐름을 방해하지 않고 메시지를 다른 경로로 복사해 보내는 패턴입니다. 감사 로그, 모니터링에 유용합니다.
from("direct:orders")
.wireTap("direct:auditLog") // 비동기로 감사 로그에 복사
.to("direct:processOrder"); // 원본 흐름은 계속 진행
from("direct:auditLog")
.log("감사: ${date:now:yyyy-MM-dd HH:mm:ss} - 주문 ${body.orderId}")
.to("jms:queue:audit"); 하나의 메시지를 여러 엔드포인트에 동시에 전달합니다.
from("direct:newOrder")
.multicast()
.parallelProcessing()
.to("direct:inventory", "direct:billing", "direct:notification")
.end()
.log("모든 처리 완료"); AI가 해킹 도구로 진화했습니다. 27초 만에 공격 코드 작성, AI 봇의 랜섬웨어 협상, GPU 탈취까지—삼성SDS…
필기 시험의 접근통제 영역은 용어 하나만 알아도 풀리는 문제와 개념을 뒤집어 묻는 문제가 섞여 나옵니다.…
유튜브에 AI 자동 생성 영상이 넘쳐납니다. 진짜 크리에이터들은 어떻게 살아남아야 할까요? AI와 경쟁하는 3가지 생존…
이틀 전에 사이드카가 걸렸을 때만 해도 "한 번 놀란 장"으로 끝날 줄 알았는데요. 15일 아침…
오전 시황 글에 이어 장중 후속 정리입니다. 코스피는 개장 직후 5%대였던 낙폭이 오전 10시 전후에…
10월 15일 목요일 아침, 코스피가 전날 종가보다 5.59% 낮은 5,673.01로 출발했습니다. 장 시작 7분 만에…