Results 1 to 7 of 7

Thread: Integration batch help

Threaded View

  1. #1
    Join Date
    Oct 2012
    Location
    Ireland
    Posts
    7

    Default Integration batch help

    Hi All,

    I'm writing a simple application that uses both spring-integration and spring-batch. The app polls a directory, moves the found file into a 'processing' directory and then launches the batch job using the file. On completion of the job, the file is moved into the 'processed' directory.

    My integration context looks like this:

    Code:
    	<int-file:inbound-channel-adapter
    		directory="${file.input.directory}"
    		channel="filesIn" filename-pattern="${file.filename.pattern}">
    		<int:poller cron="${file.poller.cron}"
    			max-messages-per-poll="1" />
    	</int-file:inbound-channel-adapter>
    
    	<int:channel id="filesIn" />
    
    	<int-file:outbound-gateway id="moveFileToProcessing"
    		request-channel="filesIn" reply-channel="processing"
    		directory="${file.processing.directory}"
    		delete-source-files="true" />
    
    	<int:channel id="processing">
    		<int:dispatcher load-balancer="none" />
    	</int:channel>
    
    	<int:chain input-channel="processing" order="1">
    		<int:service-activator ref="fileToJobLaunchRequestAdapter"
    			method="adapt" />
    		<int:service-activator ref="jobLaunchingMessageHandler"
    			method="launch" />
    	</int:chain>
    
    	<int-file:outbound-channel-adapter
    		order="2" directory="${file.processed.directory}"
    		channel="processing" delete-source-files="true" />
    fileToJobLaunchRequestAdapter snippet:

    Code:
        @ServiceActivator
        public JobLaunchRequest adapt(File file) throws NoSuchJobException {
    
            JobParameters jobParameters = new JobParametersBuilder().addString("INPUT_FILE_PATH_KEY",
                    file.getAbsolutePath()).toJobParameters();
    
            return new JobLaunchRequest("job", jobParameters);
        }
    jobLaunchingMessageHandler snippet:

    Code:
        @Autowired
        private JobLauncher jobLauncher;
    
        @Autowired
        private JobRegistry jobRegistry;
    
        @ServiceActivator
        public JobExecution launch(JobLaunchRequest request) throws NoSuchJobException,
                JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException,
                JobParametersInvalidException {
    
            Job job = jobRegistry.getJob(request.getJobName());
            JobParameters jobParameters = request.getJobParameters();
    
            return jobLauncher.run(job, jobParameters);
    }
    spring.integration.version : 2.1.3.RELEASE
    spring.batch.version : 2.1.9.RELEASE

    All seems to work ok in the nominal case. However, if a runtime exception occurs in the batch job i'm unable to handle it with the current configuration. Can someone suggest how i might do this?

    Any help appreciated.
    Last edited by maddenj.ie; Oct 30th, 2012 at 12:34 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •