Spring Integration 5.2.5

扩展Spring编程模型以支持著名的企业集成模式。Spring集成支持基于Spring的应用程序中的轻量级消息传递,并支持通过声明性适配器与外部系统集成。这些适配器比Spring对远程处理、消息传递和调度的支持提供了更高层次的抽象。Spring Integration的主要目标是为构建企业集成解决方案提供一个简单的模型,同时维护对生成可维护、可测试代码至关重要的关注点分离。
介绍
使用Spring框架鼓励开发人员使用接口编写代码,并使用依赖注入(DI)来提供一个普通的旧Java对象(POJO),其中包含执行任务所需的依赖项。Spring集成将这一概念向前推进了一步,其中pojo使用消息传递范式连接在一起,单个组件可能不知道应用程序中的其他组件。这样的应用程序是通过组装细粒度的可重用组件来构建的,以形成更高级别的功能。经过仔细的设计,这些流可以模块化,也可以在更高的层次上重用。
除了将细粒度组件连接在一起之外,Spring集成还提供了多种通道适配器和网关,用于与外部系统通信。通道适配器用于单向集成(发送或接收);网关用于请求/答复方案(入站或出站)。有关适配器和网关的完整列表,请参阅参考文档。
Spring Cloud Stream项目建立在Spring Integration之上,springintegration用作消息驱动微服务的引擎。
特征
大多数企业集成模式的实现
终点
频道(点对点和发布/订阅)
聚合器
过滤器
变压器
控制总线

与外部系统集成
ReST/HTTP协议
FTP/SFTP协议
推特
WebServices(SOAP和ReST)
TCP/UDP协议
JMS公司
拉比马克
电子邮件

该框架具有广泛的JMX支持
将框架组件公开为mbean
从mbean获取属性、调用操作、发送/接收通知的适配器
实例
在下面的“快速启动”应用程序中,您可以看到相同的网关接口用于调用两个完全不同的服务实现。要构建和运行此程序,您将需要如上所述的spring integration ws和spring 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);

}

<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"/>

<int:gateway id=“wsGateway” service-interface=“foo.TempConverter”
default-request-channel=“viaWebService” />

<int:chain id=“wsChain” input-channel=“viaWebService”>
<int:transformer
expression="’<FahrenheitToCelsius xmlns=“https://www.w3schools.com/xml/”><Fahrenheit>XXX</Fahrenheit></FahrenheitToCelsius>’.replace(‘XXX’, payload.toString())" />
int-ws:header-enricher
<int-ws:soap-action value=“https://www.w3schools.com/xml/FahrenheitToCelsius”/>
</int-ws:header-enricher>
<int-ws:outbound-gateway
uri=“https://www.w3schools.com/xml/tempconvert.asmx”/>
<int-xml:xpath-transformer
xpath-expression="/[local-name()=‘FahrenheitToCelsiusResponse’]/[local-name()=‘FahrenheitToCelsiusResult’]"/>
</int:chain>

And here is the same application (web service part) using the Java DSL (and Spring Boot). You will need the spring-boot-starter-integration dependency or spring-integration-java-dsl directly if you don’t use Spring Boot. If you use Spring Integration starting version 5.0, you don’t need any additional dependencies - the Java DSL is included to the core project:

@Configuration
@SpringBootApplication
@IntegrationComponentScan
public class Application {

public static void main(String[] args) {
ConfigurableApplicationContext ctx = SpringApplication.run(Application.class, args);
TempConverter converter = ctx.getBean(TempConverter.class);
System.out.println(converter.fahrenheitToCelcius(68.0f));
ctx.close();
}

@MessagingGateway
public interface TempConverter {

@Gateway(requestChannel = "convert.input")
float fahrenheitToCelcius(float fahren);

}

@Bean
public IntegrationFlow convert() {
return f -> f
.transform(payload ->
“<FahrenheitToCelsius xmlns=“https://www.w3schools.com/xml/”>”
+ “” + payload + “”
+ “”)
.enrichHeaders(h -> h
.header(WebServiceHeaders.SOAP_ACTION,
“https://www.w3schools.com/xml/FahrenheitToCelsius”))
.handle(new SimpleWebServiceOutboundGateway(
“https://www.w3schools.com/xml/tempconvert.asmx”))
.transform(Transformers.xpath("/[local-name()=“FahrenheitToCelsiusResponse”]"
+ "/
[local-name()=“FahrenheitToCelsiusResult”]"));
}

}

Spring Boot Config
Spring Boot Autoconfiguration for Spring Integration
Spring Initializr
Quickstart Your Project
Bootstrap your application with Spring Initializr.

发布了0 篇原创文章 · 获赞 135 · 访问量 4922

猜你喜欢

转载自blog.csdn.net/blog_programb/article/details/105134669
今日推荐