Spring集成:轻量级集成方法

当今的应用程序希望能够访问企业环境中的所有业务,而无需考虑与绝望的系统无缝集成的应用程序技术。 可以通过使用中间件技术对各种系统进行布线来实现这种集成。

集成平台使应用程序可以相互共享信息的环境,从而使体系结构具有高度的互操作性。 Spring Integration提供了一个中介框架,以使用路由和中介构建轻量级集成解决方案,而与协议无关。 Spring Integration是轻量级的路由和中介框架,不需要笨重的ESB容器即可部署。

Spring Integration使用Message对象来通信,路由和传递数据,这没什么,但是Java对象上的包装器由有效负载和标头组成。 有效载荷包含的数据可以是任何类型,例如文件,字符串,流等,而标头包含有关消息的通用信息,例如ID,时间戳等。

消息通过通道与生产者进行通信,该生产者将源与目标分离,并将消息发布到任何协议,例如JMS,HTTP,Ldap,文件等。生产者将消息发送到通道,而使用者则从通道接收消息

spring-integration_simple

简单集成应用

下例显示了生产者如何将雇员对象发送到渠道,发布者如何从渠道接收消息。

  • 下载源代码

Spring Dependency Maven配置

为了开始简单的集成示例,我们只需要将核心spring集成和spring上下文依赖项添加到maven pom.xml中。 此外,我们还需要Junit和spring测试才能进行单元测试

<properties><spring.framework.version>3.2.3.RELEASE</spring.framework.version><spring.integration.version>2.2.4.RELEASE</spring.integration.version><junit.version>4.11</junit.version></properties><dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>${spring.framework.version}</version></dependency><dependency><groupId>org.springframework.integration</groupId><artifactId>spring-integration-core</artifactId><version>${spring.integration.version}</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>${junit.version}</version><scope>test</scope></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId><version>${spring.framework.version}</version><scope>test</scope></dependency></dependencies>

弹簧配置
我们必须在Spring配置中配置通道和网关以发送和接收消息

SpringIntegTest-context.xml

<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.2.xsd"><!--sendRequestreceiveRequest--><annotation-config/><context:component-scan base-package="org.springsample.integration"/><gateway id="request" service-interface="org.springsample.integration.SentRequest"/><channel id="sendRequest"/><outbound-channel-adapter channel="sendRequest" ref="receiveResponse" method="processMessage" />
</beans:beans>

在这里,我们创建了请求网关以将消息发送到通道,并创建出站适配器以从sendRequest通道接收消息。 Spring Integration的网关是发送消息的入口点,该消息使用Java接口指定。 Spring Integration在运行时自动定义代理实现

请求和接收

下面我们创建SentRequest和ReceiveResponse类,以发送和接收消息,如下所示

SentRequest.java

package org.springsample.integration;
import org.springframework.integration.annotation.Gateway;
public interface SentRequest {@Gateway(requestChannel="sendRequest")public void process(Employee emp);}

@Gateway批注将指示发送消息的入口点

package org.springsample.integration;
import org.springframework.integration.Message;
import org.springframework.integration.annotation.MessageEndpoint;
@MessageEndpoint
public class ReceiveResponse {
public void processMessage(Message<Employee> message) {Employee employee = message.getPayload();System.out.println("Message Received \n Name :"+employee.getName()+"/n Phone : "+employee.getPhone()+"/n Address :"+employee.getAddress());}
}

@MessageEndpoint将指示它将通过适配器从通道接收消息。

以下是雇员POJO,但并非不行

package org.springsample.integration;
public class Employee {private String name;private String title;private String address;private String phone;public Employee(String name, String phone, String address) {this.name=name;this.phone=phone; this.address=address;
//……..Getter amd Setter}
}

测试中

我们可以使用spring测试框架进行测试,如下所示

package org.springbyexample.integration;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class SpringIntegTest {@Autowiredprivate SentRequest request = null;@Testpublic void testIntegration() {Employee emp = new Employee("John", "12345678", "Sunny Street Mac RG1");request.process(emp);}
}

确保在org / springbyexample / integration中保留spring配置文件名称SpringIntegTest-context,并且应该在类路径中
在运行SpringIntegTest时,它将显示控制台消息,如下所示

收到消息
名字:John / n电话:12345678 / n地址:Sunny Street Mac RG1

  • 下载源代码

摘要

Spring Integration是开放源代码的简单集成,可增强松散耦合并使应用程序集成变得容易和简单。 它将以可配置的方式在通道和网关之间集成,路由和中介消息。 本文有助于了解Spring Integration,并将帮助您开发一个简单的集成应用程序。

资源资源

  • http://static.springsource.org/spring-integration/reference/html/overview.html

参考: Spring集成:我们的JCG合作伙伴 Nitin Kumar在Tech My Talk博客上提出的一种轻量级集成方法 。

翻译自: https://www.javacodegeeks.com/2013/09/spring-integration-a-lightweight-integration-approach.html

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

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

相关文章

动态REM

什么是rem&#xff1f; rem是相对于根元素html字体大小来计算的&#xff0c;即( 1rem html字体大小 ) rem和em区别&#xff1f; rem:&#xff08;root em&#xff0c;根em&#xff09;根元素的fort-size的大小计算em&#xff1a;相对长度单位&#xff0c;相对于当前对象内文本…

java教学楼的属性_java设计一个父类建筑物building,由它派生出教学楼类classroom,然后采用一些数据进行测试....

public class Building {public String bname;//建筑物名称public int floors;//代表总层数public double area;//代表总面积public Building(){}public Building(String bname, int floors, double area) {this.bname bname;this.floors floors;this.area area;}}public cl…

Bootstrap中的列表的使用

列表无序列表排列顺序无关紧要的一列元素。Lorem ipsum dolor sit ametConsectetur adipiscing elitInteger molestie lorem at massaFacilisis in pretium nisl aliquetNulla volutpat aliquam velitPhasellus iaculis nequePurus sodales ultriciesVestibulum laoreet portti…

Vue项目中使用HighChart

记&#xff1a;初次在Vue项目中使用 HighChart 的时候要走的坑 感谢这位哥们的思路 传送门 Vue-cli项目使用 npm install highcharts --save 让我们看看 highcharts 的使用方法&#xff0c;传送门 Highcharts.chart(targetTag, option) 重启项目&#xff0c;建立chart.vue文件 …

form字体和颜色java安卓开发_Android 修改App中默认TextView的字体和颜色

一、别人怎么做来源http://stackoverflow.com/questions/3078081/setting-global-styles-for-views-in-androidActually, you can set a default style for TextViews (and most other built-in widgets) without needing to do a custom java class or setting the style indi…

使用Dozer框架进行Bean操作

介绍 如您所知&#xff0c;您可以在任何操作系统中将文件或文件夹从源位置复制到目标位置。 您是否考虑过复制基本上是POJO的java对象&#xff1f; 在许多情况下&#xff0c;您需要将源bean的内容复制到目标bean。 我不关心对象的拷贝构造函数&#xff0c;浅拷贝或深拷贝或克隆…

js如何把ajax获取的值返回到上层函数里?

我现在有个系统在用户点击浏览时&#xff0c;系统会以ajax的方式从后台获取查看的链接&#xff0c;并以window.open的方式打开&#xff0c;但因为现在多数的浏览器都会拦截window.open打开的地址&#xff0c;而window.location.href的方式又无法在浏览器新窗口打开&#xff0c;…

接口IDisposable的用法

C#的每一个类型都代表一种资源&#xff0c;而资源又分为两类&#xff1a; 托管资源 由CLR管理分配和释放的资源&#xff0c;即从CLR里new出来的对象。非托管资源 不受CLR管理的对象&#xff0c;如Windows内核对象&#xff0c;或者文件、数据库连接、套接字、COM对象等。如果类…

图形处理:betweeness中心性– neo4j的密码与graphstream

上周&#xff0c; 我写了关于中间性中心性算法以及使用graphstream 理解它的尝试 &#xff0c;在阅读源代码时&#xff0c;我意识到我可以使用neo4j的所有最短路径算法将某些东西放在一起。 概括地说&#xff0c;中间性中心度算法用于确定图中节点的负载和重要性。 在与Jen讨…

java tongpaiyu danliantiao_java版的汉字转拼音程序

[文件] ChiToLetter.javaimport java.io.UnsupportedEncodingException;import java.util.HashSet;import java.util.Iterator;import java.util.Set;import java.util.Vector;//实现汉字向拼音的转化//-----------------------------------------------------设计人:牛文平// …

小程序之Tab切换

小程序越来越火了&#xff0c;作为一名&#xff0c;额 有理想的攻城狮&#xff0c;当然要紧跟互联网时代的步伐啦&#xff0c;于是我赶紧抽时间学习了一下小程序的开发&#xff0c;顺便把经验分享给大家。 对于申请账号以及安装开发工具等&#xff0c;大家可以看官网&#xff…

configparser logging

configparser模块 # 该模块适用于配置文件的格式与windows ini文件类似&#xff0c;可以包含一个或多个节&#xff08;section&#xff09;&#xff0c;每个节可以有多个参数&#xff08;键值&#xff09;。 import configparser config configparser.ConfigParser() c…

JS结合Cookie实现验证码功能

验证码功能是现在网站开发中非常常见的一种功能&#xff0c;常见的编程语言&#xff0c;比如.NET,JAVA都能很容易实现验证码功能&#xff0c;今天我准备分享一个使用JS实现验证码的功能&#xff0c;非常简单使用&#xff0c;拿来就可以用&#xff0c;废话不多说&#xff0c;直接…

创建基于密码的加密密钥

本文讨论了创建基于密码的加密PBE密钥。 首先提醒您以前的要点–通常&#xff0c;在实际操作中&#xff0c;应将PBE密钥用作主密钥&#xff0c;该主密钥仅用于解锁工作密钥。 这具有三个主要优点&#xff1a; 您可以有多个密码&#xff0c;例如&#xff0c;托管的恢复密钥&am…

php-5.6.26源代码 - PHP文件汇编成opcode、执行

文件 php-5.6.26/Zend/zend.c ZEND_API int zend_execute_scripts(int type TSRMLS_DC, zval **retval, int file_count, ...) /* {{{ */ {va_list files;int i;zend_file_handle *file_handle;zend_op_array *orig_op_array EG(active_op_array); // 保存现场&#xff0c;操作…

java1a2b3c4d5e6f_用两个线程,一个输出字母,一个输出数字,交替输出1A2B3C4D...26Z...

用两个线程&#xff0c;一个输出字母&#xff0c;一个输出数字&#xff0c;交替输出1A2B3C4D...26Z方法一public class Test {static Thread t1 null, t2 null;public static void main(String[] args) {char[] aI "1234567".toCharArray();char[] aC "ABCD…

js如何设置浏览器全屏效果?

现在很多网页游戏进入游戏界面后都是全屏显示的效果&#xff0c;很多人问我这个要怎么实现&#xff0c;其实这个只要调用Fullscreen API就可以实现了作为一个比较新的 API&#xff0c;目前只有 Safari、Chrome 和 FireFox以及IE10以上的浏览器才支持该特性。因为尚未发布正式版…

6759: 异或序列

6759: 异或序列 时间限制: 1 Sec 内存限制: 128 MB题目描述 已知一个长度为n的整数数列a1,a2,…,an&#xff0c;给定查询参数l、r&#xff0c;问在al,al1,…,ar区间内&#xff0c;有多少子序列满足异或和等于k。也就是说&#xff0c;对于所有的x,y(l≤x≤y≤r)&#xff0c;满足…

Neo4j Java REST绑定–第2部分(批处理)

在第1部分中 &#xff0c;我们讨论了使用Java REST绑定建立与Neo4j Server的连接。 现在让我们详细了解事务&#xff0c;批处理以及REST请求的实际情况。确保org.neo4j.rest.logging_filter to true) as described in Part 1打开日志记录&#xff08;将系统属性org.neo4j.rest.…

selector简介

最近在学习java NIO&#xff0c;发现java nio selector 相对 channel ,buffer 这两个概念是比较难理解的 ,把学习理解的东西以文字的东西记录下来&#xff0c;就像从内存落地到硬盘&#xff0c;把内存中内容换成该知识点的索引。 在介绍Selector之前先明确以下3个问题&#…