Spring Batch : How to use spring batch to read fil

2019-01-27 06:58发布

问题:

My current project is based on Spring Batch and Spring integration.

My goal is using Spring Batch to execute job flow steps:

  1. read file from SFTP server(step1).
  2. decrypt the file(step2).
  3. save the file into database(step3).

I want to divide this into steps queue(read from sftp, decrypt, write to db). And I also need to save the file, transfer start time, transfer end time, file size into DB.

Some days ago, I used Spring integration to poll file from sftp server and then send it to Spring batch to do the extra job. Also I can not get the transfer start time.

But now my project is main based on Spring batch, not Spring Integration.

Can you give me some suggestions ?

Or, can you show me how to use Spring Batch to drive Spring Integration for reading SFTP files.

And how can I get the transfer start time ?

Thanks. :)

回答1:

Add a tasklet as the first step; have the tasklet invoke a Spring Integration flow, probably using an sftp outbound gateway to GET the file.

There's an example of how to use the gateway in the sftp sample.

The 'transfer start time' would be the time you invoke the gateway.