【问题标题】:Spring inbound integration on cluster mode集群模式下的 Spring 入站集成
【发布时间】:2017-04-01 10:30:48
【问题描述】:

我们正在使用 spring 入站轮询适配器来检查文件并对其进行处理。问题是进程在集群模式下运行多个节点。我们的测试环境使用两个节点的负载平衡,要求是在一个节点上启动这个轮询过程。我们如何在不创建两个战争文件的情况下实现这一点..?我们不应该使用 XML 配置。

【问题讨论】:

    标签: spring spring-integration load-balancing


    【解决方案1】:

    为此,Spring Integration 提供了FileSystemPersistentAcceptOnceFileListFilter,您应该使用相同的共享外部MetadataStore 进行配置:http://docs.spring.io/spring-integration/reference/html/system-management-chapter.html#metadata-store

    编辑

    按照 Gary 的建议,您可以控制入站通道适配器的 autoStartup

    我像这样测试它:

    @BeforeClass
    public static void setup() {
        System.setProperty("integrationAllowed", "false");
    }
    
    ...
    
    @Bean
    public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
        return new PropertySourcesPlaceholderConfigurer();
    }
    
    @Bean
    @InboundChannelAdapter(value = "flow1.input", autoStartup = "${integrationAllowed}", poller = @Poller(fixedRate = "100"))
    public MessageSource<?> integerMessageSource() {
    

    效果很好。

    表达式${integrationAllowed}表示属性占位符语句。

    如果你不能使用一些共享持久性资源来控制集群状态,那么它看起来就不像一个集群......

    【讨论】:

    • 感谢您的指导.. 目前我们没有使用任何元数据存储,我会朝这个方向探索。
    • 您还可以将Leadership Election 与zookeeper 一起使用,这样一次只运行一个实例。您还可以使用系统属性(用于 autoStartup 属性)并且只启动一个;您可以根据需要使用一些外部监视器来停止/启动实例,也许使用 JMX。
    • 我尝试使用系统属性,但由于某种原因它没有按预期工作。创建了一个 ENV 变量 integrationAllowed = true 并在应用程序中像这样使用它 @InboundChannelAdapter(value = "fileInputChannel", autoStartup = "#{systemProperties['integrationAllowed']}" , poller = @Poller(fixedRate = "1000"))
    • 嗯,消息注释不支持 SpEL,但属性占位符非常适合您的要求 autoStartup = "${integrationAllowed}"
    • 尝试过的属性占位符,但由于注释属性只接受常量,我无法使用它..我无法将属性值注入最终静态变量
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-16
    • 2019-03-07
    • 1970-01-01
    • 2017-06-14
    • 1970-01-01
    相关资源
    最近更新 更多