Spring Integration and Spring Batch to launch batch job -


problem statement: there service copies 2 files filea.xls , fileb.xls 2 different sources in input directory. need read both files , prepare report containing matching records in filea , fileb.

solution attempted:

i trying achieve spring batch job. launching batch job using spring integration.

i have created inbound adaptor receive files input dir both files copied daily, since want start batch job when both files copied using inputpollskipstrategey skip poll in case both files not present in inputdir.

now problem 'inbound adaptor' processing files 1 one. while want transfer both files batch job @ once batch job can process them together. advisable use si aggregator in scenario publish both files @ once spring batch component.

//inbound channel @bean @inboundchanneladapter(value="inboundchannel", poller=@poller("poller") public messagesource<file> filereadingmessagesource{  filereadingmessagesource source = new filereadingmessagesource (); //set "inputdir" source dir source.setdirectory( new file("/tmp/input")); source.setscaneachpoll(true); return source;  }  @bean pollermetadata poller(){  pollermetadata poller=new pollermetadata(); list<advice> advicechain=new arraylist<advice> (); pollskipadvice pollskipadvice =new pollskipadvice(new inputpollskipstrategey()) advicechain.add(pollskipadvice ); poller.setadvicechain(advicechain); return poller; }  private final class inputpollskipstrategey implements pollskipstrategey  {     public boolean skippoll()   {      if (both files ordera.txt , orderb.txt present in input dir)      return false      else         return true;     } }   @bean @serviceactivator(inputchannel="inboundchannel",outputchannel="jobchannel") public joblaunchingmessagehandler launcher(joblauncher joblauncher) {     return new joblaunchingmessagehandler(joblauncher); }  public class filemessagetojobrequest {      public void setfileparametername(string fileparametername) {         this.fileparametername = fileparametername;     }        @transformer(inputchannel="inboundchannel",outputchannel="jobchannel")     public joblaunchrequest torequest(file afile) {         job job= context.getbean("testjob");         jobparametersbuilder jobparametersbuilder = new jobparametersbuilder();          jobparametersbuilder.addstring("filename", afile.getabsolutepath());          jobparametersbuilder.adddate("date", new date());          return new joblaunchrequest(job, jobparametersbuilder.tojobparameters());     } } 


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -