繁体   English   中英

Spring 集成聚合器节流器

[英]Spring Integration Aggregator Throttler

我有一条消息SomeMessage看起来像这样:

class SomeMessage{
 id,
 title
}

目前,我根据 id 聚合消息。 消息在 10 秒后被释放。

.aggregate(
            a ->
                a 
                .outputProcessor(messageProcessor())
                .messageStore(messageGroupStore())
                .correlationStrategy(correlationStrategy())
                .expireGroupsUponCompletion(true)
                .sendPartialResultOnExpiry(true)
                .groupTimeout(TimeUnit.SECONDS.toMillis(10)))
        .handle(amqpOutboundEndpoint)

我需要的是一种基于title属性来限制消息的方法。 如果title=="A" ,它仍然应该等待 10 秒进行聚合; 如果title=="B"它应该等待 60 秒进行聚合,并且它不应该立即发送到amqpOutboundEndpoint但它应该有一些限制(例如,每条具有title=="B"的消息之间有 30 秒)。

最好的方法是什么? AmqpOutboundEndpoint上是否有类似节流的东西?

更新

.groupTimeout(messageGroup -> {
                      if(anyMessageInGroupHasTitleB(messageGroup)){
                        return TimeUnit.SECONDS.toMillis(60);
                      }
                      else {
                        return TimeUnit.SECONDS.toMillis(10);
                      }
                    }))
        .route(
            (Function<SomeMessage, Boolean>) ec ->
            ec.getTitle().equals("B"),
        m -> m.subFlowMapping(true, sf ->
            sf.channel(channels -> channels.queue(1))
                .bridge(e -> e.poller(Pollers
                    .fixedDelay(60, TimeUnit.SECONDS)
                    .maxMessagesPerPoll(1)
                ))
        ).subFlowMapping(false, IntegrationFlowDefinition::bridge))
    .handle(amqpOutboundEndpoint)

使用groupTimeoutExpression()而不是固定超时...

payload.title == 'A' ? 10000 : 30000

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM