如何按规范订阅不同的通道?

问题描述 投票:0回答:1

我正在寻找一个Spring IntegrationFlows中的切换操作符,我需要根据用户可以决定的属性来订阅一个通道。我需要根据用户可以决定的属性来订阅一个通道。

    @Bean
    public IntegrationFlow flow() {
        return IntegrationFlows
                .from()
                .publishSubscribeChannel(
                        subscription -> {
                            if (true)//user is going to decide this.
                                subscription.subscribe(flow1());
                            else
                                subscription.subscribe(flow2());
                        }
                )
                .get();
    }

这是我的基本实现,但它不工作。有这样的功能吗?

spring-integration spring-integration-dsl
1个回答
1
投票

如果我们谈论的是一个 application.properties,那么在配置上就只有一个条件了。请看一个 @Value 注入到一个bean定义方法中。https:/docs.spring.iospringdocs5.2.6.RELEASEspring-framework-referencecore.html#beans-value-annotations。

所以,像这样的东西,你的流豆。

@Bean
public IntegrationFlow flow(Value("${your.prop}") String propValue) {

比你确实可以做到这一点 if...else 内行 subscription lambda。

另一种方法是使用 @ConditionalOnProperty 并在Spring Boot的基础上将这些 flow1()flow2() 作为条件 bean。

然后你可以注入一个 IntegrationFlow 阁下 flow() Bean--同样的方法参数注入技术,--而且只有一个条件Bean可以为你所用。

两句话:所有你能用Spring依赖注入做的事情,都可以在你声明了 IntegrationFlow 豆子。

© www.soinside.com 2019 - 2024. All rights reserved.