首页 文章

如何通过cron启动spring批量远程分区作业?

提问于
浏览
0

我正在使用 spring 批次和 spring 批量管理器进行日常批处理工作 . 我通过Spring批处理管理UI启动作业,使用tomcat 7测试了它 .

我的工作有跨越不同服务器的远程分区步骤,我使用rabbitmq作为中间件,使用spring批量集成进行远程分区 .

在测试时,我在所有服务器上部署应用程序,在所有服务器上启动tomcat,以便启动所有侦听器(入站网关并发线程),启动所有bean .

现在我想把它移到 生产环境 中,所以想把它添加到cron中,它应该每天凌晨4点自动启动工作 .

1)有没有办法使用cron启动作业?

2)在这种情况下,我们是否需要在所有服务器上启动tomcat,否则它可以在没有它的情况下运行?

3)如果我在一台服务器(主服务器)上启动作业,将如何在所有服务器上启动bean,消费者等,以便步骤将作为所有服务器上的分区步骤运行?

在spring batch admin示例中,在launch-context.xml中有

<description><![CDATA[
  A convenient aggregating config file for running the jobs in this project
  from the command line instead of from the web application.  E.g.

  $ MAVEN_OPTS="-Dbatch.jdbc.url=jdbc:hsqldb:hsql://localhost:9005/samples -Dbatch.data.source.init=false" \
    mvn exec:java -Dexec.classpathScope=runtime \
    -Dexec.mainClass=org.springframework.batch.core.launch.support.CommandLineJobRunner \
    -Dexec.args="classpath:launch-context.xml job1 fail=false run.id=1"


  ]]>
</description>

<import resource="classpath*:/META-INF/spring/batch/bootstrap/**/*.xml" />
<import resource="classpath*:/META-INF/spring/batch/override/**/*.xml" />

<bean id="jobLauncherTaskExecutor" class="org.springframework.core.task.SyncTaskExecutor"/>

我可以将它用于我的用例吗?

1 回答

  • 1

    该过程需要在所有服务器上运行 .

    一种解决方案是继续使用Tomcat(并让它们一直运行) . 您可以使用 spring-batch-admin 的ReST API启动批处理作业(例如,使用 cron 来自 cron ) .

    Spring XD Project(即将发布)还提供了用于启动批处理作业的ReST API .

相关问题