領先一步
VMware 提供培訓和認證,助您加速進步。
瞭解更多親愛的 Spring 社群:
我們很高興地宣佈 Spring Integration 4.1 Release Candidate 已釋出。請使用 Milestone Repository 配合 Maven 或 Gradle,或者下載 分發存檔 來進行試用。
本次釋出包含許多新功能和改進,以及一些 bug 修復。GA 版本計劃在十一月初發布。
首先,感謝所有為 4.1 Milestone 1 提供反饋並提交報告(bug 或新功能)的人。特別感謝那些透過 Pull Requests 做出貢獻的人。以下是自里程碑版本以來的主要變更摘要:
WebSocket 支援
此功能在 4.1 Milestone 1 中引入,但已修復了若干問題,現在我們提供了幾個示例來更好地理解如何在 Spring Integration 應用程式中使用 WebSocket:Basic 和 STOMP Chat。
JDK8 Optional<?> 一致性處理
如果您使用 Java 8,將能夠使用 Optional<?> 容器作為服務方法的引數。例如:
public void optionals(@Payload("@myConvert.conv(payload)") Optional<Bar> payload,
@Header(value="foo") Optional<String> header)
在這種情況下,如果 @myConvert.conv(payload) 返回 null,則 payload 變數將包含 Optional.empty()。對於 header 變數也是如此——如果請求 Message<?> 中沒有 foo 頭,則 header 變數將包含 Optional.empty()。這可以作為 @Header 註解上 required 屬性的替代方案。
路由跳轉模式 (Routing Slip pattern)
現在支援 路由跳轉模式。我們引入了 RoutingSlipRouteStrategy,它允許根據請求 Message<?> 和 reply object 進行動態執行時路由,而不是一個簡單的 靜態通道名稱列表。SpEL 也受支援。
<header-enricher input-channel="input" output-channel="process">
<routing-slip value="channel1; request.headers[myRoutingSlipChannel];
routingSlipRoutingStrategy;"/>
</header-enricher>
此模式在複雜、動態的場景下非常有用,當配置多個路由器來確定訊息流變得困難時。有了這個增強功能,當訊息到達一個沒有 output-channel 的端點時,就會查詢路由跳轉列表來確定訊息將被髮送到的下一個通道。當路由跳轉列表耗盡時,將恢復正常的 replyChannel 處理。
冪等接收者模式 (Idempotent Receiver pattern)
在此版本中,我們將 冪等接收者 實現為一項一流功能。以前,使用者需要透過在 <filter/> 中使用自定義 MessageSelector 來實現此模式。現在,框架支援此功能,並將其作為 Advice 元件應用於任何消費端點。
<idempotent-receiver endpoint="endpoint1, foo*"
metadata-store="store"
discard-channel="duplicates"
key-expression="payload.invoiceNumber"/>
這會建立一個 AOP IdempotentReceiverInterceptor,它應用於端點中 id 與提供的 endpoint 模式之一匹配的 MessageHandler#handleMessage。
如果省略 discard-channel,重複的訊息仍會發送給訊息處理程式,但它將包含一個 duplicateMessage 頭,允許使用者程式碼採取進一步的操作。
對於 JavaConfig,提供了 @IdempotentReceiver 註解,但 IdempotentReceiverInterceptor @Bean 也必須進行配置。
@Bean
public IdempotentReceiverInterceptor idempotentReceiverInterceptor() {
return new IdempotentReceiverInterceptor(new MetadataStoreSelector(m ->
m.getPayload().toString()));
}
@Bean
@ServiceActivator(inputChannel = "input", outputChannel = "output")
@IdempotentReceiver("idempotentReceiverInterceptor")
public MessageHandler myService() {
....
}
有關更多資訊,請閱讀 IdempotentReceiverInterceptor JavaDocs。
散佈-收集模式 (Scatter-Gather pattern)
現在提供 散佈-收集 企業整合模式。
<!--Auction scenario-->
<scatter-gather input-channel="inputAuction" output-channel="output"
scatter-channel="auctionChannel">
<gatherer release-strategy-expression="^[payload gt 5] != null or size() == 3"/>
</scatter-gather>
<!--Distribution scenario-->
<scatter-gather input-channel="inputDistribution" output-channel="output"
gather-channel="gatherChannel">
<scatterer apply-sequence="true">
<recipient channel="distribution1Channel"/>
<recipient channel="distribution2Channel"/>
<recipient channel="distribution3Channel"/>
</scatterer>
<gatherer release-strategy-expression="^[payload gt 5] != null or size() == 3"/>
</scatter-gather>
它是一個複合端點,結合了 釋出-訂閱 邏輯和 聚合 功能。當然,以前也可以將其作為整合流實現,使用現有的 publish-subscribe-channel 或 recipient-list-router,以及 aggregator 元件,但這個新功能為諸如 最佳報價 之類的場景提供了更簡潔的實現。
Redis 佇列閘道器 (Redis Queue Gateways)
在 Redis 模組中添加了一對基於 Redis List 的 request-reply(入站和出站)閘道器元件。
<int-redis:queue-outbound-gateway request-channel="sendChannel" queue="foo"/>
<int-redis:queue-inbound-gateway request-channel="requestChannel" queue="foo"/>
Reactor 的 PersistentQueue
QueueChannel 已被修改為允許注入任何 Queue<?> 實現。這樣做是為了允許在 [Reactor] (http://reactor.github.io/reactor/) 專案中使用 Chronicle-Queue 實現。
@Bean QueueChannel queueChannel() {
return new QueueChannel(new PersistentQueueSpec<Message<?>>()
.codec(new JavaSerializationCodec<>())
.basePath("/usr/queuePath")
.get());
}
跳過輪詢 (Skipping Polls)
在使用輪詢端點時,有時需要“跳過”輪詢,可能是因為下游的某些條件可能導致失敗,或者任務執行器池沒有可用執行緒。本次釋出添加了 PollSkipAdvice,可以將其插入到輪詢器的建議鏈中,其跳過邏輯基於使用者提供的程式碼。
註釋
結論
有關此版本的 發行說明,以及更多資訊,請訪問 專案主頁。有關 4.1 版本“新增內容”的完整列表,請參閱 參考文件。從早期版本升級的使用者應查閱各種 遷移指南。
一如既往,我們非常歡迎 貢獻。