領先一步
VMware 提供培訓和認證,助您加速進步。
瞭解更多我們很高興地宣佈 Spring Integration Java DSL 1.0 Milestone 3 已釋出。請使用 Milestone Repository(Maven 或 Gradle)、下載 發行包,或訪問專案 主頁 獲取更多資訊。
自上次 Milestone 2 釋出以來,此 Milestone 版本包含了一些新功能和進一步的改進,以及大量的 bug 修復。GA 版本預計在十月底左右釋出。
首先,感謝所有對 Spring Integration 擴充套件感興趣的社群成員,感謝你們提供反饋、分享想法,甚至貢獻程式碼。
以下是主要變更的摘要:
Spring Integration 4.1
當前 Milestone 版本與 Spring Integration 4.1 和 Spring Framework 4.1 相容。
變更包括:
Channel 名稱的延遲解析,這使得 DSL IntegrationFlow 的定義可以僅基於通道名稱,避免了先前需要透過 @DependsOn 來處理一個流到另一個流的依賴關係;
(以及其 DSL)基於 Spring Messaging 模組時;
.io/spring/docs/current/spring-framework-reference/html/expressions.html#expressions-spel-compilation)。這對於在執行時廣泛使用 SpEL 的 Spring Integration 非常有用。您可以透過設定系統屬性 spring.expression.compiler.mode 為 IMMEDIATE 或 MIXED 來啟用 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 會根據隱式的 IntegrationFlowBuilder 將這個“偽” Bean 轉換為真正的 StandardIntegrationFlow。這種定義的唯一限制是,它基於一個名為 lambdaFlow.input 的隱式 DirectChannel。
特定協議介面卡
在此 Milestone 版本中,引入了幾個新的特定協議的 名稱空間工廠:Files、(S)Ftp 和 Mail。以下是一些簡單的使用示例。
@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() 提供了流暢的語法,可以作為內聯物件指定 Properties 和 Map<String, String>。不幸的是,Java 沒有為這些簡單類提供 Builder API,因此我們為您完成了這項工作,並提供了函式式介面,透過 Lambda 來構建 Properties 和 Map。例如,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 改進。