集成框架spring integration体验

本文介绍了一个基于 Spring Integration 的企业级应用集成案例,包括服务适配器、服务流设计及服务调用过程。通过实例展示了如何使用 Spring Integration 进行 RMI 和 WebService 之间的调用与数据转换。

这段时间做大客户项目,大量的业务系统,错综复杂的调用关系,每天就是在不停的与外系统沟通,不得已对企业集成做了点小了解,重点体验了下spring integreation。

   忽略spring integration中的各种费解概念,就想弄点我想要的简单的应用集成模式,简化服务接入,服务编排工作,弄个类似tibco bw的process设计类似的小东西。

  • 我所理解的概念
  1.   服务适配器 dapaper:描述各种类型的外系统接入,webService接入,rmi接入,wtc接入,ftp,jms等等。
  2.   服务 service :基本的服务调用。
  3.   服务流  flow:一组由service,filter,splitter,route,aggregator,transformer等连接起来的服务集合。
  4.   服务流程 :节点状态控制,节点流转控制,节点可以是服务,可以是服务流,以及其他类型。
  • 我想要的功能
  1. 适配器定义
  2. 服务定义
  3. 服务流设计器
  4. 流程设计器
  5. 流程服务监控,服务统计,流量统计等
  • 基于spring integration的尝试

1.可配置的json调用,通过http adapter可以发布我们的服务,服务流,流程等为http ajax调用,可以解决界面调用的问题,。

2.统一输入和输出

  规范服务的输入和输出, 所有类型的服务输入输出都可被包装成统一模式。

3输入和输出的映射实现

  在transformer中配置输出到输入的映射,使得服务A的结果可以再图形界面中映射到服务B。

4服务异常处理机制

5服务流事务处理机制

 

  • spring integration示例

    示例描述

    调用其他系统发布的rmi服务,rmi调用成功后继续调用webservice服务,其中rmi的结果映射到webservice服务的输入参数中,最终打印webservice中的返回结果.

    spring配置文件

 

Xml代码  收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
  5.         http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.2.xsd  
  6.         http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file-2.2.xsd  
  7.         http://www.springframework.org/schema/integration/http http://www.springframework.org/schema/integration/http/spring-integration-http-2.2.xsd  
  8.         http://www.springframework.org/schema/integration/rmi http://www.springframework.org/schema/integration/rmi/spring-integration-rmi-2.2.xsd  
  9.         http://www.springframework.org/schema/integration/ws http://www.springframework.org/schema/integration/ws/spring-integration-ws-2.2.xsd  
  10.         http://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream-2.2.xsd"  
  11.       
  12.     xmlns:int="http://www.springframework.org/schema/integration"  
  13.     xmlns:int-file="http://www.springframework.org/schema/integration/file"  
  14.     xmlns:int-http="http://www.springframework.org/schema/integration/http"  
  15.     xmlns:int-mail="http://www.springframework.org/schema/integration/mail"  
  16.     xmlns:int-rmi="http://www.springframework.org/schema/integration/rmi"  
  17.     xmlns:int-ws="http://www.springframework.org/schema/integration/ws"  
  18.     xmlns:int-stream="http://www.springframework.org/schema/integration/stream">  
  19.       
  20.     <!-- websercice调用处理类,  
  21.         从输入中获取的参数转换成requestXml  
  22.         从输出中获取responseXml装换成ResContext  
  23.      -->  
  24.     <bean name="wsInvoker"  
  25.         class="org.springframework.integration.samples.WebServiceInvoker" />  
  26.     <!-- ResContext到json的装换实现 -->  
  27.     <bean name="jsonTransformer" class="com.gsoft.framework.esb.json.JsonTransformer"/>     
  28.       
  29.     <!-- rmi请求入口channel -->  
  30.     <int:channel id="rmiRequestChannel"/>  
  31.     <!-- rmi 服务调用适配器 -->  
  32.     <int-rmi:outbound-gateway id="rmiGateway"  
  33.         request-channel="rmiRequestChannel" remote-channel="rmiExchange"  
  34.         host="127.0.0.1" reply-channel="rmiReply" />  
  35.     <!-- rmi服务调用 -->  
  36.     <int:service-activator  input-channel="rmiExchange" ref="rmiServiceFactory" method="exchange"/>  
  37.     <!-- rmi服务接口 -->  
  38.     <int:gateway id="rmiServiceFactory" service-interface="com.gsoft.framework.esb.rmi.RmiServiceFactory"/>  
  39.       
  40.     <!-- 把rmi服务调用后的输出结果映射到webservice服务调用的输入中 -->  
  41.     <int:transformer input-channel="rmiReply" output-channel="helloWorldWsChannel"   
  42.         ref="rmi2hellWorldWsTransformer"></int:transformer>  
  43.     <!-- 配置输入输出的transformer,定义映射规则 -->  
  44.     <bean name="rmi2hellWorldWsTransformer" class="com.gsoft.framework.esb.data.ReqMapResTransformer">  
  45.         <property name="mapping">  
  46.             <map>  
  47.                 <entry key="userName" value="#record.userName"></entry>  
  48.             </map>  
  49.         </property>  
  50.     </bean>     
  51.     <!-- websercice服务调用入口 -->  
  52.     <int:channel id="helloWorldWsChannel"/>  
  53.     <!-- 输入参数处理,从输入参数转换为requestXml -->  
  54.     <int:service-activator id="helloWordReqProcess" input-channel="helloWorldWsChannel"  
  55.         ref="wsInvoker" method="request"  output-channel="helloWorldReqChannel" />  
  56.     <!-- webservice 服务调用适配器 -->  
  57.     <int-ws:outbound-gateway request-channel="helloWorldReqChannel" id="helloWorldGateway"   
  58.         uri="http://localhost:8086/platform/services/HelloWorld"  reply-channel="wsResChannel"/>  
  59.     <!-- 输出参数处理,从响应的responseXml装换成ResContext对象 -->      
  60.     <int:service-activator id="wsResRrocess" input-channel="wsResChannel" output-channel="wsReply"  
  61.         ref="wsInvoker" method="reply"/>  
  62.     <!-- ResContext到json格式的转换 -->  
  63.     <int:transformer input-channel="wsReply" ref="jsonTransformer" output-channel="log"/>  
  64.     <!-- 打印输出到控制台 -->  
  65.     <int-stream:stdout-channel-adapter id="log"/>  
  66. </beans>  

 

  spring integration 图

  

  测试代码

  • 初步总结
  1.  spring integration框架的应用集成可以简化我们很多的接口开发工作,通过自主开发设计器,能够把我们大部分的系统间服务调用装换成图形化的配置。
  2. 服务的切换是可行的。
  3. 服务调用的统计和监控工作的实现很容易切入。
  4. 性能上的优化是可自主掌控的。
  5. 服务的分解粒度已经可以很细。
  6. 服务,流程测试很方便;自主实现调试也是可行的。
  7. 部署和运维的集成也可行。

   

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值