Spring Integration Java DSL 1.0 Milestone 3 釋出

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

我們很高興地宣佈 Spring Integration 1.0 Milestone 3 的 Java DSL 已經發布。 請使用 Maven 或 Gradle 的 Milestone 倉庫,下載分發包,或檢視專案主頁以獲取更多資訊。

自上次Milestone 2以來,此 Milestone 包含了一些新特性和進一步的改進,以及一些錯誤修復,GA 版本預計在 10 月底釋出。

首先感謝所有對 Spring Integration Extension 感興趣,提供反饋,分享想法甚至做出貢獻的人。

以下是主要變更的摘要

Spring Integration 4.1

當前 Milestone 提供了與 Spring Integration 4.1 以及 Spring Framework 4.1 的相容性。

這些變更包括

  • Spring Integration 4.1 提供了 通道名稱延遲解析

它允許 DSL IntegrationFlow 的定義基於通道名稱,並避免了需要在流之間使用 @DependsOn 的解決方法;

  • Spring Framework 4.1 中包含了一些 Messaging 效能改進,當 Spring Integration

(以及它的 DSL)基於 Spring Messaging 模組時;

.io/spring/docs/current/spring-framework-reference/html/expressions.html#expressions-spel-compilation)。 它對於 Spring Integration 非常有用,Spring Integration 在執行時廣泛使用 SpEL。 您可以使用值為 IMMEDIATEMIXEDspring.expression.compiler.mode 系統屬性來啟用 SpEL 編譯器。

當然,仍然保持與 Spring Integration 4.0 的相容性。

IntegrationFlow Lambda

IntegrationFlow bean 定義現在也可以表示為 Lambda,以簡化 DSL 的使用

@Bean
public IntegrationFlow lambdaFlow() {
    return f -> f.filter("World"::equals)
                 .transform("Hello "::concat)
                 .handle(System.out::println);
}

實際上,我們只是將 IntegrationFlow 變成了一個只有一個方法 define(IntegrationFlowDefinition<?> flow) 的函式式介面,而 IntegrationFlowBeanPostProcessor 只是將那個“偽造”的 bean 轉換為基於隱式 IntegrationFlowBuilder 的真實 StandardIntegrationFlow。 唯一的限制是這種定義基於帶有 lambdaFlow.input bean 名稱的隱式 DirectChannel

特定協議的介面卡

在這個里程碑中,引入了幾個新的特定協議的 Namespace factoriesFiles(S)FtpMail。 一些簡單的用法示例

@Autowired
private DefaultFtpSessionFactory ftpSessionFactory;

@Bean
public IntegrationFlow ftpInboundFlow() {
     return IntegrationFlows
               .from(Ftp.inboundAdapter(this.ftpSessionFactory)
                        .preserveTimestamp(true)
                        .remoteDirectory("ftpSource")
                        .regexFilter(".*\\.txt$")
                        .localFilenameGeneratorExpression("#this.toUpperCase() + '.a'")
                        .localDirectory(new File("tmp")),
                      e -> e.id("ftpInboundAdapter"))
               .channel(MessageChannels.queue("ftpInboundResultChannel"))
               .get();
}

@Bean
public IntegrationFlow tailFlow() {
	return IntegrationFlows
			.from(Files.tailAdapter(new File(tmpDir, "TailTest"))
					.delay(500)
					.end(false))
			.channel(MessageChannels.queue("tailChannel"))
			.get();
}

@Bean
public IntegrationFlow imapIdleFlow() throws AddressException {
    return IntegrationFlows
            .from(Mail.imapIdleAdapter("imap://user:[email protected]:993/INBOX")
                    .searchTermStrategy((f, l) -> 
                    		new AndTerm(new FromTerm(new InternetAddress("bar@baz")), 
                    					new FlagTerm(new Flags(Flags.Flag.SEEN), false)))
                    .javaMailProperties(p -> p
                            .put("mail.debug", "true")
                            .put("mail.imap.connectionpoolsize", "5"))
                    .shouldReconnectAutomatically(true))
            .enrichHeaders(s -> s.headerExpressions(h -> h
                            .put(MailHeaders.SUBJECT, "payload.subject")
                            .put(MailHeaders.FROM, "payload.from[0].toString()")))
            .channel(MessageChannels.queue("imapIdleChannel"))
            .get();
}

支援新增

正如您在最後一個 IMAP 示例中注意到的那樣,.javaMailProperties().enrichHeaders() 具有流暢的語法來指定 PropertiesMap<String, String> 作為內聯物件。 不幸的是,Java 沒有為這些簡單的類提供 Builder API,因此我們為您完成了這項工作,並提供了函式式介面來從 Lambdas 構建 PropertiesMap。 例如,Mail.headers() 提供了一個 MailHeadersBuilder - MapBuilder 的擴充套件,可以在 .enrichHeaders() 中使用

@Bean
public IntegrationFlow sendMailFlow() {
	return f -> f.enrichHeaders(Mail.headers().subject("foo").from("foo@bar").to("bar@baz"))
				 .handle(Mail.outboundAdapter("smtp.gmail.com")
							.credentials("user", "pw")
							.protocol("smtp")));
}

當然,這相當於 XML 配置中的 <int-mail:header-enricher>

總結

您可以從他們的 原始碼 中獲取關於這些和現有類的更多資訊。

我們期待您的評論和反饋 (StackOverflow (spring-integration 標籤), Spring JIRA, GitHub) 儘快報告您發現的問題,以便我們在幾個月內 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 社群中所有即將舉行的活動。

檢視全部