Spring Integration 4.0 發布候選版本已推出

發布 | Artem Bilan | 2014 年 4 月 15 日 | ...

我們很高興宣布 Spring Integration 4.0 發布候選版本 (4.0.0.RC1) 現已推出。 請使用 Milestone Repository 搭配 Maven 或 Gradle、下載 發布封存,或參閱專案首頁取得更新的文件及 Maven/Gradle 組態詳細資訊連結。

此版本包含多個錯誤修正、一些新功能,以及進一步的改進,GA 版本預計在四月底推出。

以下是自上次的里程碑版本以來的主要變更摘要

@Poller 和 @InboundChannelAdapter

建立在M4 發布版本中宣布的註解支援的廣泛改進基礎上,新的 @Poller 註解已新增至每個 Messaging Annotation (@ServiceActivator@Router 等)。@Poller 註解屬性能夠為 Messaging Annotation 的 inputChannel 設定 poller 選項。 這允許使用註解的端點成為 PollingConsumer。 之前,使用註解的端點只能使用 SubscribableChannel 並成為事件驅動。

這也讓我們能夠引入 @InboundChannelAdapter 方法 Messaging Annotation。 現在可以不用 XML 進行設定,例如在 Spring Boot 應用程式中

@EnableAutoConfiguration  // enables integration infrastructure
@MessageEndpoint          // makes this class as an integration component
@PropertySource("classpath:integration.properties") // property-placeholder configuration
public class Integration {

    public static void main(String[] args) throws Exception {
        ConfigurableApplicationContext ctx = SpringApplication.run(Integration.class, args);
        Thread.sleep(10000);
        ctx.close();
    }

	@InboundChannelAdapter(value = "countChannel",
         poller = @Poller(fixedDelay = "${poller.interval}", maxMessagesPerPoll = "1"))
	public Integer count() {
		return this.counter.incrementAndGet();
	}

 	@ServiceActivator(inputChannel="countChannel")
    public void foo(Integer payload) {
        System.out.println(payload);
    }
        
}

這相當於以下 XML 組態

<int:inbound-channel-adapter channel="countChannel" ref="counter" method="incrementAndGet">
	<int:poller fixed-delay="${poller.interval}" max-messages-per-poll="1"/>
</int:inbound-channel-adapter>

<int-stream:stdout-channel-adapter id="countChannel"/>

分散式 MetadataStore 和 LockRegistry

MetadataStore 的設計目的是儲存各種泛型 meta-data (例如,已處理的最新 feed 條目的發布日期),以協助元件 (例如 Feed Adapter) 維護狀態並避免重複。 針對分散式環境和多個執行個體應用程式,為了讓持續性 metadata 狀態在應用程式重新啟動後仍能維持,此版本導入了 RedisMetadataStoreGemfireMetadataStore

例如,可以設定一個 <int-file:inbound-channel-adapter> 並搭配 FileSystemPersistentAcceptOnceFileListFilter,而 FileSystemPersistentAcceptOnceFileListFilter 又可以設定為使用這些分散式 MetadataStore 的其中一個。 這允許 filter keys 在多個應用程式執行個體之間共用,或多個伺服器正在使用網路檔案共用時共用。

對於類似的分散式 (跨 JVM) 環境,當只有一個執行個體可以存取物件時 (例如,MessageGroup 到達訊息時的 AggregatorHandler),已導入分散式 LockRegistry 實作 - RedisLockRegistryGemfireLockRegistry

彙總器自動群組發布

現在 <aggregator><resequencer> 端點可以具有 group-timeoutgroup-timeout-expression 選項,以允許這些關聯端點在群組閒置一段時間後採取動作。 之前,您必須為此目的設定外部 MessagGroupStoreReapergroupTimeout 屬性會在 Message 到達後排程強制完成 MessageGroup 的時間,而該事件不會導致 ReleaseStrategy 發布群組。

從這個角度來看,可能更有趣的是 group-timeout-expression。 它允許在訊息到達時,根據群組的狀態在執行階段動態決定 groupTimeout 值。 例如

<aggregator input-channel="input" output-channel="output" discard-channel="discard"
        send-partial-result-on-expiry="true"
        group-timeout-expression="size() ge 2 ? 1000 : -1"
        release-strategy="someReleaseStrategy"/>

在這種情況下,如果群組中只有 1 個訊息,則群組永遠不會逾時,但只要群組包含至少 2 個訊息,Aggregator 就會在閒置 1 秒後自動傳送部分 MessageGroup

優先順序通道和訊息儲存

在此版本中,您可以使用外部 MessageStore 設定 <priority-queue>。 為此,我們導入了新的 PriorityCapableChannelMessageStore 策略,並提供 JDBC、Redis 和 MongoDB 的實作。 現在允許在優先順序通道中進行訊息持久性。

Twitter 搜尋閘道

現有的 twitter <search-inbound-channel-adapter> 只允許在每次輪詢時執行固定的查詢。 為了獲得更大的彈性,已新增 <int-twitter:search-outbound-gateway/> 作為一個元件,以根據 search-args-expression 執行任意的要求/回覆 Twitter 搜尋作業。 預設值為 payload,可以是搜尋字串或 org.springframework.social.twitter.api.SearchParameters 的一個執行個體。 但是,這個屬性可以在 SpEL 中設定為

"new SearchParameters(payload).count(5).sinceId(headers.sinceId)"

"{payload, 30}"

作為 SpEL 行內清單 - 在這種情況下為查詢字串和頁面大小,或...

"{payload, headers.pageSize, headers.sinceId, headers.maxId}"

org.springframework.social.twitter.api.SearchOperations#search 的四個引數。 如需詳細資訊,請參閱 Spring Social Twitter 文件。

總結

如需完整的變更清單,請參閱發布說明新功能和新元件的Java 文件

我們期待您的意見反應 (Spring 論壇StackOverflow (spring-integration 標籤)、Spring JIRA),並在我們在本月底 GA 之前盡快回報您發現的問題。

SpringOne 2GX 2014 即將到來

請盡快預訂在 德州達拉斯舉行的 SpringOne (9 月 8-11 日) 的席位。 這是直接了解所有最新資訊並提供直接意見反應的最佳機會。 今年預計會有許多重要的新公告。 我們預期會展示多場深入的 Spring-Integration 會議。

取得 Spring 電子報

訂閱 Spring 電子報以保持聯繫

訂閱

領先一步

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

深入了解

取得支援

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

深入了解

即將到來的活動

查看 Spring 社群中所有即將到來的活動。

檢視所有內容