Exercise 4.3 | Building Updates Notification System |
Data | Building footprints (Esri Shapefile) |
Overall Goal | Triggering real-time updates to databases |
Demonstrates | Processing Directory Watch notifications |
Start Workspace | None |
End Workspace | C:\FMEData2018\Workspaces\ServerAuthoring\RealTime-Ex3-Complete.fmw |
Now that you have learned how to run a workspace in response to a notification, it's time to take that basic workspace and adjust it for your overall goal: to provide real-time updates to your corporate database.
The next step towards achieving this is understanding how to extract information from the notifications and configure an FME Workspace to process that incoming data.
Miss Vector says... |
This exercise continues where Exercise 2 left off. You must have completed Exercise 2 to carry out this exercise. |
1) Create Workspace
Start FME Workbench and begin with an empty workspace.
Select Readers > Add Reader from the menubar. When prompted set the parameters as follows:
Reader Format | Text File |
Reader Dataset | C:\FMEData2018\readme.txt |
Reader Parameters | Read Whole File at Once: Yes |
It doesn't matter what text file we use as the source right now; setting the source dataset in this step is only to satisfy the text file reader requirements. At runtime, the source dataset will be replaced by the content of the incoming message.
2) Add JSONFlattener
Now add a JSONFlattener transformer to the workspace, after the Text File Reader. The incoming message is formatted as JSON, and this transformer will expose attributes on the canvas - making them available to work with.
Inspect the transformer parameters and - under the JSON Document parameter - select the attribute text_line_data as the source of the JSON content.
Add a Logger transformer to each output port on the JSONFlattener.
Dr. Workbench says... |
Instead of using Text Reader > JSONFlattener we could have used the JSON Reader. Why didn't we? The JSON Reader requires a source file with valid schema. At this stage in the exercise, we do not have a file with this structure yet. |
3) Publish to FME Server
Publish the workspace to FME Server, registering it under the Job Submitter service.
4) Update Subscription
Now log in to the FME Server web interface and navigate to the Notifications page.
Click on the Subscriptions tab and select the existing "Process Building Updates" Subscription to edit it.
Change the specified workspace, from the one created in Exercise 2, to the one uploaded in the previous step.
The change of workspace will cause a Source Text File parameter to appear. Here just select the checkbox to the right for Get Value from Topic Message.
Click OK to update the Subscription.
5) Test Topic
Once more (as in exercises 1 and 2) locate the update003.shp source Shapefile datasets in C:\FMEData2018\Data\Engineering\BuildingFootprints and create a compressed (zip) file from the set of Shapefiles (.dbf, .prj, .shp, .shx).
Be sure to give the zip file a different name to any used previously.
Copy the zip file into the Resources folder data\BuildingUpdates. You can do this through the file system (by copying the file to C:\ProgramData\Safe Software\FME Server\resources\data\BuildingUpdates) or by using the FME Server web interface.
6) Check Results
Open the Jobs page in the web interface. The completed jobs list should include the workspace you updated in the subscription. View or download the log file and look for the logged feature. You should find it has an attribute containing JSON and a number of attributes extracted from the JSON.
dirwatch_publisher_action | CREATE |
dirwatch_publisher_content | ENTRY_CREATE C:\ProgramData\Safe Software\FME Server\resources\data\BuildingUpdates\update002.zip |
dirwatch_publisher_path | C:\ProgramData\Safe Software\FME Server\resources\data\BuildingUpdates\update002.zip |
So now we know what the data looks like and can process it accordingly.
Mr. Flibble says... |
You may recognize these attributes from the Topic Monitoring exercise - indeed you can view the same information there without going through this process of adding Logger transformers! |
7) Edit JSONFlattener Transformer
Back in FME Workbench inspect the JSONFlattener transformer parameters once more. Under Attribute to Expose add the attribute dirwatch_publisher_path by clicking the browse button and then manually typing it in:
8) Add FeatureReader Transformer
Now remove the Logger transformers and add a FeatureReader transformer to the output of the JSONFlattener:
This is a transformer that will let us read the contents of the dataset into the workflow mid-translation. Inspect the transformer's parameters and set the following values:
Reader Format | Esri Shapefile |
Reader Dataset | Select Attribute Value > dirwatch_publisher_path |
Output Port | Single Output Port |
Select to have a Single Output Port:
9) Add Writer
Having read the data from a Shapefile, we can now add it to the corporate database.
Select Writers > Add Writer from the menubar. When prompted set the parameters as follows:
Writer Format | SpatiaLite |
Writer Dataset | C:\FMEData2018\Data\Engineering\BuildingFootprints\building_footprints.sl3 |
Writer Parameters | Overwrite Existing Database: No |
Add Feature Types | Table Definition: Manual |
In the new feature type that is created, change the Table Name parameter to building_footprints:
Ensure that the Table Handling is set to "Create if Needed". Click OK to close the dialog and then connect the new feature type to the FeatureReader transformer's <Generic> output port.
10) Inspect Data
After adding the writer, click on the building_footprints feature type to bring up the popup menu. Then click the Inspect button to open the dataset in the FME Data Inspector. There is already data in the building_footprints.sl3 dataset, but we should take note of what the data looks like so we will know where it has changed once we update the dataset with the new data. The area within the red box will be where the new data will be added:
10) Republish Workspace
Back in FME Workbench, publish the workspace back to FME Server. If you have the same FME Workbench session open from the start of this exercise, you can use the Republish option on the toolbar or under the File menu.
11) Add Dataset to FME Server
Since the purpose of this notification system is to update our database – let's make sure that it is accessible in FME Server. To do this, we will upload the building_footprints.sl3 SpatiaLite database to FME Server's shared resources.
Use the FME Server web interface to create a new folder Output in Resources > Data and upload the file located at C:\FMEData2018\Data\Engineering\BuildingFootprints\building_footprints.sl3
12) Edit Subscription
Navigate to the Notifications page and open the Process Building Updates Subscription for editing. The parameters should now include one for the output database. Use the browse button to locate the database uploaded in the previous step:
Click OK to save the changes.
13) Test Solution
Now test the solution by putting update001.zip, update002.zip or update003.zip into the BuildingUpdates folder. If these files already exist, delete them first, and then re-add them. You will find that each dataset put into the folder is added to the SpatiaLite database.
Check the Completed Jobs page to confirm that the workspace was run. Then in the FME Data Inspector, add a new dataset, and browse to the C:\ProgramData\Safe Software\FMEServer\resources\data\Output\ folder and add the building_footprints.sl3 dataset. Depending on which update file you added, you should see one of the three buildings added to the dataset:
CONGRATULATIONS |
By completing this exercise you have learned how to:
|