关于使用 Spring Integration 感受

我一直认为 组件间或者方法间的互相调用 就是 按照 互相粘合 或者 通过反射机制依赖注入的方式 或者 工作流的机制 来进行调用。Integration  给我带来对 组件间或者方法间相互通讯的世界观改变。其实组件的通讯 可以不用那么耦合度那么高。使用Integration 建立通讯 线路,可以方便的进行组件间的编排。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xmlns:task="http://www.springframework.org/schema/task"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:websocket="http://www.springframework.org/schema/websocket"
       xmlns:integration="http://www.springframework.org/schema/integration"
       xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
        http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
        http://www.springframework.org/schema/websocket http://www.springframework.org/schema/websocket/spring-websocket.xsd
        http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd">
       
    <context:annotation-config />
    <aop:aspectj-autoproxy />
    <context:component-scan base-package="com.richcomm.ippower.entity"/>
    <context:component-scan base-package="com.richcomm.ippower.dao"/>
    <context:component-scan base-package="com.richcomm.ippower.service.*"/>
   


   <!--  首先来配置一个GateWay组件,提供消息的发送和接收。接口Cafe,提供一个void placeOrder(Order order);方法
        该方法标记了@Gateway(requestChannel="orders"), 实现向orders队列实现数据的发送
          --> 
   <integration:gateway service-interface="com.richcomm.ippower.service.impl.Cafe" id="cafe" />   
    
     <!--  订单Channel  --> 
    <integration:channel id="orders"></integration:channel>
  
  <!--  实现Splitter模式, 接收 orders队列的消息,调用orderSplitter Bean的split方法,进行消息的分解
    并把分解后的消息,发送到drinks队列.
      --> 
  <integration:splitter  input-channel ="orders"  ref ="orderSplitter"  method ="split"  output-channel ="drinks"></integration:splitter>

  <!--  饮料订单Channel,处理饮料的类别  --> 
  <integration:channel id="drinks"></integration:channel>
  
    <!-- 实现路由Router模式,接收 drinks队列的消息, 并触发 drinkRouter Bean的 resolveOrderItemChannel方法
        由在 resolveOrderItemChannel该方法的返回值(String队列名称)表示把消息路由到那个队列上 -->
    <integration:router  input-channel ="drinks"  ref ="drinkRouter"  method ="resolveOrderItemChannel"></integration:router>
   
    <!--  冷饮生产Channel 最大待处理的数据量为 10 --> 
   <integration:channel id="coldDrinks">
       
   </integration:channel>
   
    <!--  定义一个服务处理器,其作用是定义一个消息接收队列 codeDrinks,一但收到消息,则
    触发 barista Bean的 prepareColdDrink方法, 再把 prepareColdDrink方法的值,封成Message的
    payLoad属性,把消息再发送到preparedDrinks队列,  --> 
    <integration:service-activator  input-channel ="coldDrinks"  ref ="barista" 
                       method ="prepareColdDrink"  output-channel ="preparedDrinks"></integration:service-activator>
  
   <!--  热饮生产Channel 最大待处理的数据量为 10 --> 
 <integration:channel id="hotDrinks">
  
 </integration:channel>
 
 <!--  定义一个服务处理器,其作用是定义一个消息接收队列 hotDrinks,一但收到消息,则
    触发 barista Bean的 prepareHotDrink 再把 prepareColdDrink方法的值,封成Message的
    payLoad属性,把消息再发送到preparedDrinks队列,  --> 
 <integration:service-activator   input-channel ="hotDrinks"  ref ="barista" 
                       method ="prepareHotDrink"  output-channel ="preparedDrinks"></integration:service-activator>
 
 <!--  定义最终进行生产的消息队列  --> 
 <integration:channel id="preparedDrinks"></integration:channel>
      
        <!--实现 aggregator 模式, 接收 preparedDrinks 消息, 并触发 waiter Bean的prepareDelivery方法
     再把处理好的数据,发送到 deliveries队列--> 
  <integration:aggregator  input-channel ="preparedDrinks"  ref ="waiter" 
                method ="prepareDelivery"  output-channel ="lastpipe"></integration:aggregator>
  
  <!-- 最后输出管道 -->
  <integration:channel id="lastpipe"></integration:channel>
  
  <!--最后进入礼貌通道 -->
  <integration:service-activator input-channel="lastpipe" ref="politenessServiceImpl" method="greet" />
 
  

</beans>

转载于:https://my.oschina.net/zhangtiant/blog/993768

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值