Spring Integration Java DSL 1.1 M2 版本已釋出

發佈 | Artem Bilan | 2015 年 9 月 10 日 | ...

我們很高興地宣布 Spring Integration Java DSL 的 Milestone 2 版本已可從 Milestone Repository 下載

Gradle 請使用以下設定

compile "org.springframework.integration:spring-integration-java-dsl:1.1.0.M2"

Maven 請使用以下設定

<dependency>
     <groupId>org.springframework.integration</groupId>
     <artifactId>spring-integration-java-dsl</artifactId>
     <version>1.1.0.M2</version>
</dependency>

Milestone 1 以來,沒有太多新功能,但以下是您應該注意的重點

Spring Integration 4.2 基礎

Spring Integration Java DSL 1.1 現在基於 Spring Integration 4.2,並成為即將推出的 Spring IO 2.0 的一部分。Java DSL 的 1.1 版本不再與 Spring Integration 4.1.x 相容。

Spring Integration Kafka 1.2.x 升級

我們現在為 Spring Integration Kafka 配接器提供 Kafka 命名空間工廠。新的 Spring Integration Kafka 1.2 版本 與升級到 Apache Kafka 0.8.2 一起帶來了一些重大變更。因此,這個 Java DSL Milestone 2 的 1.1 版本不再與先前版本的 Spring Integration Kafka 和 Apache Kafka 相容。

HTTP 命名空間工廠

Spring Integration HTTP 配接器現在由其特定的 Http 命名空間工廠涵蓋。請參考我們經典的 HTTP Proxy 範例,但這次是用 Java DSL 編寫

@Bean
public IntegrationFlow httpProxyFlow() {
    return IntegrationFlows
        .from((MessagingGateways g) ->
               g.httpGateway("/proxy")
                     .requestMapping(r -> r.params("name"))
                     .payloadFunction(httpEntity ->
                           ((ServletRequestAttributes) RequestContextHolder
                                                     .currentRequestAttributes())
						.getRequest()
						.getQueryString()))
        .handleWithAdapter(a ->
              a.httpGateway(m ->
                   String.format("http://target/service?%s", m.getPayload()))
                              .expectedResponseType(String.class))
        .get();
}

Reactive Streams 支援

我們很高興地宣布 Spring Integration 開始提供與 Reactive Streams 的整合,並且直接在 Java DSL 中提供了對 Publisher 的支援

@Bean
public Publisher<Message<String>> reactiveFlow() {
	return IntegrationFlows
		.from(() -> new GenericMessage<>("a,b,c,d,e,f"))
		.split(String.class, p -> p.split(","))
		.toReactivePublisher();
}

如您所見,從 Spring Integration 世界轉到 Reactive Streams 世界很簡單。然後可以將 org.reactivestreams.Publisher bean 用作 Reactive 程式的事件來源,例如使用 Project Reactor 實作

@Autowired
@Qualifier("reactiveFlow")
private Publisher<Message<String>> publisher;
....
List<String> results = new ArrayList<>();
CountDownLatch latch = new CountDownLatch(6);
Streams.wrap(this.publisher)
	.map(m -> m.getPayload().toUpperCase())
	.consume(p -> {
			results.add(p);
			latch.countDown();
		});

另一個方向 - 從 Reactive Stream 到 Spring Integration - 也同樣簡單 (從 Reactor 的角度來看)

.consume(v -> messagingTemplate().convertAndSend(reactorStreamResult(), v));

我們將在未來的版本中考慮為 MessageChannel 實作提供一些 org.reactivestreams.Subscriber 選項。

其他變更

為了使 DSL 更流暢、方便和靈活,我們進行了其他重要的重構和棄用,例如

  • FileSplitter 組件的 Files.splitter() 工廠方法;
  • 用於新 MessageSessionCallback(S)Ftp.outboundGateway() (Spring Integration 4.2 功能);
  • 重構和改進了 .aggregate().resequence() EIP 方法等。

##SpringOne 2GX 2015 即將到來!在 下週在華盛頓特區舉行的 SpringOne2GX 上預訂您的席位。這絕對是第一手掌握所有最新資訊並提供直接回饋的最佳機會。

來參加我的 演講,從 Spring Integration Java DSL 的第一手資料中獲得更多資訊,並幫助我讓這個 Framework 變得更好!

專案頁面 | JIRA | 問題 | [貢獻] (https://github.com/spring-projects/spring-integration/blob/master/CONTRIBUTING.md) | StackOverflow (spring-integration 標籤)

訂閱 Spring 電子報

隨時掌握 Spring 電子報的最新消息

訂閱

領先一步

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

了解更多

獲得支援

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

了解更多

即將舉行的活動

查看 Spring 社群中所有即將舉行的活動。

查看全部