springspring-batchspring-integrationspring-batch-admin

How to launch spring batch remote partitioned job through cron?


I am using spring batch and spring batch admin for our daily batch processing work. I have tested it using tomcat 7 by launching jobs through spring batch admin UI.

My job has remote partitioned steps which runs across different servers, I am using rabbitmq as a middleware, spring batch integration for remote partitioning.

While testing, I deploy application on all servers, start tomcat on all servers so that all listeners (inbound gateways concurrent threads) starts, all beans are initiated.

Now I want to move it to production so want to add it in cron which should automatically launch job at 4 am daily.

1) Is there any way to launch the job using cron?

2) In that case do we need to start tomcat on all servers or it can run without it?

3) If I launch job on one server (master), how beans, consumers etc will be initiated on all servers so that steps will run as partioned steps on all servers?

In spring batch admin sample, in launch-context.xml there is

<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"/>

Can I use it for my use case?


Solution

  • The process needs to be running on all servers.

    One solution is to continue to use Tomcat (and leave them running all the time). You can launch the batch job using spring-batch-admin's ReST API (e.g. using curl from cron).

    The Spring XD Project (which will be released soon) also provides a ReST API for launching batch jobs.