rube3xxx_Rube GoldbergSpring整合

rube3xxx

Spring Integration为集成系统所涉及的一些复杂性提供了非常好的抽象-Spring Integration从Integration的角度完美地满足了Facade的定义-简化了对复杂基础系统的访问。

为了说明这一点,请考虑一个简单的系统,该系统仅接收一条消息,然后将其发送回大写,称其为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集成方案:

首先是描述旋流的图表:

那么它到底是做什么的:

  • 它接收到这样的消息-“来自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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/354634.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

纯CSS实现React Logo图形,内含详细解析

以上是将要实现的效果&#xff0c;Javascript框架React的Logo图形&#xff0c;首先我们来拆解下&#xff0c;它包括三个交叉的椭圆和中间一个圆点&#xff0c;所以我们Html元素可以用以下代码实现&#xff1a;<div class"main"><div class"ellipse ell…

学生ID查询

var http require("http");var server http.createServer(function(req,res){//得到urlvar userurl req.url;res.writeHead(200,{"Content-Type":"text/html;charsetUTF8"})//substr函数来判断此时的开头if(userurl.substr(0,9) "/stud…

平等还是认同?

将对象存储在集合中时&#xff0c;同一对象永远不能添加两次非常重要。 这是集合的核心定义。 在Java中&#xff0c;使用两种方法来确定两个引用的对象是否相同或它们是否可以同时存在于同一Set中。 equals&#xff08;&#xff09;和hashCode&#xff08;&#xff09;。 在本文…

二次优化大招(由泰勒公式推出最值条件)

经过前两篇的铺垫&#xff0c;这一篇迎来了高潮。先说一句&#xff1a;特征值大法好&#xff01; 在开始正文之前&#xff0c;先看以下简单的推导 有了这些&#xff0c;理解下面的泰勒公式推出最值条件就容易了 转载于:https://www.cnblogs.com/Mr-ZeroW/p/7764916.html

前端自动化测试浅析

前言&#xff1a;测试简介前端常见的问题&#xff1a;修改某个模块功能时&#xff0c;其它模块也受影响&#xff0c;很难快速定位bug多人开发代码越来越难以维护不方便迭代&#xff0c;代码无法重构代码质量差增加自动化测试后&#xff1a;我们为核心功能编写测试后可以保障项目…

使用SpringData出现java.lang.AbstractMethodError

最近学习一下SpringData&#xff0c;在添加SpringData支持的时候&#xff0c;出现了这样的问题&#xff1a; SpringData需要的jar有:spring-data-jpa.jar spring-data-commons.jar slf4j-api.jar 没有添加slf4j也会出现一个异常&#xff0c;不过那个异常说的非常明确&#xf…

2021这份电子书单请收好(品类齐全)!

2021年已经快过去一个月了&#xff0c;今年的读书计划有没有安排上&#xff0c;这里有份长长的书单&#xff0c;多年的积累&#xff0c;品类齐全&#xff0c;赶快从中挑几本加入今年的读书计划里。•《货币战争2&#xff1a;金权天下》 - 宋鸿兵.mobi•《圣经》中英对照豪华版 …

在Kotlin中使用libGDX

最近&#xff0c;我一直在阅读有关不同语言的信息&#xff0c;以及它们可以为已经拥挤的软件开发人员带来什么&#xff0c;而一种语言对我来说很突出&#xff1a;Kotlin。 &#xff08; https://kotlinlang.org/ &#xff09; 这是一种相对较新的语言&#xff08;成立于2011年…

练习1-2:编写一个 JAVA 程序,实现输出考试成绩的前三名。

1、 考试成绩已保存在数组 scores中&#xff0c;数组元素依次为 89 , -23 , 64 , 91 , 119 , 52 , 732、 要求通过自定义方法来实现成绩排名并输出操作&#xff0c;将成绩数组作为参数传入3、 要求判断成绩的有效性&#xff08; 0—100 &#xff09;&#xff0c;如果成绩无效&a…

【重学JS系列】slice用法大合集

让我们回顾下slice的日常用法slice 工作原理在深入研究一些更高级的用法之前&#xff0c;让我们看一下slice方法的基础知识。如MDN文档&#xff0c;slice 是数组上的一个方法&#xff0c;它最多有两个参数:arr.slice([begin[, end]])begin从该索引处开始提取原数组中的元素,如果…

redux-4-ways

https://medium.com/react-native-training/redux-4-ways-95a130da0cdc转载于:https://www.cnblogs.com/skating/p/7774090.html

【Github开源】一站搞定各种开发文档

开发者的苦恼&#xff1a;经常要在多个API文档中切换&#xff0c;浏览器书签栏收藏各种语言相关的接口说明文档。无意中在Github上发现DevDocs[1]这个开源项目&#xff0c;它是一个把所有开发相关的文档以web的形式做了一个综合的网站&#xff0c;并提供搜索&#xff0c;离线访…

javafx 表单_JavaFX 2:创建登录表单

javafx 表单在本教程中&#xff0c;我将使用JavaFX 2和CSS设计一个外观漂亮的Login Form 。 它是经典的登录表单&#xff0c;带有用户名和密码以及登录按钮。 为了遵循本教程&#xff0c;我强烈建议您查看以下这些教程&#xff1a; Eclipse IDE中的JavaFX 2入门 JavaFX 2&…

中高级JavaScript易错面试题

写出下题的输出 1、函数的实参与形参length var length 10; function fn() {console.log(this.length); } var obj {length: 5,method: function(fn) {fn();arguments[0]();} }; console.log(obj.method(fn, 1));  // 0 2 我们都知道&#xff0c;[1, 2, 3].length可以得到3…

静音设计模式

您最近是否遵循Mute-Design-Pattern™编写了大量代码&#xff1f; 例如 try {complex();logic();here(); } catch (Exception ignore) {// Will never happen heheSystem.exit(-1); }Java 8有一个更简单的方法&#xff01; 只需将这个非常有用的工具添加到您的Utilities或Hel…

【详细教程】教你如何使用Node + Express + Typescript开发一个应用

Express是nodejs开发中普遍使用的一个框架&#xff0c;下面要谈的是如何结合Typescript去使用。 目标 我们的目标是能够使用Typescript快速开发我们的应用程序&#xff0c;而最终我们的应用程序却是编译为原始的JavaScript代码&#xff0c;以由nodejs运行时来执行。 初始化设置…

结构型模式 适配器模式

结构型模式 适配器模式 适用于&#xff1a; 是将一个类的接口转换成客户希望的另外一个接口。使得原本由于接口不兼容而不能一起工作的那些类可以一起工作。 /*** 结构型模式 适配器模式* Adapter模式也叫适配器模式&#xff0c;是构造型模式之一&#xff0c;通过Adapter模式可…

乐哥学AI_Python(二):Numpy索引,切片,常用函数

Numpy的索引和切片 ndarray对象的内容可以通过索引和切片查看和修改。 索引&#xff1a;ndarray对象中的元素索引基于0开始 切片&#xff1a;对数组里某个片段区域的描述 数组的切片也可以理解为原始数组的局部视图&#xff0c;都是指向内存中的原始数组&#xff0c;所以不同于…

仅使用HTML和CSS实现的标签云效果

标签云的效果在博客和网站上不难见到&#xff0c;它其实就是带有超链接的某些关键字&#xff0c;为了达到强调主题的作用。通常出现概率比较大或者受欢迎的标签文字显示比较大&#xff0c;相反的就显示的小。来源于TagCrowd.com我们就不去深入研究标签云带来的效率上的提升和可…

捍卫Java

因此&#xff0c;我们不时发布了一本电子书&#xff0c;名为“十大Java性能问题” 。 毫无例外&#xff0c;一些人回答说“问题是您正在使用Java”。 显然&#xff0c;Java一直在受到批评&#xff0c;人们已经预测了它的消亡已有一段时间了。 当然&#xff0c;它不像Python&am…