Spring Integration Java DSL 1.0 Milestone 3 已釋出

版本發布 | Artem Bilan | 2014 年 9 月 7 日 | ...

我們很高興地宣布 Spring Integration 1.0 的 Java DSL Milestone 3 已經發布。請使用 Milestone Repository 與 Maven 或 Gradle,下載 發布檔案,或參閱專案首頁以取得更多資訊。

自上次的 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 提供 Channel names late resolution (通道名稱延遲解析),

允許 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。您可以使用 spring.expression.compiler.mode 系統屬性(值為 IMMEDIATEMIXED)啟用 SpEL Compiler。

當然,與 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

協定特定配接器

在此 Milestone 中,引入了幾個新的協定特定 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 的 Session] (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 社群中所有即將舉行的活動。

查看全部