Tuesday, April 10, 2012

Polling files on-demand : File Based Triggers

Many a times there is a need to trigger the polling of File/FTP Adapter on the basis of some event e.g. after process A has finished writing the file F1, process B should poll for the file F1 OR just process the files only between 10.00 AM to 11.00 AM. While the above could be accomplished to some extent using Sync Read operation, but it requires the knowledge of the File Name in advance (wild cards can't be used).

Well, the solution is File-Based Triggers. File-based triggers can be used to control the File/FTP adapter activation. File Triggers are nothing but the files with .trg extension. The content of trigger file doesn't matter. When File-based triggers are used, File/FTP adapter checks for the existence of a Trigger file (e.g. ReadFile.trg) before reading the actual file. If the trigger file is found, it reads and processes the actual file else it does nothing. You can configure how frequently the adapter checks for the trigger file and hence can control the processing of the actual files.
To use a File-Based trigger, follow the below steps.
1.) Define a File/FTP adapter with Read Operation.
2.) On the File Polling page, Check the option Use trigger file and provide the Trigger File details as shown below.

3.) Complete the adapter wizard.
4.) Follow the normal steps to create a bpel process to poll the file. Deploy this process.

As soon as the process is deployed, File/FTP adapter looks for the trigger file in the C:/TriggerFileDir location. If it finds the triger file, it will poll and process the file. How frequently it looks for the trigger file depends on the property TriggerFileStrategy (we didn't specify this property anywhere because the property is set already by default to value EndpointActivation).

The various possible values for TriggerFileStrategy are:
OnceOnly: The adapter will looks for the trigger file only once in its lifetime. Once it finds the trigger file, it remembers that across restarts and redeployments. This could be very risky as the adapter would never look for a trigger file again in future.

EveryTime: The adapter looks for the trigger file everytime it goes for polling the file. At every polling interval, it checks if the trigger file is there or not. If the trigger file is present, it picks the actual file else it will do nothing and will check for the existence of trigger file at next polling cycle.

EndpointActivation (Default): The adapter looks for the trigger file every time the composite is activated that means everytime you Restart/Activate/Redeploy your composite.

Add the property in .jca file of your File Adapter as shown below and it's done.

Note: You may want to delete the Trigger file after your file has been successfully processed. For this, there is no Delete operation. But you can use Sync Read operation to read the trigger file and check Delete Files after successful retrieval option.

Happy to hear back if any suggestions or comments!

6 comments:

  1. Hi Neeraj,
    Nice artical but can it is possible to get 3 mint gap on every files reading, means FTP file process file by file and interval time is 3mint gap.

    Regards

    ReplyDelete
    Replies
    1. I think its possible. You can use the use the minimum file age option and set it to 3 min to give a gap of 3 min in file reading. So the next file will be read after the age of the file is 3 min.

      Delete
  2. Hi Neeraj,

    Is it possible to use '*.trg' for giving the trigger filename e.g.



    Regards,
    Vatan

    ReplyDelete
    Replies
    1. Hi Neeraj,
      I have the same requirement, please let me know is it possible ?

      Delete
  3. Is it possible to stop file polling when there is need without using console

    ReplyDelete
  4. Here I came to know the phenomena File-Based Triggers.such a nice post to do beyond poll based triggers.I read this post part of my oracle SOA training thank you.

    ReplyDelete