【问题标题】:How to open/close Spring Integration channel based on environmental variable?如何根据环境变量打开/关闭 Spring Integration 通道?
【发布时间】:2015-12-30 23:57:53
【问题描述】:

我有一个通道用作链中的输入通道。只有当环境变量 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>

【问题讨论】:

    标签: java environment-variables spring-integration


    【解决方案1】:

    &lt;chain&gt; 是一个普通的endpoint,可以根据lifecycle 合约启动/停止。

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

    另一个技巧是,将auto-startup="false" 添加到基于该变量的定义中就足够了。

    嗯嗯。我认为即使使用普通的属性占位符也应该有效:

    <int:chain auto-startup="${myChain.autoStartup}">
    

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

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

    更新

    根据您的关心:

    所以,我希望这个链在启动脚本中的 -Dsd=true 时不工作,而在任何其他情况下工作

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

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

    【讨论】:

    • 您能否看一下问题说明:“所以,我希望这个链在启动脚本中的 -Dsd=true 时不工作,并在任何其他情况下工作。”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多