领先一步
VMware 提供培训和认证,助您加速进步。
了解更多亲爱的 Spring 社区:
我们很高兴地宣布 Spring Integration 4.1 Milestone 1 已发布。请使用 Maven 或 Gradle 的 Milestone Repository,下载 分发存档,或访问项目 主页 获取更新的文档以及 Maven/Gradle 配置详情链接。
本次发布包含一些新功能和进一步的改进,以及若干 bug 修复,GA 版本预计在十月底发布。
以下是主要变更的摘要:
Spring Framework 4.1
Spring Integration 利用了 Spring Framework 4.1 中的多项新功能,并需要该版本支持。
更改包括:
移除以避免目标应用程序混淆;
Spring Framework 4.1 中包含多项 Messaging 性能改进。
Spring Framework 4.1 引入了 [SpEL 编译器](http://docs.spring
.io/spring/docs/current/spring-framework-reference/html/expressions.html#expressions-spel-compilation)。这对于广泛使用 SpEL 的 Spring Integration 在运行时非常有用。您可以通过设置系统属性 spring.expression.compiler.mode 为 IMMEDIATE 或 MIXED 来启用 SpEL 编译器。
WebSocket 适配器
引入了 WebSocket 入站和出站 Channel 适配器。它们构建在 Spring WebSocket 和 Messaging 基础之上。
WebSocket 的一个关键特性是它是一个 流式 协议,从 Java 的角度来看,它基于与服务器端和客户端相同的 API,因此我们可以在双方使用相似的组件构建集成流。
服务器端
@Configuration
@EnableIntegration
public class ServerConfig {
@Bean
public ServerWebSocketContainer serverWebSocketContainer() {
return new ServerWebSocketContainer("/ws").withSockJs();
}
@Bean
public MessageProducer webSocketInboundChannelAdapter() {
WebSocketInboundChannelAdapter webSocketInboundChannelAdapter =
new WebSocketInboundChannelAdapter(serverWebSocketContainer());
webSocketInboundChannelAdapter.setOutputChannel(webSocketInputChannel());
return webSocketInboundChannelAdapter;
}
@Bean
@Transformer(inputChannel = "webSocketInputChannel", outputChannel = "webSocketOutputChannel")
public ExpressionEvaluatingTransformer transformer() {
return new ExpressionEvaluatingTransformer(PARSER.parseExpression("'Hello ' + payload"));
}
@Bean
@ServiceActivator(inputChannel = "webSocketOutputChannel")
public MessageHandler webSocketOutboundMessageHandler() {
return new WebSocketOutboundMessageHandler(serverWebSocketContainer());
}
}
客户端
@Configuration
@EnableIntegration
public class ClientConfig {
@Bean
public WebSocketClient webSocketClient() {
return new SockJsClient(Collections.<Transport>singletonList(
new WebSocketTransport(new JettyWebSocketClient())));
}
@Bean
public IntegrationWebSocketContainer clientWebSocketContainer() {
return new ClientWebSocketContainer(webSocketClient(), "ws://host:port/ws");
}
@Bean
public MessageProducer webSocketInboundChannelAdapter() {
WebSocketInboundChannelAdapter webSocketInboundChannelAdapter =
new WebSocketInboundChannelAdapter(clientWebSocketContainer());
webSocketInboundChannelAdapter.setOutputChannel(webSocketInputChannel());
return webSocketInboundChannelAdapter;
}
@Bean
@ServiceActivator(inputChannel = "webSocketOutputChannel")
public MessageHandler webSocketOutboundMessageHandler() {
return new WebSocketOutboundMessageHandler(clientWebSocketContainer());
}
}
另一个简单的集成 Spring WebSockets 和 STOMP 子协议的方法是使用 @MessageMapping 注解,但将其用于 @MessagingGateway 接口,以使用集成流来处理请求和发送响应。
@MessagingGateway
@Controller
public interface WebSocketGateway {
@MessageMapping("/greeting")
@SendToUser("/queue/answer")
@Gateway(requestChannel = "greetingChannel")
String greeting(String payload);
}
Reactor 支持
添加了 Promise<?> Gateway 来支持 Project Reactor。现在 Spring Integration 消息流可以作为 Reactive Streams 的一部分。
@MessagingGateway(reactorEnvironment = "reactorEnv")
public interface PromiseGateway {
@Gateway(requestChannel = "promiseChannel")
Promise<Integer> multiply(Integer value);
}
...
@ServiceActivator(inputChannel = "promiseChannel")
public Integer multiply(Integer value) {
return value * 2;
}
...
Streams.defer(Arrays.asList("1", "2", "3", "4", "5"))
.env(this.environment)
.get()
.map(Integer::parseInt)
.mapMany(integer -> promiseGateway.multiply(integer))
.collect()
.consume(integers -> ...)
.flush();
此外,还增加了对 Spring Framework ListenableFuture<?> 网关方法返回类型的支持。
Boon JSON 映射器
为 JSON Transformer 添加了 Boon JsonObjectMapper 实现。Boon 在 JSON 映射性能上优于 Jackson。它通过检测类路径中是否存在其 jar 文件,在 Spring Integration 中自动启用。
Splitter 迭代器
<splitter> 现在可以返回 Iterator<?> 和 Iterable<?> 作为 payload,以实现 流式 行为,即通过 Iterator.next() 发送每个项目作为回复消息。
此外,我们还发布了两个维护版本 3.0.5 和 4.0.4。强烈建议升级到最新版本,因为它们包含一些关键修复。
总结
有关更改的完整列表,请参阅 发行说明、新功能介绍 和新组件的 Java Docs。
当然,不要错过 迁移指南。
我们期待尽快收到您的评论和反馈(StackOverflow (spring-integration 标签)、Spring JIRA),并在 GA 版本发布前的几个月内报告您发现的问题。
SpringOne 2GX 2014
下周在 SpringOne 上将涵盖其中一些话题。请参加 [Gary Russell 的演讲](https://2014.event.springone2gx.com/schedule/sessions/spring_integration_java_configuration_and_more.html),以了解更多关于这些以及过去12个月中添加的其他 Spring Integration 改进。