Apache Velocity는 Java 기반 템플릿 엔진입니다. 정해진 형식에 동적 데이터를 채워 넣어야 할 때(이메일 본문, 보고서, XML 요청 등) 매우 유용합니다. Camel은 Velocity와의 통합을 기본으로 제공합니다.
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-velocity-starter</artifactId>
</dependency> ## src/main/resources/templates/order-email.vm
안녕하세요, ${body.customerName}님!
주문 접수 확인 메일입니다.
주문 정보:
- 주문 번호: ${body.orderId}
- 주문 일시: $date
- 상품: #foreach($item in $body.items)
* ${item.productName} x ${item.quantity} = ${item.subtotal}원
#end
- 총 금액: ${body.totalAmount}원
배송 주소: ${headers.deliveryAddress}
감사합니다! from("direct:sendOrderConfirmation")
.to("velocity:templates/order-email.vm") // 템플릿 적용
.log("이메일 내용 생성 완료")
.to("smtp://mail.example.com?to=${header.customerEmail}"); 템플릿에서 접근 가능한 기본 변수들:
${body}: 메시지 본문 객체${headers}: 메시지 헤더 Map${header.xxx}: 특정 헤더 값${exchange}: Exchange 객체 전체${camelContext}: CamelContext$date: 현재 날짜 (VelocityTools)## soap-request.vm
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<OrderRequest xmlns="http://example.com/orders">
<OrderId>${body.orderId}</OrderId>
<CustomerId>${body.customerId}</CustomerId>
<Amount>${body.amount}</Amount>
<Currency>${header.currency}</Currency>
</OrderRequest>
</soap:Body>
</soap:Envelope> from("direct:callSoap")
.to("velocity:soap-request.vm")
.setHeader(Exchange.HTTP_METHOD, constant("POST"))
.to("http://legacy-service/soap?bridgeEndpoint=true"); Velocity 대신 FreeMarker 템플릿 엔진도 사용할 수 있습니다.
<!-- FreeMarker 의존성 -->
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-freemarker-starter</artifactId>
</dependency> // FreeMarker 사용 (동일한 방식)
from("direct:generateReport")
.to("freemarker:templates/report.ftl")
.to("file:reports?fileName=report_${date:now:yyyyMMdd}.html"); // Mustache - Logic-less 템플릿
from("direct:mustache")
.to("mustache:templates/notification.mustache"); 코스피 8% 폭락, 서킷브레이커 발동, SK텔레콤 Claude AI 차단까지. 한국의 AI 레버리지 버블이 단 하루…
SNS 사진 1장으로 30초 만에 딥페이크 영상이 완성됩니다. 당신의 얼굴이 이미 범죄에 악용되고 있을 수…
SNS 사진 1장으로 30초 만에 딥페이크 영상이 완성됩니다. 당신의 얼굴이 이미 범죄에 악용되고 있을 수…
달러/원 환율이 급등하는 이유와 실생활 영향을 정리했습니다. 지금 당장 활용할 수 있는 환전·투자 대응 전략까지…
미래에셋·미래에셋벤처투자·미래에셋생명이 동반 급등한 이유는 스페이스X 상장 기대감입니다. 세 회사가 스페이스X와 어떻게 연결되어 있는지 상세히 분석했습니다.
스페이스X 상장이 계속 미뤄지는 진짜 이유를 파헤쳤습니다. 화성 계획, 스타링크 분리, 국방 계약... 머스크가 절대…