Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

How to create empty files per flow file session in Nifi

avatar
Explorer

Hello,

My use case is to create a set of empty files with .sem at the end of each new file, downloaded in every batch run.

5 REPLIES 5

avatar
Master Guru

You can use GenerateFlowFile to create 0-Byte flow files. Recent versions of NiFi also let you supply dynamic properties to GenerateFlowFile which means you can add a "filename" attribute set to "${filename}.sem", the filename part will be a timestamp/number. If your version of NiFi doesn't support dynamic properties in GenerateFlowFile, you can use UpdateAttribute afterward to do the same.

Note that GenerateFlowFile runs continuously on the schedule you pick, so there isn't a concept of being "done" or creating a "batch". Instead you could manually (or via the REST API) stop the processor when you have the requisite number of flow files created.

To write the files somewhere, use the PutFile processor.

avatar
Explorer

Matt,

Thanks a lot for such a speedy response.

I just tried, i see all the options, but it doesnt let me put a connector between PutSFTP and GenerateFlowFile.

On the canvas, i have GetSFTP connected to PutSFTP and then GenerateFlowFile, I want to trigger GenerateFlowFile once PutSFTP copies over the files.

Am i doing anything wrong?

avatar
Super Mentor

@vikash kumar

You current flow is as follows?

getSFTP ---->(success)----> putSFTP ---->(success)----> ??? After you put copies of your FlowFiles content to your target SFTP server using putSFTP, do you have any need for the content any longer?

If not you could simply use the ReplaceText processor configured as follows:

13344-screen-shot-2017-03-07-at-124330-pm.png

"Always replace" will replace the entire content with the configured "replacement value". If blank you will end up with a 0 byte file for every FlowFile that was successfully written to your putSFTP server.

Is this what you are looking for?

Thanks, Matt

avatar
Explorer

My requirement is getSFTP ---->(success)----> putSFTP ---->(success)---->write $filename.sem to a seperate directory on the same remote server where i applied putSFTP, these .sem files are trigger for my ETL application.

And yes i need to keep the data i brought in with putSFTP.

thanks.

avatar
Super Mentor

You need to keep the NIFi copy of the data even after writing a copy of it out via the putSFTP?

If you need to retain a local copy of the data, route success twice form your putSFTP processor.

So you should be able to do this with.....

13346-screen-shot-2017-03-07-at-25716-pm.png

The UpdateAttribute processor can be used to update the filename by adding the following new property to its configuration:

13347-screen-shot-2017-03-07-at-25756-pm.png

The Local copy of your Files remain unchanged down the success relationship to the left. The copy sent down the path to the right will have its content cleared, filename changed, and then sent via another PutSFTP.

Thanks,

Matt