2016-08-10 46 views
0

我有一个Spring启动MVC和批处理应用程序。批处理和MVC都共享DAO和服务层,因此它们位于同一个war文件中。它们被部署到4个云服务器中,并且为UI应用程序配置了负载均衡和vip。所以MVC应用程序很好。仅在一台服务器上运行批处理

问题是作为批处理的一部分,我将FTP文件传输到外部服务器,并且该外部服务器将处理的文件FTP传回。处理后的文件只能返回到4台服务器中的一台。所以我希望批处理只能在1台服务器上运行。如何禁止在其他服务器上执行批处理。

回答

0

由于您的4个实例在4个不同的云服务器上运行,因此解决方案变得更加轻松。批处理的起点可以是文件轮询器。因此,如果文件被放入服务器1上的轮询目录中,则服务器1上的批处理作业将被调用。其他实例不会执行任何操作,因为在该服务器上没有文件被丢弃。

您需要在spring批处理之前集成文件轮询器。事情是这样的 - http://docs.spring.io/spring-batch/reference/html/springBatchIntegration.html

<int:channel id="inboundFileChannel"/> 
<int:channel id="outboundJobRequestChannel"/> 
<int:channel id="jobLaunchReplyChannel"/> 

<int-file:inbound-channel-adapter id="filePoller" 
channel="inboundFileChannel" 
directory="file:/tmp/myfiles/" 
filename-pattern="*.csv"> 
<int:poller fixed-rate="1000"/> 
</int-file:inbound-channel-adapter> 

<int:transformer input-channel="inboundFileChannel" 
output-channel="outboundJobRequestChannel">. <bean class="io.spring.sbi.FileMessageToJobRequest"> 
<property name="job" ref="personJob"/> 
<property name="fileParameterName" value="input.file.name"/> 
</bean> 
</int:transformer> 

<batch-int:job-launching-gateway request-channel="outboundJobRequestChannel" 
reply-channel="jobLaunchReplyChannel"/> 

0

这可能是很多办法,但办法做到的就是保持一个值在属性文件并设置它的值,则为true

现在处理您的批量运行仅在属性文件中值为true之一。

通过这种方式,您可以灵活地更改要处理批处理作业的服务器。

相关问题