Spring Batch Integration using Java DSL / launching jobs -
i've working spring boot/batch projet containing 2 jobs.
i'm trying add integration poll files remote sftp using java configuration / java dsl, , launch job.
the file polling working i've no idea on how launch job in flow, despite reading these links :
spring batch integration config using java dsl
and
spring batch integration job-launching-gateway
some code snippets:
@bean public sessionfactory sftpsessionfactory() { defaultsftpsessionfactory sftpsessionfactory = new defaultsftpsessionfactory(); sftpsessionfactory.sethost("myip"); sftpsessionfactory.setport(22); sftpsessionfactory.setuser("user"); sftpsessionfactory.setprivatekey(new filesystemresource("path key")); return sftpsessionfactory; } @bean public integrationflow ftpinboundflow() { return integrationflows .from(sftp.inboundadapter(sftpsessionfactory()) .deleteremotefiles(boolean.false) .preservetimestamp(boolean.true) .autocreatelocaldirectory(boolean.true) .remotedirectory("remote dir") .regexfilter(".*\\.txt$") .localdirectory(new file("c:/sftp/")), e -> e.id("sftpinboundadapter").poller(pollers.fixedrate(600000))) .handle("filemessagetojobrequest","torequest") // put next process jobrequest ?
for .handle("filemessagetojobrequest","torequest") use 1 described here http://docs.spring.io/spring-batch/trunk/reference/html/springbatchintegration.html
i appreciate on that, many thanks.
edit after gary comment i've added, doesn't compile -of course- because don't understand how request propagated :
.handle("filemessagetojobrequest","torequest") .handle(joblaunchinggw()) .get(); } @bean public messagehandler joblaunchinggw() { return new joblaunchinggateway(joblauncher()); } @autowired private joblauncher joblauncher; @bean public jobexecution joblauncher(joblaunchrequest req) throws jobexecutionexception { jobexecution execution = joblauncher.run(req.getjob(), req.getjobparameters()); return execution; }
i've found way launch job using @serviceactivator , adding flow i'm not sure it's practice :
.handle("lauchbatchservice", "launch") @component("lauchbatchservice") public class launchbatchservice { private static logger log = loggerfactory.getlogger(launchbatchservice.class); @autowired private joblauncher joblauncher; @serviceactivator public jobexecution launch(joblaunchrequest req) throws jobexecutionexception { jobexecution execution = joblauncher.run(req.getjob(), req.getjobparameters()); return execution; } }
.handle(joblaunchinggw()) // handle result ... @bean public messagehandler joblaunchinggw() { return new joblaunchinggateway(joblauncher()); }
where joblauncher()
joblauncher
bean.
edit
your service activator doing same jlg; uses this code.
your joblauncher @bean
wrong.
@bean
s definitions; don't runtime stuff this
@bean public jobexecution joblauncher(joblaunchrequest req) throws jobexecutionexception { jobexecution execution = joblauncher.run(req.getjob(), req.getjobparameters()); return execution; }
since autowiring joblauncher
, use that.
@autowired private joblauncher joblauncher; @bean public messagehandler joblaunchinggw() { return new joblaunchinggateway(joblauncher); }
Comments
Post a Comment