领先一步
VMware 提供培训和认证,助您加速进步。
了解更多我们很高兴地宣布 Spring Integration 4.0 release candidate (4.0.0.RC1) 现已可用。请使用 Milestone Repository 进行 maven 或 gradle 操作,下载 分发存档,或查看项目 主页 以获取指向更新的文档和 Maven/Gradle 配置详细信息的链接。
此次发布包含一些错误修复、一些新功能以及进一步的改进,GA 版本预计将在四月底发布。
以下是自 上次里程碑 以来的主要更改摘要:
@Poller 和 @InboundChannelAdapter
在发布 M4 Release 中宣布对注解支持进行了大量改进的基础上,为每个消息注解(@ServiceActivator、@Router 等)添加了新的 @Poller 注解。@Poller 注解属性可以为消息注解的 inputChannel 配置 poller 选项。这使得注解端点可以成为 PollingConsumer。此前,注解端点只能使用 SubscribableChannel 并采用事件驱动的方式。
这也使我们能够引入 @InboundChannelAdapter 方法消息注解。现在,例如在 Spring Boot 应用程序中,无需使用 XML 即可对其进行配置。
@EnableAutoConfiguration // enables integration infrastructure
@MessageEndpoint // makes this class as an integration component
@PropertySource("classpath:integration.properties") // property-placeholder configuration
public class Integration {
public static void main(String[] args) throws Exception {
ConfigurableApplicationContext ctx = SpringApplication.run(Integration.class, args);
Thread.sleep(10000);
ctx.close();
}
@InboundChannelAdapter(value = "countChannel",
poller = @Poller(fixedDelay = "${poller.interval}", maxMessagesPerPoll = "1"))
public Integer count() {
return this.counter.incrementAndGet();
}
@ServiceActivator(inputChannel="countChannel")
public void foo(Integer payload) {
System.out.println(payload);
}
}
这等同于以下 XML 配置:
<int:inbound-channel-adapter channel="countChannel" ref="counter" method="incrementAndGet">
<int:poller fixed-delay="${poller.interval}" max-messages-per-poll="1"/>
</int:inbound-channel-adapter>
<int-stream:stdout-channel-adapter id="countChannel"/>
分布式 MetadataStore 和 LockRegistry
MetadataStore 用于存储各种类型的通用元数据(例如,已处理的最后一个 Feed 条目的发布日期),以帮助组件(如 Feed Adapter)维护状态并避免重复。为了应对分布式环境、多实例应用程序,以及在应用程序重新启动后仍能维护持久化的元数据状态,此版本引入了 RedisMetadataStore 和 GemfireMetadataStore。
例如,可以为 <int-file:inbound-channel-adapter> 配置 FileSystemPersistentAcceptOnceFileListFilter,并将其配置为使用这些分布式 MetadataStore 之一。这使得 filter keys 可以在多个应用程序实例之间共享,或者当多个服务器使用网络文件共享时。
对于类似的分布式(跨 JVM)环境,当只有一个实例可以访问对象时(例如,在消息到达时用于 MessageGroup 的 AggregatorHandler),已引入了分布式的 LockRegistry 实现——RedisLockRegistry 和 GemfireLockRegistry。
Aggregator 自动组释放
现在,<aggregator> 和 <resequencer> 端点可以具有 group-timeout 或 group-timeout-expression 选项,允许这些相关端点在组空闲一段时间后采取行动。此前,您需要为此配置外部的 MessagGroupStoreReaper。groupTimeout 属性会在消息到达后的一段时间安排 MessageGroup 被强制完成,前提是该事件不会导致 ReleaseStrategy 释放组。
从这个角度来看,可能更有趣的是 group-timeout-expression。它允许在运行时基于消息到达时组的状态动态确定 groupTimeout 值。例如:
<aggregator input-channel="input" output-channel="output" discard-channel="discard"
send-partial-result-on-expiry="true"
group-timeout-expression="size() ge 2 ? 1000 : -1"
release-strategy="someReleaseStrategy"/>
在这种情况下,如果组中只有一个消息,组将永远不会超时。但是,只要组中至少包含 2 条消息,在空闲 1 秒钟后,Aggregator 将自动发送部分 MessageGroup。
Priority Channel 和 Message Store
在此版本中,您可以使用外部 MessageStore 配置 <priority-queue>。为此,我们引入了新的 PriorityCapableChannelMessageStore 策略,并提供了 JDBC、Redis 和 MongoDB 的实现。现在,这使得优先级通道中的消息持久化成为可能。
Twitter 搜索网关
现有的 Twitter <search-inbound-channel-adapter> 只允许在每次轮询时执行固定查询。为了更具灵活性,已添加 <int-twitter:search-outbound-gateway/> 作为组件,用于基于 search-args-expression 执行任意的请求/响应 Twitter 搜索操作。默认值为 payload,可以是搜索字符串或 org.springframework.social.twitter.api.SearchParameters 的实例。但是,此属性可以在 SpEL 中配置为:
"new SearchParameters(payload).count(5).sinceId(headers.sinceId)"
或
"{payload, 30}"
例如 SpEL 内联列表——在这种情况下是查询字符串和页面大小,或者...
"{payload, headers.pageSize, headers.sinceId, headers.maxId}"
org.springframework.social.twitter.api.SearchOperations#search 的四个参数。有关更多信息,请参阅 Spring Social Twitter 文档。
总结
有关更改的完整列表,请参阅 发行说明、新增功能 和新组件的 Java Docs。
我们期待您尽快提供意见和反馈(Spring 论坛、StackOverflow(spring-integration 标签)、Spring JIRA),并在本月晚些时候正式发布 (GA) 前报告您发现的问题。
SpringOne 2GX 2014 即将到来
请尽快预订您在 SpringOne(德克萨斯州达拉斯)(9 月 8-11 日)的席位。这是了解所有最新动态并提供直接反馈的最佳机会。今年预计将有许多重要的公告。我们预计将会有多个深入的 Spring Integration 会话。