Spring Integration 4.1 Milestone 1 釋出

釋出 | Artem Bilan | 2014年9月5日 | ...

尊敬的 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 Integration API 遷移到 Core Spring Messaging 模組,並且 Spring Integration 等效項已棄用

或刪除以避免目標應用程式中的混淆;

  • 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。您可以使用值為 IMMEDIATEMIXEDspring.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.54.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 改進的資訊。

獲取 Spring 新聞簡報

隨時瞭解 Spring 新聞簡報

訂閱

領先一步

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

瞭解更多

獲取支援

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

瞭解更多

即將舉行的活動

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

檢視所有