검색

10.3. 노멀라이저

download PDF

10.3.1. 개요

노멀라이저 패턴은 의미 체계적으로 동일하지만 다른 형식으로 도달하는 메시지를 처리하는 데 사용됩니다. 노멀라이저는 들어오는 메시지를 공통 형식으로 변환합니다.

Apache Camel에서는 들어오는 메시지의 형식을 감지하는 8.1절. “콘텐츠 기반 라우터” 를 결합하여 다른 5.6절. “메시지#159” 로 들어오는 형식을 공통 형식으로 변환하는 컬렉션을 결합하여 노멀라이저 패턴을 구현할 수 있습니다.

그림 10.3. 노멀라이저 패턴

노멀라이저 패턴

10.3.2. Java DSL 예

이 예에서는 두 가지 유형의 XML 메시지를 공통 형식으로 변환하는 Message Normalizer를 보여줍니다. 그런 다음 이 공통 형식의 메시지가 필터링됩니다.

Fluent Builders사용

// we need to normalize two types of incoming messages
from("direct:start")
    .choice()
        .when().xpath("/employee").to("bean:normalizer?method=employeeToPerson")
        .when().xpath("/customer").to("bean:normalizer?method=customerToPerson")
    .end()
    .to("mock:result");

이 경우 Java 8080을 노멀라이저로 사용하고 있습니다. 클래스는 다음과 같습니다.

// Java
public class MyNormalizer {
    public void employeeToPerson(Exchange exchange, @XPath("/employee/name/text()") String name) {
        exchange.getOut().setBody(createPerson(name));
    }

    public void customerToPerson(Exchange exchange, @XPath("/customer/@name") String name) {
        exchange.getOut().setBody(createPerson(name));
    }

    private String createPerson(String name) {
        return "<person name=\"" + name + "\"/>";
    }
}

10.3.3. XML 구성 예

XML DSL의 동일한 예

<camelContext xmlns="http://camel.apache.org/schema/spring">
  <route>
    <from uri="direct:start"/>
    <choice>
      <when>
        <xpath>/employee</xpath>
        <to uri="bean:normalizer?method=employeeToPerson"/>
      </when>
      <when>
        <xpath>/customer</xpath>
        <to uri="bean:normalizer?method=customerToPerson"/>
      </when>
    </choice>
    <to uri="mock:result"/>
  </route>
</camelContext>

<bean id="normalizer" class="org.apache.camel.processor.MyNormalizer"/>
Red Hat logoGithubRedditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

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

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

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

Red Hat 소개

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

© 2024 Red Hat, Inc.