File Connector Guide > Process Definitions with File Connector > Example Process with File Connector
  

Example Process with File Connector

The following example illustrates one way you can use the File Connector to read delimited content, convert it to a list of process objects, call a service to make a list of phone numbers and publish the record count to the client.
First, configure the Connection:
  1. 1Define the basic connection properties and select File as the Connection Type. Be sure to select an agent where the connection will run.
  2. 2On the Event Sources tab, add a Delimited Content Writer event.
  3. 3Enter a name and be sure to enable the event source if you want the connection to be available as soon as you publish it. If you do not want the connection to be immediately available, you can disable it.
  4. 4Specify the directory that should be monitored. This field is required. You can specify other optional properties to exclude or include specific files or the subdirectories.
  5. 5Enter other file parsing options as needed.
  6. 6Select No for Use Built-In Process Objects and, for Custom Object, enter a comma-delimited list of header names that are exactly the same as the names of the headers in the delimited file header you are reading. For example:
  7. Name,Street,City,State,PostalCode,Country,Phone
  8. 7Select any optional File Read Lock Settings you want to use. The Other Attributes field allows you to specify other parameters supported by the Apache Camel File Listener but not exposed in the File Connector.
  9. 8Save, test, and publish the process.
Second, create the Process:
  1. 1Create a process and be sure it runs on the same Secure Agent defined in the connection.
  2. 2On the Start tab, select the connection, DelimitedContent, to automatically make the input field available that will hold the file content when the connection detects a new file in the monitored directory.
  3. 3Create two temporary variables in the process properties so you can iterate through the delimited content in the file:
    1. aOne to hold the full set of records. For example, TempIterator.
    2. bOne to hold each object as you iterate through the file. For example, TempCurrent.
  4. 4Create an Assignment step to assign the file records (process objects list) to the TempIterator field.
  5. 5Create an Assignment step to populate the current record from the list into a temporary variable, TempCurrent. Specify Formula as the source of TempCurrent, and use the following to get the first record:
  6. list:head($temp.TempIterator)
  7. 6Add a Decision step to validate that the record is set.
  8. 7In the Is set branch, perform the functions you need to process the data. This example makes a service call to RequestBin, passes in each record read from the file, and the service generates a list of phone numbers.
  9. 8Add an Assignment step to remove the processed record from the list of process objects. Specify Formula as the source of TempIterator, and use the following:
  10. list:remove($temp.TempIterator,1)
  11. 9Add a Jump step to loop back to the Assignment step that populates TempCurrent and get the next record from the process object.
  12. 10In the Unset branch, this example calls a service to publish the record count to the client, reading the FileInfo from the process object.
  13. 11End the process.