將處理業(yè)務(wù)的流程拆分成一個一個鏈,前面處理完,再派給下一個,類似HTTP中的FILTER
不用安裝服務(wù)器,內(nèi)嵌在SPRING容器中,對外支持多種格式的數(shù)據(jù),外部系統(tǒng)如要和SPRING INTERGRATION整合,不需要再進行開發(fā)
處理流程一般就是,ADAPTER去讀取外部數(shù)據(jù),轉(zhuǎn)換后放到CHANNEL中,ENDPOINT處理CHANNEL中的數(shù)據(jù),委派給下一個CHANNEL,下一個ENDPOINT處理,通過ADAPTER寫到外部接口中。
- ADAPTER
外部系統(tǒng)與CHANNEL之間的橋梁,獲取外部數(shù)據(jù)將其放到CHANNEL去,有FTP,JMS,文件系統(tǒng)的
CHANNEL
里面放MESSAGE對象,MESSAGE里面可以放自定義對象,以提供消費者使用
ENDPOINT
CHANNEL的消費者,CHANNEL與ENDPOINT是一對一的關(guān)系,所以如果想在一個CHANNE下對應(yīng)多個ENDPOINT,是做不到的,只能增加CHANNEL
Service Activators:從INPUT CHANNEL中取出一個對象作為參數(shù),調(diào)用設(shè)置的POJO的方法,將結(jié)果放到OUTPUT CHANNEL中
Transformers:對CHANNEL中的對象進行類型轉(zhuǎn)換
決定流向的ENDPOINT:Routers,SPLITER
- 例子
<?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,調(diào)用payload則取到Order
調(diào)用items則得到OrderItem List,拆分成OrderItem以一個為單位放到
drinks中
-->
<splitter input-channel="orders" expression="payload.items" output-channel="drinks"/>
<channel id="drinks"/>
<!-- 此處drinks里面的對象是一個一個OrderItem,調(diào)用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轉(zhuǎn)成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>