Files
Introduction
This article explains how to use the Recorder and Player transformers to cache data from a database to an FME Feature Store (FFS) file on disk. This is useful when database access is slow, intermittent, or unavailable during development — the FFS file can be replayed in a workspace as if the data were being read directly from the database.
This article uses the Safe Software training PostGIS database as an example. The same approach applies to any database format supported by FME Form.
Step-by-Step Instructions
This workflow is split into two parts. In Part 1, we will use the Recorder transformer to write data from a connected database to an FFS file on disk. In Part 2, we will use the Player transformer to read back the FFS file with no database connection.
The workspace template for this tutorial can be downloaded from the Files section.
Part 1: Record Database Data
In Part 1, we will connect to a PostGIS database and use the Recorder transformer to write data to an FFS file on disk.
1. Open FME Workbench and Start a New Workspace
Open FME Workbench and start a new workspace.
2. Add a PostGIS Reader
In the top Toolbar, click the Add Reader button. In the Add Reader dialog, set the following:
- Format: PostGIS
-
Connection: Add Database Connection:
-
Name:
fmedata -
Host:
postgis.train.safe.com -
Port:
5432 -
Database:
fmedata -
Username:
fmedata -
Password:
fmedata
-
Name:
-
Parameters:
-
Connection:
fmedata -
Tables:
public.Parkspublic.Schools- Click the ellipsis button and select the Parks table and Schools table under the Public category
-
Connection:
Click OK three times to add the reader to the canvas.
3. Expose the fme_feature_type Attribute
We will expose the fme_feature_type attribute on both the Parks and Schools feature types.
Double-click the public.Parks reader feature type to open the parameters dialog. Click the Format Attributes tab and enable the checkbox next to fme_feature_type to expose the attribute:
-
Format Attributes:
- fme_feature_type: Enabled
Repeat this process for the public.Schools feature type.
4. Add a Recorder Transformer
Click the Add Transformer button from the Toolbar. In the Add Transformer dialog, search for and add a Recorder transformer to the canvas.
Connect the public.Parks and public.Schools reader feature types to to the Recorder Input port:
Only one Recorder transformer is needed, regardless of how many feature types are being cached.
Double-click the Recorder transformer to open its parameters dialog. Set the following, then click OK:
-
Output Feature Store File: /Output.ffs
- Set an output file location
-
Feature Type Attribute:
fme_feature_type
5. Run the Workspace
Enable Data Caching in the Toolbar, then Run the workspace. The Recorder will write all features from public.Parks and public.Schools to the FFS file specified in the previous step.
If you are running the downloaded template workspace, you may have to add the database connection within the Translation Parameters dialog.
Once the translation is successful, click the green eye icon on the Recorder transformer to open the cached data in Data Preview and confirm the features were captured correctly.
We can see the fme_feature_type field correctly written to the file.
Part 2: Play the Recorded Data
In Part 2, we will add a Player transformer to run the FFS file and view without a database connection.
1. Remove the Database Connection
Open either a new workspace or the workspace from Part 1. We will remove the database connection to demonstrate the Player transformer accessing the saved database tables without a connection.
Open the FME Options dialog and click the Database Connections settings tab. Delete the existing connection to the fmedata database by selecting the connection and clicking the minus Remove Connection button.
2. Add a Player Transformer
From the Toolbar menu, click the Add Transformer button. In the Add Transformer dialog, search for and add a Player transformer to the canvas.
Double-click the Player transformer to open its parameters dialog. Set the following, then click OK:
-
Input Feature Store File: /Output.ffs
- The path to the FFS file created in Part 1
-
Recorded Feature Type Attribute:
fme_feature_type
3. Enable Caching and Run the Workspace
Ensure Feature Caching is enabled. Select the Player transformer and click the Run Only the Selected Objects button. The FFS file will be read and output through the Player PlayedBack output port.
Once the translation is complete, click the green eye icon on the Player transformer to inspect the cached data in Data Preview.
There are the same number of rows in the Player output, the FFS file, and the database, confirming that the FFS file is a complete and accurate cache.
Troubleshooting
If the feature types in the FFS file are named __RECORDED__, the Feature Type Attribute was not set correctly in the Recorder parameters. Return to Part 1, Step 4, confirm that Feature Type Attribute is set to fme_feature_type, and re-run the workspace.
Additional Resources
Recorder [FME Documentation]
Player [FME Documentation]
PostGIS Reader/Writer [FME Documentation]