领先一步
VMware 提供培训和认证,以加速您的进步。
了解更多尊敬的 Spring 社区:
我们很高兴地宣布 Spring Integration 4.1 Milestone 1 已发布。请使用 Milestone 仓库 与 Maven 或 Gradle,下载 发布存档,或查看项目主页 获得更新的文档链接以及 Maven/Gradle 配置详细信息。
此版本包含一些新功能和进一步的改进,以及许多错误修复,GA 版本预计在 10 月底左右发布。
以下是主要更改的摘要
Spring Framework 4.1
Spring Integration 利用了 Spring Framework 4.1 中的许多新功能,并且需要该版本。
更改包括
或删除以避免目标应用程序中的混淆;
Spring Framework 4.1 中包含许多消息传递性能改进。
Spring Framework 4.1 引入了 [SpEL 编译器](http://docs.spring
.io/spring/docs/current/spring-framework-reference/html/expressions.html#expressions-spel-compilation)。它对于 Spring Integration 非常有用,Spring Integration 在运行时广泛使用 SpEL。您可以使用值为 IMMEDIATE
或 MIXED
的 spring.expression.compiler.mode
系统属性启用 SpEL 编译器。
WebSocket 适配器
引入了 WebSocket 入站和出站通道适配器。它们构建在 Spring WebSocket 和 Messaging 基础之上。
WebSocket 的关键特性之一是它是一种 streaming
协议,并且从 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 转换器添加了 Boon JsonObjectMapper
实现。Boon 已被证明具有比 Jackson 更好的 JSON 映射性能。通过检测其 jar 在类路径中,可在 Spring Integration 中自动启用它。
Splitter 迭代器
<splitter>
现在可以返回 Iterator<?>
和 Iterable<?>
作为 payload
以实现 streaming
行为,当每个项目都使用 Iterator.next()
作为回复消息发出时。
此外,我们还发布了两个维护版本 3.0.5 和 4.0.4。强烈建议升级到最新版本,因为它们包含一些关键修复。
总结
有关更改的完整列表,请参阅 发行说明、新功能 和 Java 文档 的新组件。
当然,不要错过 迁移指南。
我们期待您的评论和反馈(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 改进的信息。