Categories: Camel프레임워크

[Camel in Action] 2-2. Camel XML DSL과 Spring 통합 – 설정 기반 라우트 정의

XML DSL – 설정 파일로 라우트 관리

XML DSL은 코드 변경 없이 라우팅 규칙을 수정할 수 있다는 장점이 있습니다. 특히 Spring XML 설정 방식에 익숙한 팀이나, 운영 중 동적 변경이 필요한 경우에 유용합니다.

기본 XML DSL 구조

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:camel="http://camel.apache.org/schema/spring">

    <camelContext id="camelContext"
                  xmlns="http://camel.apache.org/schema/spring">

        <route id="order-route">
            <from uri="file:orders/inbox?noop=true"/>
            <log message="파일 수신: ${header.CamelFileName}"/>
            <choice>
                <when>
                    <simple>${header.CamelFileName} contains 'urgent'</simple>
                    <to uri="direct:urgentOrder"/>
                </when>
                <otherwise>
                    <to uri="direct:normalOrder"/>
                </otherwise>
            </choice>
        </route>

    </camelContext>
</beans>

Spring Boot + application.yml 설정

Spring Boot 환경에서는 application.yml로 Camel 기본 설정을 관리합니다.

camel:
  springboot:
    name: MyApp
    main-run-controller: true
  dataformat:
    json-jackson:
      auto-discover-object-mapper: true

# Camel 라우트 자동 검색 패턴
  routes-include-pattern: "classpath:camel/*.xml"

Bean 참조와 Spring 의존성 주입

XML DSL에서 Spring Bean을 참조하는 방법입니다.

<!-- Spring Bean 정의 -->
<bean id="orderService" class="com.example.OrderService"/>

<!-- Camel 라우트에서 Bean 참조 -->
<route>
    <from uri="direct:processOrder"/>
    <bean ref="orderService" method="process"/>
    <to uri="jms:queue:completed"/>
</route>

프로퍼티 플레이스홀더 활용

환경별 설정값을 외부화하는 것은 Camel에서도 중요합니다.

# application.properties
order.input.dir=orders/inbox
jms.queue.name=orderQueue
retry.count=3
<!-- XML DSL에서 프로퍼티 사용 -->
<route>
    <from uri="file:{{order.input.dir}}?noop=true"/>
    <to uri="jms:queue:{{jms.queue.name}}"/>
</route>
// Java DSL에서 프로퍼티 사용
from("file:{{order.input.dir}}?noop=true")
    .to("jms:queue:{{jms.queue.name}}");

Java DSL vs XML DSL 선택 기준

  • Java DSL 선택: 복잡한 조건 로직, IDE 지원 필요, 타입 안전성, 팀이 Java에 익숙
  • XML DSL 선택: 빌드 없이 라우트 변경 필요, 비개발자도 이해해야 하는 경우, 레거시 Spring XML 환경

YAML DSL – 최신 트렌드

Camel 3.x 이후 YAML DSL도 지원합니다. Camel K (클라우드 네이티브 통합)에서 주로 사용됩니다.

- route:
    id: order-route
    from:
      uri: "file:orders/inbox"
      parameters:
        noop: true
    steps:
      - log:
          message: "파일 수신: ${header.CamelFileName}"
      - to: "jms:queue:orders"

zerg96

Share
Published by
zerg96

Recent Posts

[Apache Camel] 2025년 최신 트렌드 – AI 통합과 서버리스 Camel의 미래

2025년 Apache Camel의 최신 트렌드를 분석합니다. AI/LLM 통합 컴포넌트, 서버리스 배포, Camel K 진화, WebAssembly…

11시간 ago

[Camel in Action] 완결편 – Apache Camel 전체 여정 회고와 다음 단계

Camel in Action을 완독한 후 Apache Camel의 전체 그림을 다시 정리합니다. 핵심 철학, 학습 경로,…

11시간 ago

[Camel in Action] 실전편 – Camel 마이그레이션 가이드 2.x에서 4.x까지

Apache Camel 2.x에서 3.x, 4.x로 마이그레이션하는 단계별 가이드입니다. 주요 API 변경사항, 제거된 컴포넌트, 자동화 도구…

11시간 ago

[Camel in Action] 실전편 – Camel 라우트 디버깅 기법과 문제 해결 가이드

Apache Camel 라우트에서 발생하는 문제를 디버깅하고 해결하는 실전 기법을 설명합니다. 로그 분석, breakpoint 디버깅, Tracer,…

11시간 ago

[Camel in Action] 실전편 – Camel 도입 전 반드시 알아야 할 것들

Apache Camel을 프로젝트에 도입하기 전 알아야 할 핵심 사항을 정리합니다. 학습 곡선, 도입 비용, 적합한…

11시간 ago

[Camel in Action] 실전편 – Enterprise Integration Patterns 20가지 핵심 정리

엔터프라이즈 통합 패턴(EIP) 20가지를 Apache Camel 코드와 함께 한 번에 정리합니다. 메시징 채널, 메시지 라우팅,…

11시간 ago