Spring Integration
Extends the Spring programming model to support the well-known Enterprise Integration Patterns. Spring Integration enables lightweight messaging within Spring-based applications and supports integration with external systems via declarative adapters. Those adapters provide a higher-level of abstraction over Spring‘s support for remoting, messaging, and scheduling. Spring Integration‘s primary goal is to provide a simple model for building enterprise integration solutions while maintaining the separation of concerns that is essential for producing maintainable, testable code.
spring integration 将spring 编程模型扩展成支持广为人知的"企业集成模式"。spring integration,通过可声明的适应器,使得在spring应用程序和外部系统的支持集成上建立轻量级的消息成为可能。那些适应器在spring对远程、消息、日程安排方面提供了高层次的抽象。spring integration的主要目标是提供一个简单的模型来构建“企业集成的解决方案”,同时对那些产生可持续、可测试代码非常重要的关注点维持隔离。
Introduction
Using the Spring Framework encourages developers to code using interfaces and use dependency injection (DI) to provide a Plain Old Java Object (POJO) with the dependencies it needs to perform its tasks. Spring Integration takes this concept one step further, where POJOs are wired together using a messaging paradigm and individual components may not be aware of other components in the application. Such an application is built by assembling fine-grained reusable components to form a higher level of functionality. WIth careful design, these flows can be modularized and also reused at an even higher level.
In addition to wiring together fine-grained components, Spring Integration provides a wide selection of channel adapters and gateways to communicate with external systems. Channel Adapters are used for one-way integration (send or receive); gateways are used for request/reply scenarios (inbound or outbound). For a full list of adapters and gateways, refer to the reference documentation.
The Spring XD project builds on Spring Integration, where Spring Integration modules are assembled into an XD Stream.
介绍
使用spring 框架使得开发者更有勇气使用接口来编程、使用依赖注入来为一个“简单的java对象(POJO)”提供它本身执行任务时需要的一些依赖对象。spring integrationj将这种概念更深了一步:被一个消息范例和一些个体元件接通的POJOs可能并不会意识到应用中的其它元件。这样的一个应用被可装配的细颗粒的可重用的元件创建来形成一个更高级别的功能。通过精心的设计,这些流量可以被模块化,甚至可以被重用在一个更高的级别。
除了接通细颗粒的元件外,spring integration在channel adapters 和 同外部系统交互gateways方面还提供了一个广泛的选择。channel adapters 被用来做单程的集成(发送或者接收);gateways 被用在请求/应答 场景(呼入或呼出)。关于完整的adapters和gateways列表,参考相应文档。
Spring XD 项目构建在Spring integration上,spring integration 组件被装配进 一个 XD流中。
Features
- Implementation of most of the Enterprise Integration Patterns
- Endpoint
- Channel (Point-to-point and Publish/Subscribe)
- Aggregator
- Filter
- Transformer
- Control Bus
- ...
- Integration with External Systems
- ReST/HTTP
- FTP/SFTP
- WebServices (SOAP and ReST)
- TCP/UDP
- JMS
- RabbitMQ
- ...
- The framework has extensive JMX support
- Exposing framework components as MBeans
- Adapters to obtain attributes from MBeans, invoke operations, send/receive notifications
特征:
1.多数“企业集成模式”的实现:
- Endpoint :端点
- Channel (Point-to-point and Publish/Subscribe) :通道(点对点和发布/订阅)
- Aggregator:聚合器
- Filter:过滤器
- Transformer:转换器
- Control Bus : 控制总线
- ……
2.同外部系统的集成:
- ReST/HTTP
- FTP/SFTP
- WebServices (SOAP and ReST)
- TCP/UDP
- JMS
- RabbitMQ
- ...
3.这个框架提供扩展到jmx的支持。(Java Management Extensions,即Java管理扩展,是一个为应用程序、设备、系统等植入管理功能的框架。)
- 将框架组件作为MBeans暴露。(管理构件(MBean:在JMX规范中,管理构件定义如下:它是一个能代表管理资源的Java对象,遵从一定的设计模式,还需实现该规范定义的特定的接口。该定义了保证了所有的管理构件以一种标准的方式来表示被管理资源。)
- Adapters 从MBeans获得属性,调用操作,发送/接收通知。
3.这个框架提供扩展到jmx的支持。(Java Management Extensions,即Java管理扩展,是一个为应用程序、设备、系统等植入管理功能的框架。)
Quick Start
The recommended way to get started using spring-integration
in your project is with a dependency management system – the snippet below can be copied and pasted into your build. Need help? See our getting started guides on building with Maven and Gradle
在你的项目中开始使用spring-integration,推荐的方式是使用一个依赖管理系统:下面的代码片段可以被拷贝粘贴到你的系统中。若需要帮助,参考Maven 和Gradle的getting started文档。
<dependencies>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-core</artifactId>
<version>4.0.3.RELEASE</version>
</dependency>
</dependencies>
In the following "quick start" application you can see that the same gateway interface is used to invoke two completely different service implementations. To build and run this program you will need the spring-integration-ws and spring-integration-xml modules as described above.
在下面的“快速开始”应用中,你可以看到同样的gateway 接口被用来调用两个完全不同的服务实现。构建和运行这个程序,你需要上面已经描述过的spring-integration-ws 和sping-integration-xml组件。
public class Main {
public static void main(String... args) throws Exception {
ApplicationContext ctx =
new ClassPathXmlApplicationContext("context.xml");
// Simple Service
TempConverter converter =
ctx.getBean("simpleGateway", TempConverter.class);
System.out.println(converter.fahrenheitToCelcius(68.0f));
// Web Service
converter = ctx.getBean("wsGateway", TempConverter.class);
System.out.println(converter.fahrenheitToCelcius(68.0f));
}
}
public interface TempConverter {
float fahrenheitToCelcius(float fahren);
}
<!-- Simple Service -->
<int:gateway id="simpleGateway"
service-interface="foo.TempConverter"
default-request-channel="simpleExpression" />
<int:service-activator id="expressionConverter"
input-channel="simpleExpression"
expression="(payload - 32) / 9 * 5"/>
<!-- Web Service -->
<int:gateway id="wsGateway" service-interface="foo.TempConverter"
default-request-channel="viaWebService" />
<int:chain id="wsChain" input-channel="viaWebService">
<int:transformer
expression="‘<FahrenheitToCelsius xmlns=‘‘http://tempuri.org/‘‘><Fahrenheit>XXX</Fahrenheit></FahrenheitToCelsius>‘.replace(‘XXX‘, payload.toString())" />
<int-ws:header-enricher>
<int-ws:soap-action value="http://tempuri.org/FahrenheitToCelsius"/>
</int-ws:header-enricher>
<int-ws:outbound-gateway
uri="http://www.w3schools.com/webservices/tempconvert.asmx"/>
<int-xml:xpath-transformer
xpath-expression="/*[local-name()=‘FahrenheitToCelsiusResponse‘]/*[local-name()=‘FahrenheitToCelsiusResult‘]"/>
</int:chain>