rube3xxx_Rube GoldbergSpring整合
rube3xxx
为了说明这一点,请考虑一个简单的系统,该系统仅接收一条消息,然后将其发送回大写,称其为Echo网关:
public interface EchoGateway { String echo(String message);
}
并为此进行测试:
@Testpublic void testEcho() {String response = echoGateway.echo('Hello');assertThat(response, is('HELLO'));}
到目前为止听起来很简单,使用spring集成的实现将通过转换为大写并返回增强后的消息来接受“消息”并对其进行“转换”。
<?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'xsi:schemaLocation='http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.1.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd'><channel id='requestChannel'/><gateway id='echoGateway' service-interface='rube.simple.EchoGateway' default-request-channel='requestChannel' /><transformer input-channel='requestChannel' expression='payload.toUpperCase()' /> </beans:beans>
作品精美!
Spring Integration的优点在于,即使Integration场景变得复杂,它呈现给应用程序的外观仍然保持简单,
考虑一个Rube Goldberg集成方案:
首先是描述旋流的图表:
![](https://2.bp.blogspot.com/--QPaykya0mg/T-NqewTIbjI/AAAAAAAAAtw/Ck2tTZyW6HI/s400/rube.gif)
那么它到底是做什么的:
- 它接收到这样的消息-“来自Spring整合的你好”,
- 将其拆分为单个词(您好,来自,春天,完整),
- 将每个单词发送到ActiveMQ队列,
- 从队列中,单词片段被浓缩器拾取以大写每个单词,
- 将响应放回响应队列,
- 根据单词的原始顺序对其进行重新排序,
- 聚合成一个句子(“ HELLO FROM SPRING INTEG”),
- 返回到应用程序。
这是这种流程的Spring Integration配置的样子:
<?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:int-jms='http://www.springframework.org/schema/integration/jms'xmlns:beans='http://www.springframework.org/schema/beans'xsi:schemaLocation='http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.0.xsdhttp://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.1.xsdhttp://www.springframework.org/schema/integration/jms http://www.springframework.org/schema/integration/jms/spring-integration-jms-2.1.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd'><beans:import resource='broker.xml'/><channel id='requestChannel'><queue/> </channel><channel id='responseChannel'><queue/></channel><gateway id='echoGateway' service-interface='rube.complicated.EchoGateway' default-request-channel='requestChannel' default-reply-channel='responseChannel' default-reply-timeout='5000' /><channel id='toJmsOutbound'/><splitter input-channel='requestChannel' output-channel='toJmsOutbound' expression='payload.split('\s')'></splitter><channel id='sequenceChannel'></channel><int-jms:outbound-gateway request-channel='toJmsOutbound' reply-channel='sequenceChannel' request-destination='amq.outbound' extract-request-payload='true' /><channel id='enhanceMessageChannel'/><channel id='toReplyQueueChannel'/><int-jms:inbound-gateway request-channel='enhanceMessageChannel' request-destination='amq.outbound' reply-channel='toReplyQueueChannel'/><transformer input-channel='enhanceMessageChannel' expression='(payload + '').toUpperCase()' output-channel='toReplyQueueChannel'/><resequencer input-channel='sequenceChannel' output-channel='aggregateChannel' release-partial-sequences='false'></resequencer><aggregator input-channel='aggregateChannel' output-channel='responseChannel' expression='T(com.google.common.base.Joiner).on(' ').join(![payload].toArray())'/><poller id='poller' fixed-delay='500' default='true'/></beans:beans>
这个流程有太多的复杂性(因此,Rube Goldberg也是如此),但是Spring Integration提供给应用程序的外观仍然非常简单。
@Testpublic void testEcho() throws Exception{String amessage = 'Hello from Spring Integration';String response = echoGateway.echo(amessage);assertThat(response, is('HELLO FROM SPRING INTEGRATION'));}
我认为这是Spring Integration的本质
我在https://github.com/bijukunjummen/rg-si.git上有一个包含此代码的github存储库。
参考: all和其他博客中的Rube Goldberg Spring Integration,来自我们的JCG合作伙伴 Biju Kunjummen。
翻译自: https://www.javacodegeeks.com/2012/06/rube-goldberg-spring-integration_22.html
rube3xxx
rube3xxx_Rube GoldbergSpring整合相关推荐
- Rube GoldbergSpring整合
Spring Integration为集成系统所涉及的某些复杂性提供了非常好的抽象-Spring Integration从Integration的角度来看非常适合Facade的定义-简化了对复杂底层系 ...
- Spring Boot整合Spring Data JPA操作数据
一. Sping Data JPA 简介 Spring Data JPA 是 Spring 基于 ORM 框架.JPA 规范的基础上封装的一套 JPA 应用框架,底层使用了 Hibernate 的 J ...
- ssh(Struts+spring+Hibernate)三大框架整合-简述
ssh(Struts+spring+Hibernate)三大框架配合使用来开发项目,是目前javaee最流行的开发方式,必须掌握: 注意: 为了稳健起见,每加入一个框架,我们就需要测试一下,必须通过才 ...
- struts2 与 sping 整合 控制器中 service注入的问题
以个人见解认为struts1 与spring整合的时候按照习惯,我们会把 action 控制器直接配置到sping中去: eg : 这里以使用元注解方式实现Service注入进行讲解: 控制器关键代码 ...
- Strutsw2与Spring整合流程-简述
1. 新建WEB工程: 2. 导入struts2开发包,和资源配置文件 ① globalMessages.properties ② struts.properties 3. ...
- 【牛腩新闻发布系统】整合前台04
前言: 后台,前台完成后,整合界面会变得非常简单 整理前台的问题总结: 1. 数据绑定 2. html语言问题 3. 莫名错误,重试解决 4. 整合收缩页 5. 整合新闻内容页 6. 整个前台页面出错 ...
- SSM框架整合(Spring+SpringMVC+MyBatis)
输出结果 1.Maven Web项目创建 之前有写过Eclipse+Maven创建web项目的帖子,如果需要,请参考这里写链接内容 创建好项目之后因为入下图: 2.SSM整合 2.1 引入需要的JAR ...
- SpringBoot整合Shiro安全框架完整实现
目录 一.环境搭建 1. 导入shiro-spring依赖 2. 编写首页及其controller 3. 编写shiro配置类 二.Shiro实现登录拦截 1. 编写页面及其controller 2. ...
- SpringBoot整合MyBatis详细教程~
目录 1. 导入依赖 2. 连接数据库 3. 编写数据库配置信息 4. 编写pojo实体类 5. 编写mapper接口 6. 编写mapper.xml 7. 编写controller 8. 测试 1. ...
最新文章
- stella forum v1.2 用例分析
- Windows 8测试版安装图组
- 请你说明一下TreeMap的底层实现?
- python列透视_python – 在pandas数据帧中透视列和列值
- PowerDesigner生成mysql字段comment 注释
- 求关于运动的英语(收集)
- Python自动化中的元素定位xpath(二)
- 12月1日struts、spring、hibernate等框架的整合培训日记
- 【元胞自动机】基于matlab元胞自动机传染病传播模拟【含Matlab源码 1680期】
- cim系统(cim系统包含哪些部分)
- mysql报错You do not have the SUPER privilege and binary logging is enabled
- 聚焦质控 | 如何进行单病种过程质量管理
- matlab抢占时隙算法,ALOHA anti-collision、二进制数搜索算法以及帧时隙算法
- Java下载Excel文件
- 逃离烤鸭味的雾霾北京,我们还能去哪里?
- Stm32 - Printf重定向(不)使用微库(Keil MDK)
- 饿了么被上海市市场监督局予以警告处分
- LeetCode算法题解 414-第三大的数
- PHP--有道(百度)文字或语句转MP3音频文件
- 使用python代替matlab仿真线性控制系统(倒立摆)