产品定制网站,网站域名有了_网站如何建设,保密管理咨询公司,wordpress企业版主体当今的应用程序希望能够访问企业环境中的所有业务#xff0c;而无需考虑与绝望的系统无缝集成的应用程序技术。 可以通过使用中间件技术对各种系统进行布线来实现这种集成。 集成平台使应用程序可以相互共享信息的环境#xff0c;从而使体系结构具有高度的互操作性。 Spring… 当今的应用程序希望能够访问企业环境中的所有业务而无需考虑与绝望的系统无缝集成的应用程序技术。 可以通过使用中间件技术对各种系统进行布线来实现这种集成。 集成平台使应用程序可以相互共享信息的环境从而使体系结构具有高度的互操作性。 Spring Integration提供了一个中介框架以使用路由和中介构建轻量级集成解决方案而与协议无关。 Spring Integration是轻量级的路由和中介框架不需要笨重的ESB容器即可部署。 Spring Integration使用Message对象来通信路由和传递数据这没什么但是Java对象上的包装器由有效负载和标头组成。 有效载荷包含的数据可以是任何类型例如文件字符串流等而标头包含有关消息的通用信息例如ID时间戳等。 消息通过通道与生产者进行通信该生产者将源与目标分离并将消息发布到任何协议例如JMSHTTPLdap文件等。生产者将消息发送到通道而使用者则从通道接收消息 简单集成应用 下例显示了生产者如何将雇员对象发送到渠道发布者如何从渠道接收消息。 下载源代码 Spring Dependency Maven配置 为了开始简单的集成示例我们只需要将核心spring集成和spring上下文依赖项添加到maven pom.xml中。 此外我们还需要Junit和spring测试才能进行单元测试 propertiesspring.framework.version3.2.3.RELEASE/spring.framework.versionspring.integration.version2.2.4.RELEASE/spring.integration.versionjunit.version4.11/junit.version/propertiesdependenciesdependencygroupIdorg.springframework/groupIdartifactIdspring-context/artifactIdversion${spring.framework.version}/version/dependencydependencygroupIdorg.springframework.integration/groupIdartifactIdspring-integration-core/artifactIdversion${spring.integration.version}/version/dependencydependencygroupIdjunit/groupIdartifactIdjunit/artifactIdversion${junit.version}/versionscopetest/scope/dependencydependencygroupIdorg.springframework/groupIdartifactIdspring-test/artifactIdversion${spring.framework.version}/versionscopetest/scope/dependency/dependencies 弹簧配置 我们必须在Spring配置中配置通道和网关以发送和接收消息 SpringIntegTest-context.xml ?xml version1.0 encodingUTF-8?
beans:beans xmlnshttp://www.springframework.org/schema/integration
xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance
xmlns:beanshttp://www.springframework.org/schema/beans
xmlns:contexthttp://www.springframework.org/schema/context
xsi:schemaLocationhttp://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-packageorg.springsample.integration/gateway idrequest service-interfaceorg.springsample.integration.SentRequest/channel idsendRequest/outbound-channel-adapter channelsendRequest refreceiveResponse methodprocessMessage /
/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(requestChannelsendRequest)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(MessageEmployee 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.namename;this.phonephone; this.addressaddress;
//……..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