In FME Server Notifications I used a JSON Reader to digest the incoming Topic Message and get at the relevant information to pass downstream in my translation. However when I try and create an Automation using the process the workspace fails with a 'file does not exist' error. How can I use the trigger event as JSON to run a workspace in Automations?
How do I read in event as JSON in Automations?
Best answer by hollyatsafe
In the Notification Service we used a JSON or TEXTLINE Reader to get the value from the Topic message. This was because when a message was received by a topic it was written to a temporary file location in FME Server. This enables a Reader to pick up this message because the source dataset references a file path.
e.g. `--SourceDataset_JSON' `$(FME_SHAREDRESOURCE_SYSTEM)temp/subscriptions/79b0c08e24eb4ddd8d882c708b471104.json'
However in Automations the concept of topics as a messenger is no longer required and you can pass straight from a Trigger to an Action. This means that you are passing through the actual JSON event value as it does not get saved to a file so the Reader cannot digest this information because it expects a file path so will produce an error similar to: .
The file '{file.path":"/data/fmeserverdata/resources/data/Example.txt","file.event":"CREATE","source":"dirwatch","time":"2019-05-06T18:21:22Z","event.id":"f754c6b3-c75c-4e95-a49e-0a1db41decfc}' does not exist
If you look in the Job Configuration you will see unlike in Notifications the Source Published Parameter value is the JSON string itself so you can no longer extract this information with a Reader.
e.g. `--SourceDataset_JSON' `{"file.path":"/data/fmeserverdata/resources/data/DirWatchExample.json","file.event":"CREATE","source":"dirwatch","time":"2019-05-06T18:42:42Z","event.id":"fa3062ae-8291-4b95-ba6a-855c07617644"}'
Instead you can use a User Parameter Type = Text along with a JSONFragmenter transformer. The workspace attached demonstrates how you could set this up to get a file path from one of the ‘Watcher’ triggers. I use a ParameterFetcher to bring the JSON into an attribute and then a JSONFragmenter to get the file.path value only. You can modify the Query in the JSONFragmenter to read in these different elements. I also had to use a Creator transformer to pass through a null feature to kickstart the translation.
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.