2016-11-17 47 views
1

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

回答

0

为此Spring集成提供FileSystemPersistentAcceptOnceFileListFilter你应该用相同的共享外部MetadataStore配置:http://docs.spring.io/spring-integration/reference/html/system-management-chapter.html#metadata-store

EDIT

作为加里建议,可以控制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}表示属性占位符句子。

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

+0

谢谢你的方向。目前,我们没有使用任何元数据存储,我会在这个方向探索。 –

+0

你也可以使用zookeeper的[Leadership Election](http://docs.spring.io/spring-integration/reference/html/messaging-endpoints-chapter.html#endpoint-roles),这样只有一个实例在一次。您也可以使用系统属性(用于autoStartup属性)并仅启动一个系统属性;您可以使用某个外部监视器来根据需要停止/启动实例,也许使用JMX。 –

+0

我尝试使用系统属性,出于某种原因它没有按预期工作。创建一个ENV变量integrationAllowed = true并在应用程序中使用它像这样@InboundChannelAdapter(value =“fileInputChannel”,autoStartup =“#{systemProperties ['integrationAllowed']}”,poller = @Poller(fixedRate =“1000”)) –