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 閱讀(671) 評論(0)  編輯  收藏 所屬分類: SPRING INTERGRATION

          主站蜘蛛池模板: 叙永县| 略阳县| 松原市| 花垣县| 长春市| 深圳市| 嘉义市| 乐业县| 米脂县| 洛浦县| 青海省| 林甸县| 太仆寺旗| 通化市| 海城市| 寻甸| 新龙县| 新邵县| 政和县| 阿鲁科尔沁旗| 潢川县| 红桥区| 新龙县| 中阳县| 康乐县| 商城县| 汉阴县| 金溪县| 贵定县| 松江区| 景洪市| 河间市| 福清市| 宜昌市| 高陵县| 越西县| 剑川县| 白银市| 安平县| 乌兰察布市| 马鞍山市|