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 阅读(657) 评论(0)  编辑  收藏 所属分类: SPRING INTERGRATION


只有注册用户登录后才能发表评论。


网站导航: