Spring Integration 4.1 Milestone 1 釋出

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

親愛的 Spring 社群:

我們很高興地宣佈 Spring Integration 4.1 Milestone 1 已釋出。請使用 Maven 或 Gradle 的 Milestone Repository,下載 分發存檔,或訪問專案 主頁 獲取更新的文件以及 Maven/Gradle 配置詳情連結。

本次釋出包含一些新功能和進一步的改進,以及若干 bug 修復,GA 版本預計在十月底釋出。

以下是主要變更的摘要:

Spring Framework 4.1

Spring Integration 利用了 Spring Framework 4.1 中的多項新功能,並需要該版本支援。

更改包括:

  • 將更多的 Spring Integration API 遷移到核心 Spring Messaging 模組,並棄用 Spring Integration 中的對應介面。

移除以避免目標應用程式混淆;

  • 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)。這對於廣泛使用 SpEL 的 Spring Integration 在執行時非常有用。您可以透過設定系統屬性 spring.expression.compiler.modeIMMEDIATEMIXED 來啟用 SpEL 編譯器。

WebSocket 介面卡

引入了 WebSocket 入站和出站 Channel 介面卡。它們構建在 Spring WebSocket 和 Messaging 基礎之上。

WebSocket 的一個關鍵特性是它是一個 流式 協議,從 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 Transformer 添加了 Boon JsonObjectMapper 實現。Boon 在 JSON 對映效能上優於 Jackson。它透過檢測類路徑中是否存在其 jar 檔案,在 Spring Integration 中自動啟用。

Splitter 迭代器

<splitter> 現在可以返回 Iterator<?>Iterable<?> 作為 payload,以實現 流式 行為,即透過 Iterator.next() 傳送每個專案作為回覆訊息。

此外,我們還發布了兩個維護版本 3.0.54.0.4。強烈建議升級到最新版本,因為它們包含一些關鍵修復。

總結

有關更改的完整列表,請參閱 發行說明新功能介紹 和新元件的 Java Docs

當然,不要錯過 遷移指南

我們期待儘快收到您的評論和反饋(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 社群所有即將舉行的活動。

檢視所有