【问题标题】:Spring Integration - scatter-gather - dynamic value in releaseExpressionSpring Integration - scatter-gather - releaseExpression中的动态值
【发布时间】:2021-06-03 23:16:55
【问题描述】:

我在 Spring Integration 流程中使用 scatter-gatter 来并行调用 3 个服务:

                    .scatterGather(rlr -> rlr.applySequence(true)
                                             .recipientFlow(f1 -> f1
                                                    .channel(c -> c.executor(executorMLCalls))
                                                    .route(ifService1NeedsToBeCalled(), routeToService1OrBypassCall()))
                                             .recipientFlow(f2 -> f2
                                                    .channel(c -> c.executor(executorMLCalls))
                                                    .enrich(this::service2RequestEnricher)
                                                    .enrich(this::service2Enricher))
                                             .recipientFlow(f3 -> f3
                                                    .channel(c -> c.executor(executorMLCalls))
                                                    .enrich(this::service3RequestEnricher)
                                                    .enrich(this::service3Enricher)),
                                   agg -> agg.correlationStrategy(msg -> msg.getHeaders().get("corrMLCalls"))
                                             .releaseExpression("size() == 3"),
                                   sgs -> sgs.gatherTimeout(gatherTimeout)
                                             .requiresReply(true)
                    )

所以 service2service3 必须始终被调用,但调用 service1 取决于条件。
因此,我不能使用 size() == 3 释放表达式,因为有时它应该是 size() == 2

如何在表达式中使用动态值?可以在release表达式中调用本地方法吗?

谢谢!

问候,
五、

【问题讨论】:

    标签: spring-integration spring-integration-dsl


    【解决方案1】:

    是的,这样的表达式是 BeanFactory-aware,您可以使用 @ 语法来访问应用程序上下文中的任何 bean。

    另一方面,有一个:

    /**
     * @param releaseStrategy the release strategy.
     * @return the handler spec.
     * @see AbstractCorrelatingMessageHandler#setReleaseStrategy(ReleaseStrategy)
     */
    public S releaseStrategy(ReleaseStrategy releaseStrategy) {
    

    这可能会根据您的环境和MessageGroup 作为发布候选者做出任何决定。

    【讨论】:

    • 感谢您的回复! @ 看起来很有希望,但我怎样才能将参数传递给这个方法呢?假设要调用的方法是isValid(Storage storage)Storage 是一个简单的 bean,我在其中存储请求/响应并在 SI 组件之间传递。如何在发布表达式中传递这个?非常感谢!
    • 好吧,如果是 Java DSL,我建议使用 ReleaseStrategy impl。这只是 lambda 声明的问题!您可以从那里访问任何 bean,所以
    • 感谢您的提示!我选择了releaseStrategy,它似乎工作正常。但是我遇到了另一个问题:stackoverflow.com/questions/67836736/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-07
    • 1970-01-01
    • 2019-01-13
    • 2022-01-16
    • 2018-01-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多