做系統(tǒng)集成新的方式,主要是消息處理機制,采用通道的方式。
簡單的配置文件
<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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<!-- 啟動Message bus 消息服務(wù)總線 支持四個屬性
auto-startup[boolean是否自動啟動 default=true]如果設(shè)置false,則需要手動調(diào)用applicationContext.start()方法
auto-create-channels[boolean是否自動注冊MessageChannel default=false],如果使用的MessagChannle不存在
error-channel 設(shè)置錯誤時信息發(fā)送的MessageChannle,如果不設(shè)置,則使用DefaultErrorChannel
dispatcher-pool-size 使用的啟動線程數(shù),默認為10-->
<message-bus/>
<!-- 啟動支持元數(shù)據(jù)標記 -->
<annotation-driven/>
<!-- 設(shè)置 @Component標識的元數(shù)據(jù)掃描包(package) -->
<context:component-scan base-package="org.springframework.integration.samples.cafe"/>
<!-- 下面啟動了四個 MessageChannel服務(wù) 處理接收發(fā)送端發(fā)過來的消息和把消息流轉(zhuǎn)到消息的消費端 -->
<!-- 屬性說明: capacity 消息最大容量默認為100 publish-subscribe是否是發(fā)布訂閱模式,默認為否
id bean的id名稱 datatype ? -->
<channel id="orders"/> <!-- 訂單Channel -->
<channel id="drinks"/> <!-- 飲料訂單Channel,處理飲料的類別 -->
<channel id="coldDrinks"/> <!-- 熱飲生產(chǎn)Channel -->
<channel id="hotDrinks"/> <!-- 冷飲生產(chǎn)Channel -->
<!-- 消息處理終端 接收 channel coldDrinks的消息后,執(zhí)行barista.prepareColdDrink方法 生產(chǎn)冷飲 -->
<!-- 屬性說明: input-channel 接收消息的Channel必須 default-output-channel設(shè)置默認回復(fù)消息Channel
handler-ref 引用bean的id名稱 handler-method Handler處理方法名(參數(shù)類型必須與發(fā)送消息的payLoad使用的一致)
error-handler設(shè)置錯誤時信息發(fā)送的MessageChannle reply-handler 消息回復(fù)的Channel -->
<endpoint input-channel="coldDrinks" handler-ref="barista"
handler-method="prepareColdDrink"/>
<!-- 消息處理終端 接收 channel hotDrinks的消息后,執(zhí)行barista.prepareHotDrink方法 生產(chǎn)熱飲 -->
<endpoint input-channel="hotDrinks" handler-ref="barista"
handler-method="prepareHotDrink"/>
<!-- 定義一個啟動下定單操作的bean,它通過 channel orders下定單 -->
<beans:bean id="cafe" class="org.springframework.integration.samples.cafe.Cafe">
<beans:property name="orderChannel" ref="orders"/>
</beans:bean>
</beans:beans>