Spring Integration 4.1 RC1 釋出

釋出 | Artem Bilan | 2014 年 10 月 27 日 | ...

尊敬的 Spring 社群:

我們很高興地宣佈 Spring Integration 4.1 Release Candidate 已釋出。 請使用 Milestone Repository 與 Maven 或 Gradle,或下載 distribution archive,進行試用。

此版本包含許多新功能和改進,以及一些錯誤修復。 GA 版本計劃於 11 月初發布。

首先,感謝所有為 4.1 Milestone 1 提供反饋並提交報告(錯誤或新功能)的人員。 特別感謝那些透過 Pull Requests 提供貢獻的人。 以下是自里程碑版本以來的主要更改摘要

Web Sockets 支援

此功能在 4.1 Milestone 1 中引入,但已解決了一些問題,並且我們現在提供了一些示例,以更好地瞭解如何在 Spring Integration 應用程式中使用 Web Sockets:BasicSTOMP 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 註釋中 required 屬性的替代方法。

Routing Slip 模式

現在支援 Routing Slip 模式。 我們引入了 RoutingSlipRouteStrategy,它提供基於請求 Message<?>reply object 的動態執行時路由,而不是簡單的 static list of channel names。 也支援 SpEL

<header-enricher input-channel="input" output-channel="process">
	<routing-slip value="channel1; request.headers[myRoutingSlipChannel];
	                        routingSlipRoutingStrategy;"/>
</header-enricher>

當配置多個路由器來確定訊息流變得困難時,此模式在複雜的動態情況下非常有用。 透過此增強功能,當訊息到達沒有 output-channel 的端點時,將查詢路由滑塊以確定訊息將傳送到的下一個通道。 當路由滑塊耗盡時,正常的 replyChannel 處理將恢復。

Idempotent Receiver 模式

在此版本中,我們已將 Idempotent Receiver 實現為一流的功能。 以前,使用者必須透過在 <filter/> 中使用自定義 MessageSelector 來實現此模式。 該框架現在支援此功能作為 Advice 元件,該元件可以應用於任何消耗端點

<idempotent-receiver endpoint="endpoint1, foo*"
				     metadata-store="store"
					 discard-channel="duplicates"
					 key-expression="payload.invoiceNumber"/>

這將建立一個 AOP IdempotentReceiverInterceptor,該攔截器應用於 MessageHandler#handleMessage 在其中 id 與提供的 endpoint 模式之一匹配的端點內。

如果省略了 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 模式

現在提供了 Scatter-Gather 企業整合模式

<!--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 邏輯和 aggregation 函式。 當然,它以前可以使用現有的 publish-subscribe-channelrecipient-list-router 以及 aggregator 元件實現為整合流,但是此新功能為諸如 best quote 之類的場景提供了更清晰的實現。

Redis 佇列閘道器

基於 Redis List 的一對 request-reply(入站和出站)閘道器元件已新增到 Redis 模組中

<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());
}

跳過輪詢

使用輪詢端點時,有時需要“跳過”輪詢,可能是因為某些下游條件可能導致失敗,或者說,任務執行程式池沒有可用的執行緒。 此版本添加了 PollSkipAdvice,可以將其插入輪詢器的 advice 鏈中,跳過邏輯基於使用者提供的程式碼。

注意

  1. Spring Integration 4.1 需要 Spring Framework 4.1
  2. 雖然現在需要 JDK8 才能構建 Spring Integration,但該框架在執行時仍然與 Java 6 相容。
  3. 我們希望在本週晚些時候宣佈 Spring Integration Java DSL 釋出候選版的可用性。

結論

有關此版本的更多資訊,請參見發行說明,有關更多資訊,請參見專案頁面。有關4.1版本中“新增功能”的完整列表,請參見參考文件。從早期版本升級的使用者應查閱各種遷移指南

與往常一樣,我們非常歡迎貢獻

獲取 Spring 新聞通訊

透過 Spring 新聞通訊保持聯絡

訂閱

搶先一步

VMware 提供培訓和認證,以加速您的進步。

瞭解更多

獲得支援

Tanzu Spring 在一個簡單的訂閱中提供 OpenJDK™、Spring 和 Apache Tomcat® 的支援和二進位制檔案。

瞭解更多

即將舉行的活動

檢視 Spring 社群中所有即將舉行的活動。

檢視所有