상세 컨텐츠

본문 제목

ESB 를 이용한 전문전송을 위한 JAVA 코딩 예제

IT/java

by 심장과영혼 2023. 1. 23. 22:33

본문

728x90
반응형

1. Apache Camel ESB:

from("jms:queue:incomingOrders")
  .choice()
    .when(header("orderType").isEqualTo("new"))
      .to("jms:queue:newOrders")
    .when(header("orderType").isEqualTo("update"))
      .to("jms:queue:updatedOrders")
    .otherwise()
      .to("jms:queue:errorOrders")


2. Mule ESB:
<flow name="orderProcessingFlow">
  <jms:inbound-endpoint queue="incomingOrders" />
  <choice>
    <when expression="#[headers.orderType == 'new']">
      <jms:outbound-endpoint queue="newOrders" />
    </when>
    <when expression="#[headers.orderType == 'update']">
      <jms:outbound-endpoint queue="updatedOrders" />
    </when>
    <otherwise>
      <jms:outbound-endpoint queue="errorOrders" />
    </otherwise>
  </choice>
</flow>

3. WSO2 ESB:
<proxy name="OrderProcessingProxy">
  <target>
    <inSequence>
      <property name="orderType" expression="get-property('transport', 'orderType')" />
      <switch source="$ctx:orderType">
        <case regex="new">
          <send>
            <endpoint>
              <address uri="jms:/newOrders?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&amp;java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&amp;java.naming.provider.url=tcp://localhost:61616"/>
            </endpoint>
          </send>
        </case>
        <case regex="update">
          <send>
            <endpoint>
              <address uri="jms:/updatedOrders?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&amp;java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&amp;java.naming.provider.url=tcp://localhost:61616"/>
            </endpoint>
          </send>
        </case>
        <default>
          <send>
            <endpoint>
              <address uri="jms:/errorOrders?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&amp;java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&amp;java.naming.provider.url=tcp://localhost:61616"/>
            </endpoint>
          </send>
        </default>
      </switch>
    </inSequence>
  </target>
  <parameter name="transport.jms.ContentType">
    <rules>
      <jmsProperty>contentType</jmsProperty>
      <default>text/plain</default>
    </rules>
  </param>

4. Apache Camel ESB 프레임워크를 사용하는 다음 코드 샘플은 JMS 대기열에서 RESTful 웹 서비스로 메시지를 라우팅하는 방법을 보여줍니다.
from("jms:queue:incomingMessages")
    .to("http://localhost:8080/webService/processMessage")
    .log("Message successfully sent to web service")

5.  Mule ESB를 사용하여 수신 XML 메시지를 JSON으로 변환한 다음 데이터베이스로 라우팅하는 방법을 보여줍니다.
<flow name="dataFlow">
    <jms:inbound-endpoint queue="incomingData"/>
    <xml-to-json-transformer/>
    <db:insert config-ref="DatabaseConfig" doc:name="Insert into Database"/>
</flow>

6. WSO2 ESB를 사용하여 메시지 헤더 값에 따라 메시지를 다른 끝점으로 라우팅하는 방법을 보여줍니다.
<proxy xmlns="http://ws.apache.org/ns/synapse" name="HeaderRouter">
    <target>
        <inSequence>
            <property name="route" expression="get-property('To')"/>
            <switch source="$ctx:route">
                <case regex="http://localhost:8080/endpoint1">
                    <send>
                        <endpoint>
                            <address uri="http://localhost:8080/endpoint1"/>
                        </endpoint>
                    </send>
                </case>
                <case regex="http://localhost:8080/endpoint2">
                    <send>
                        <endpoint>
                            <address uri="http://localhost:8080/endpoint2"/>
                        </endpoint>
                    </send>
                </case>
                <default>
                    <send>
                        <endpoint>
                            <address uri="http://localhost:8080/defaultEndpoint"/>
                        </endpoint>
                    </send>
                </default>
            </switch>
        </inSequence>
    </target>
</proxy>

7. Talend ESB를 사용하여 파일 시스템에서 RESTful 웹 서비스로 메시지를 라우팅하고 프로세스에서 메시지를 JSON 형식으로 변환하는 방법을 보여줍니다.
<route>
    <from uri="file:data/incoming?noop=true"/>
    <unmarshal ref="xml"/>
    <marshal ref="json"/>
    <to uri="http://localhost:8080/webService/processData"/>
</route>

 


나날이 발전이 있으시기를 바랍니다.

구독과 좋아요는 큰 힘이 됩니다.

728x90
반응형

관련글 더보기