Spring Integration 4.0 发布候选版本

发布 | Artem Bilan | 2014 年 4 月 15 日 | ...

我们很高兴地宣布 Spring Integration 4.0 发布候选版本 (4.0.0.RC1) 现已可用。请使用 Milestone 仓库 与 Maven 或 Gradle,下载 分发存档,或查看项目主页,以获取更新的文档以及 Maven/Gradle 配置详细信息。

此版本包含多个错误修复、一些新功能以及进一步的改进,GA 版本将于四月底发布。

以下是自 上次里程碑 以来的一些主要变更摘要

@Poller 和 @InboundChannelAdapter

M4 版本 中宣布的对注解支持的广泛改进的基础上,新的 @Poller 注解已添加到每个消息传递注解 (@ServiceActivator, @Router 等) 中。@Poller 注解属性允许配置消息传递注解的 inputChannelpoller 选项。这允许带注解的端点成为 PollingConsumer。以前,带注解的端点只能使用 SubscribableChannel 并且是事件驱动的。

这也为我们提供了引入 @InboundChannelAdapter 方法消息传递注解的能力。 现在可以在不使用 XML 的情况下进行配置,例如在 Spring Boot 应用程序中

@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)维护状态并避免重复。 对于分布式环境和多实例应用程序,并且为了使持久性元数据状态在应用程序重新启动时得以维护,此版本引入了 RedisMetadataStoreGemfireMetadataStore

例如,可以使用 FileSystemPersistentAcceptOnceFileListFilter 配置 <int-file:inbound-channel-adapter>,该过滤器可以配置为使用这些分布式 MetadataStore 之一。 这允许在多个应用程序实例之间共享 filter keys,或者当多个服务器使用网络文件共享时。

对于类似的分布式 (跨 JVM) 环境,当只有一个实例可以访问对象(例如,AggregatorHandler 用于消息到达时的 MessageGroup)时,引入了分布式 LockRegistry 实现 - RedisLockRegistryGemfireLockRegistry

聚合器自动组释放

<aggregator><resequencer> 端点现在可以具有 group-timeoutgroup-timeout-expression 选项,以允许这些相关端点在组空闲一段时间后采取措施。 以前,您必须为此目的配置外部 MessagGroupStoreReapergroupTimeout 属性计划在 Message 到达后一段时间强制完成 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"/>

在这种情况下,如果组中只有 1 条消息,则该组将永远不会超时,但是只要该组包含至少 2 条消息,Aggregator 将在空闲 1 秒后自动发送部分 MessageGroup

优先级通道和消息存储

在此版本中,您可以使用外部 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 文档

我们期待您的意见和反馈(Spring 论坛StackOverflow (spring-integration 标签)、Spring JIRA),并尽快报告您发现的问题,以便我们在本月底之前发布 GA 版本。

SpringOne 2GX 2014 即将到来

尽快预订您在 德克萨斯州达拉斯举行的 SpringOne(9 月 8 日至 11 日)的席位。 这是第一手了解所有正在发生的事情并提供直接反馈的最佳机会。 预计今年将发布许多重要的新公告。 我们预计将介绍一些深入的 Spring-Integration 会议。

获取 Spring 新闻通讯

通过 Spring 新闻通讯保持联系

订阅

抢占先机

VMware 提供培训和认证,以加速您的进步。

了解更多

获取支持

Tanzu Spring 在一个简单的订阅中提供 OpenJDK™、Spring 和 Apache Tomcat® 的支持和二进制文件。

了解更多

即将举行的活动

查看 Spring 社区中所有即将举行的活动。

查看全部