검색

8.14. 구성된 메시지 프로세서

download PDF

8.14.1. 구성된 메시지 프로세서

그림 8.10. “구성된 메시지 프로세서 패턴” 에 표시된 대로 구성된 메시지 프로세서 패턴을 사용하면 이를 분할하고 하위 메시지를 적절한 대상으로 라우팅한 다음 응답을 단일 메시지로 다시 집계하여 복합 메시지를 처리할 수 있습니다.

그림 8.10. 구성된 메시지 프로세서 패턴

배포 집계

8.14.2. Java DSL 예

다음 예제에서는 주문의 각 부분을 다른 인벤토리에서 확인해야 하는 다중 파트 순서를 채울 수 있는지 확인합니다.

// split up the order so individual OrderItems can be validated by the appropriate bean
from("direct:start")
    .split().body()
    .choice()
        .when().method("orderItemHelper", "isWidget")
            .to("bean:widgetInventory")
        .otherwise()
            .to("bean:gadgetInventory")
    .end()
    .to("seda:aggregate");

// collect and re-assemble the validated OrderItems into an order again
from("seda:aggregate")
    .aggregate(new MyOrderAggregationStrategy())
    .header("orderId")
    .completionTimeout(1000L)
    .to("mock:result");

8.14.3. XML DSL 예

이전 경로는 다음과 같이 XML DSL로 작성할 수도 있습니다.

 <route>
   <from uri="direct:start"/>
   <split>
     <simple>body</simple>
     <choice>
       <when>
         <method bean="orderItemHelper" method="isWidget"/>
 	<to uri="bean:widgetInventory"/>
       </when>
       <otherwise>
 	<to uri="bean:gadgetInventory"/>
       </otherwise>
     </choice>
     <to uri="seda:aggregate"/>
   </split>
 </route>

 <route>
   <from uri="seda:aggregate"/>
   <aggregate strategyRef="myOrderAggregatorStrategy" completionTimeout="1000">
     <correlationExpression>
       <simple>header.orderId</simple>
     </correlationExpression>
     <to uri="mock:result"/>
   </aggregate>
 </route>

8.14.4. 처리 단계

처리는 8.4절. “Splitter” 을 사용하여 순서를 분할하여 시작합니다. 그러면 8.4절. “Splitter” 에서 개별 OrderItems 를 항목 유형에 따라 메시지를 라우팅하는 8.1절. “콘텐츠 기반 라우터” 로 보냅니다. 위젯 항목은 위젯 인벤토리 빈에서 확인할 수 있도록 전송되며 가젯 항목은 가젯 인벤토리 빈으로 전송됩니다. 이러한 OrderItems 의 유효성을 검사한 후 적절한 8080에서 8.5절. “수집기” 로 전송되어 검증된 OrderItems 를 다시 주문으로 수집하고 재조정합니다.

각 수신된 순서에는 주문 ID 가 포함된 헤더가 있습니다. 집계 단계에서 주문 ID를 사용합니다. aggregate() DSL 명령에 .header("orderId") 한정자를 사용하여 키, orderId 와 함께 헤더를 사용하도록 지시합니다.

자세한 내용은 camel-core/src/test/java/org/apache/camel/processor 에서 ComposedMessageProcessorTest.java 예제 소스를 확인하십시오.

Red Hat logoGithubRedditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

© 2024 Red Hat, Inc.