如何open/close Spring 基于环境变量的集成通道?

How to open/close Spring Integration channel based on environmental variable?

我有一个通道用作链中的输入通道。只有当环境变量 sd 不正确时,我才需要使用它。是否可以在不创建额外的 Java 过滤器的情况下将此条件写入 spring-integration 文件?所以,我希望这个链 不工作 当启动脚本中的 -Dsd=true 并且在任何其他情况下工作。

<int:channel id="sdCreationChannel">
    <int:queue/>
</int:channel>

<int:chain input-channel="sdCreationChannel" output-channel="debugLogger">
    <int:poller fixed-delay="500" />
    <int:filter ref="sdIntegrationExistingRequestSentFilter" method="filter"/>
    <int:transformer ref="sdCreationTransformer" method="transformOrder"/>
    <int:service-activator ref="sdCreationServiceImpl" method="processMessage">
        <int:request-handler-advice-chain>
            <ref bean="retryAdvice"/>
        </int:request-handler-advice-chain>
    </int:service-activator>
</int:chain>

<chain>是正常的endpoint,根据lifecycle合同可以started/stopped。

因此,您可以在运行时随时或在任何条件下通过其 id start/stop 它。

另一个技巧是根据该变量将 auto-startup="false" 添加到其定义中就足够了。

M-m-m。我认为即使使用正常 property-placeholder:

也应该可以工作
<int:chain auto-startup="${myChain.autoStartup}">

您可以从另一方面看一下 profile 功能并像这样配置它:

 <beans profile="myChain.profile">
     <int:chain>
         ....
     </int:chain>
 </beans>

更新

根据您的关注:

So, I would like this chain not to work when -Dsd=true in the startup script and work in any other case

正如我上面所说:你只能从一开始就在auto-startup="false"中标记它,例如使用相同的Environment:

<int:chain auto-startup="#{environment.getProperty('sd', true)}">