搶先一步
VMware 提供培訓和認證,以加速您的進度。
了解更多親愛的 Spring 社群:
我們很高興地宣布 Spring Integration 4.1 里程碑 1 版本已發布。請使用 Maven 或 Gradle 的 Milestone Repository、下載發布封存檔,或參閱專案首頁取得更新的文件以及 Maven/Gradle 設定詳細資訊的連結。
此版本包含一些新功能和進一步的改進,以及許多錯誤修正,GA 版本預計在 10 月底左右發布。
以下是主要變更的摘要
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)。它對於 Spring Integration 非常有用,後者在執行階段大量使用 SpEL。您可以使用 spring.expression.compiler.mode
系統屬性(值為 IMMEDIATE
或 MIXED
)來啟用 SpEL 編譯器。
WebSocket 轉接器
已引入 WebSocket Inbound 和 Outbound Channel Adapters。它們建立在 Spring WebSocket 和 Messaging 基礎之上。
WebSockets 的關鍵功能之一是它是一種 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<?>
gateway 方法傳回類型的支援。
Boon JSON mapper
已為 JSON Transformers 新增 Boon JsonObjectMapper
實作。Boon 已被證明比 Jackson 具有更好的 JSON 映射效能。透過偵測 classpath 中的 jar,它會在 Spring Integration 中自動啟用。
Splitter Iterator
現在 <splitter>
s 可以傳回 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 改進。