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

충격! 코스피 8% 폭락에 SK텔레콤 AI 차단까지 – 한국의 AI 도박이 터졌다

코스피 8% 폭락, 서킷브레이커 발동, SK텔레콤 Claude AI 차단까지. 한국의 AI 레버리지 버블이 단 하루…

3주 ago

당신 얼굴이 이미 쓰이고 있다… AI 딥페이크 범죄, 생각보다 훨씬 심각합니다

SNS 사진 1장으로 30초 만에 딥페이크 영상이 완성됩니다. 당신의 얼굴이 이미 범죄에 악용되고 있을 수…

4주 ago

당신 얼굴이 이미 쓰이고 있다 — AI 딥페이크 범죄, 생각보다 훨씬 심각합니다

SNS 사진 1장으로 30초 만에 딥페이크 영상이 완성됩니다. 당신의 얼굴이 이미 범죄에 악용되고 있을 수…

4주 ago

달러·원 환율 급등, 지금 당신이 꼭 알아야 할 것들

달러/원 환율이 급등하는 이유와 실생활 영향을 정리했습니다. 지금 당장 활용할 수 있는 환전·투자 대응 전략까지…

4주 ago

미래에셋·미래에셋벤처투자·미래에셋생명 동반 급등, 스페이스X와 무슨 관계?

미래에셋·미래에셋벤처투자·미래에셋생명이 동반 급등한 이유는 스페이스X 상장 기대감입니다. 세 회사가 스페이스X와 어떻게 연결되어 있는지 상세히 분석했습니다.

4주 ago

스페이스X 상장 D-데이? 일론 머스크가 절대 말 안 하는 진짜 이유

스페이스X 상장이 계속 미뤄지는 진짜 이유를 파헤쳤습니다. 화성 계획, 스타링크 분리, 국방 계약... 머스크가 절대…

4주 ago