Writing a file to your local file system

Use a FileOutput node to write a file to a specified directory on your local file system.

Before you begin

This example shows you how one combination of values in the Record definition, Delimiter, and Delimiter type properties result in the creation of a file from multiple messages. The example describes the FileOutput node of a message flow and assumes that the rest of the flow has been developed. It is also assumed that a Windows system is being used. To complete this example task, you must first have added a FileOutput node to a message flow. You must also ensure that the following messages are produced by the flow preceding the FileOutput node:
  • Three input messages, which are sent, in this order, to the In terminal of the FileOutput node:
    • Message 1:
      <Message>test1</Message>
    • Message 2:
      <Message>testtwo</Message>
    • Message 3:
      <Message>testthree</Message>
    These messages can be produced, for example, by the XMLNSC domain with a message set which recognizes XML with the following form:
    <Message>...</Message>
  • A final message, which is sent to the Finish File terminal of the FileOutput node after the first three messages have been sent:
    <thiscanbe>anything</thiscanbe>
Complete the following steps:

Procedure

  1. Set the required node properties on the FileOutput node.
    The following table summarizes the FileOutput node properties that you must set, on which tab they appear, and the value that you must set in order to follow this example:
    Tab Property Value
    Basic Directory C:\FileOutput\TestDir
    File name or pattern test_output1.xml
    Mode for writing to file Stage in transit directory and move to output directory on Finish File
    Action if file exists Time Stamp, Archive and Replace Existing File
    Replace duplicate archive files Selected
    Records and Elements Record definition Record is Delimited Data
    Delimiter Broker System Line End
    Delimiter type Postfix
    FTP FTP Cleared
  2. Deploy the message flow to the integration node. See Deploying integration solutions.
  3. Send the first three messages to the In terminal of the FileOutput node.
  4. Send the final message to the Finish File terminal of the FileOutput node.

Results

The following actions occur when you perform these steps:
  1. The file is processed. In accordance with the values set in the properties of the FileOutput node, the node generates one record per message with a local file system line terminator after each one. The file contains the following data, each line terminated by a carriage return (X'0D') and line feed (X'0A') pair of characters (on a Windows system):
    <Message>test1</Message>
    <Message>testtwo</Message>
    <Message>testthree</Message>
  2. Records are accumulated in file test_output1.xml in the C:\FileOutput\TestDir\mqsitransit directory. When the final message is sent to the Finish File terminal, the file is moved to the output directory, C:\FileOutput\TestDir directory.
  3. If a file of the same name exists in the output directory, the existing file is renamed and moved to the mqsiarchive directory. For example, the following file might be created:
    C:\FileOutput\TestDir\mqsiarchive\20081124_155346_312030_test_output1.xml
    If a file of this name exists in this archive directory, it is overwritten in accordance with the Replace duplicate archive files property selected on the FileOutput node.

What to do next

See Setting the Record definition property for the FileOutput and FTEOutput nodes to see the results of running this task with different values set in the Record definition, Delimiter, and Delimiter type properties of the FileOutput node.
You can use the append mode of the FileOutput node to append to a file.
  • Appending directly:

    An example is when an application uses the content of the file continually and any changes are seen as they occur. It might be that as soon as the records are seen the application loads the records into a database or a product catalog.

  • Staging before appending:

    An example is when an application uses the content of the file during the day, but the application does not want any updates that occur during the day to be seen. IBM® App Connect Enterprise batches the new record up in its transit directory and then, at a given time of the day (possibly outside normal working hours) the integration node appends to the file.

If a remote file exists, you can use the append mode of the FileOutput node to append to or replace an existing file. Data is either added to the end of the remote file or, if the file does not exist, the file is created.