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. 1. Define the basic connection properties and select File as the Connection Type. Be sure to select an agent where the connection will run.
  2. 2. On the Event Sources tab, add a Delimited Content Writer event.
  3. 3. Enter 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. 4. Specify 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. 5. Enter other file parsing options as needed.
  6. 6. Select 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. 7. Select 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. 8. Save, test, and publish the process.
Second, create the Process:
  1. 1. Create a process and be sure it runs on the same Secure Agent defined in the connection.
  2. 2. On 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. 3. Create two temporary variables in the process properties so you can iterate through the delimited content in the file:
    1. a. One to hold the full set of records. For example, TempIterator.
    2. b. One to hold each object as you iterate through the file. For example, TempCurrent.
  4. 4. Create an Assignment step to assign the file records (process objects list) to the TempIterator field.
  5. 5. Create 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. 6. Add a Decision step to validate that the record is set.
  8. 7. In 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. 8. Add 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. 9. Add a Jump step to loop back to the Assignment step that populates TempCurrent and get the next record from the process object.
  12. 10. In the Unset branch, this example calls a service to publish the record count to the client, reading the FileInfo from the process object.
  13. 11. End the process.