8장. 메시지 라우팅
초록
메시지 라우팅 패턴은 메시지 채널을 함께 연결하는 다양한 방법을 설명합니다. 여기에는 메시지의 본문을 수정하지 않고 메시지 스트림에 적용할 수 있는 다양한 알고리즘이 포함됩니다.
8.1. 콘텐츠 기반 라우터
8.1.1. 개요
그림 8.1. “컨텐츠 기반 라우터 패턴” 에 표시된 콘텐츠 기반 라우터 를 사용하면 메시지 콘텐츠를 기반으로 메시지를 적절한 대상으로 라우팅할 수 있습니다.
그림 8.1. 컨텐츠 기반 라우터 패턴

8.1.2. Java DSL 예
다음 예제에서는 다양한 서술자 표현식 평가에 따라 입력, seda:a, endpoint에서 seda:b:b:c, seda:d 로 요청을 라우팅하는 방법을 보여줍니다.
RouteBuilder builder = new RouteBuilder() {
public void configure() {
from("seda:a").choice()
.when(header("foo").isEqualTo("bar")).to("seda:b")
.when(header("foo").isEqualTo("cheese")).to("seda:c")
.otherwise().to("seda:d");
}
};8.1.3. XML 구성 예
다음 예제에서는 XML로 동일한 경로를 구성하는 방법을 보여줍니다.
<camelContext id="buildSimpleRouteWithChoice" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="seda:a"/>
<choice>
<when>
<xpath>$foo = 'bar'</xpath>
<to uri="seda:b"/>
</when>
<when>
<xpath>$foo = 'cheese'</xpath>
<to uri="seda:c"/>
</when>
<otherwise>
<to uri="seda:d"/>
</otherwise>
</choice>
</route>
</camelContext>