paulwong

          SPRING INTERGRATION

          將處理業務的流程拆分成一個一個鏈,前面處理完,再派給下一個,類似HTTP中的FILTER
          不用安裝服務器,內嵌在SPRING容器中,對外支持多種格式的數據,外部系統如要和SPRING INTERGRATION整合,不需要再進行開發
          處理流程一般就是,ADAPTER去讀取外部數據,轉換后放到CHANNEL中,ENDPOINT處理CHANNEL中的數據,委派給下一個CHANNEL,下一個ENDPOINT處理,通過ADAPTER寫到外部接口中。

          1. ADAPTER
            外部系統與CHANNEL之間的橋梁,獲取外部數據將其放到CHANNEL去,有FTP,JMS,文件系統的

          2. CHANNEL
            里面放MESSAGE對象,MESSAGE里面可以放自定義對象,以提供消費者使用

          3. ENDPOINT
            CHANNEL的消費者,CHANNEL與ENDPOINT是一對一的關系,所以如果想在一個CHANNE下對應多個ENDPOINT,是做不到的,只能增加CHANNEL

            Service Activators:從INPUT CHANNEL中取出一個對象作為參數,調用設置的POJO的方法,將結果放到OUTPUT CHANNEL中
            Transformers:對CHANNEL中的對象進行類型轉換
            決定流向的ENDPOINT:Routers,SPLITER

          4. 例子
          <?xml version="1.0" encoding="UTF-8"?>
          <beans:beans xmlns="http://www.springframework.org/schema/integration"
              xmlns:xsi
          ="http://www.w3.org/2001/XMLSchema-instance"
              xmlns:beans
          ="http://www.springframework.org/schema/beans"
              xmlns:stream
          ="http://www.springframework.org/schema/integration/stream"
              xsi:schemaLocation
          ="http://www.springframework.org/schema/beans
                      http://www.springframework.org/schema/beans/spring-beans.xsd
                      http://www.springframework.org/schema/integration
                      http://www.springframework.org/schema/integration/spring-integration.xsd
                      http://www.springframework.org/schema/integration/stream
                      http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd"
          >

              
          <gateway id="cafe" service-interface="org.springframework.integration.samples.cafe.Cafe"/>

              
          <channel id="orders"/>
              
          <!-- 此處orders里面的對象是一個一個Message,調用payload則取到Order
                   調用items則得到OrderItem List,拆分成OrderItem以一個為單位放到
                   drinks中
               
          -->
              
          <splitter input-channel="orders" expression="payload.items" output-channel="drinks"/>

              
          <channel id="drinks"/>
              
          <!-- 此處drinks里面的對象是一個一個OrderItem,調用iced則取到布爾值
                   如果是true則放到coldDrinks中,如是false則放到hotDrinks中
               
          -->
              
          <router input-channel="drinks"  expression="payload.iced ? 'coldDrinks' : 'hotDrinks'"/>

              
          <channel id="coldDrinks">
                  
          <queue capacity="10"/>
              
          </channel>
              
          <service-activator input-channel="coldDrinks" ref="barista" method="prepareColdDrink" output-channel="preparedDrinks"/>

              
          <channel id="hotDrinks">
                  
          <queue capacity="10"/>
              
          </channel>
              
          <!-- 將輸入通道中的OrderItem轉成Drink -->
              
          <service-activator input-channel="hotDrinks" ref="barista" method="prepareHotDrink" output-channel="preparedDrinks"/>

              
          <channel id="preparedDrinks"/>
              
          <!-- 將通道中的Drink按一個Order進行合并成一個List<Order>-->
              
          <aggregator input-channel="preparedDrinks"  method="prepareDelivery" output-channel="deliveries">
                  
          <beans:bean class="org.springframework.integration.samples.cafe.xml.Waiter"/>
              
          </aggregator>

              
          <stream:stdout-channel-adapter id="deliveries"/>

              
          <beans:bean id="barista" class="org.springframework.integration.samples.cafe.xml.Barista"/>

              
          <poller id="poller" default="true" fixed-delay="1000"/>

          </beans:beans>

          posted on 2012-06-11 10:04 paulwong 閱讀(675) 評論(0)  編輯  收藏 所屬分類: SPRING INTERGRATION

          主站蜘蛛池模板: 密云县| 萝北县| 靖州| 华池县| 鄂托克前旗| 安丘市| 溆浦县| 华容县| 石林| 密山市| 长垣县| 肃南| 咸丰县| 洪湖市| 从江县| 马尔康县| 平安县| 华阴市| 清远市| 尉氏县| 定结县| 吉首市| 普陀区| 灵寿县| 柯坪县| 防城港市| 广昌县| 澜沧| 兰西县| 蒲江县| 棋牌| 全南县| 哈密市| 土默特右旗| 林芝县| 大名县| 卓资县| 建湖县| 苍南县| 郸城县| 扶绥县|