Solved

How do I read in event as JSON in Automations?


Userlevel 4
Badge +13

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?

icon

Best answer by hollyatsafe 6 May 2019, 22:04

View original

11 replies

Badge +2

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. 

Badge

Hi @hollyatsafe

I have looked at the gettopicinfo.fmw but cant follow. The two examples of Notifications and Automations has public parameters with search paths to file!? In the text you describe that there is o need to have files as input to the workspace.

Im upgrading a server to FME 2019, there are som workflows with topics that I like to upgrade with automation. The case Im working on is topic with json that should trigger a workspace that uses the json and convert it to feautures. I cant figure out how to get this to work with automation.

 

 

Best/

 

Johan
Badge +2

Hi @hollyatsafe

I have looked at the gettopicinfo.fmw but cant follow. The two examples of Notifications and Automations has public parameters with search paths to file!? In the text you describe that there is o need to have files as input to the workspace.

Im upgrading a server to FME 2019, there are som workflows with topics that I like to upgrade with automation. The case Im working on is topic with json that should trigger a workspace that uses the json and convert it to feautures. I cant figure out how to get this to work with automation.

 

 

Best/

 

Johan

Hi @northswejohan,

In Automations you must select 'Event as JSON' for the attribute value:

 

In Notifications the message being sent from the Topic was being stored in a temp location on FME Server, so the published parameter value was the file path to that temp location, which is why we used a JSON reader to extract that information. However in Automations when you select 'Event as JSON' for the published parameter value this returns the actual JSON content so there is no need to read in a file.

I can see how my example may have caused confusion as I set this up using example JSON from the DirectoryWatch trigger which returns a file.path element, so to simplify it for all triggers the Event as JSON will look like:

'{"attributename":"attributevalue","attributename":"attributevalue","attributename":"attributevalue"}'

Therefore if your Trigger is an FME Server Topic the value will look something like:

{ "subscriber_content": "Example Topic Message", "ws_topic": "Test" }

Then depending on how you want to use the data you could use the JSONFragmenter, JSONExtractor or JSONFlattener transformer to bring out the relevant information.

Please let me know if you require more guidance.

-Holly

Badge

Hi @hollyatsafe , I guess I have a similar question: I have an automation defined: triggerer is an email.

 

I tried using the Creator, ParameterFetcher and JSON Fragmenter and want to use the "email.from" as the one to send the Email within the Emailer. Sending out an attachment which stems from another workflow.

However, this doesn't work:

within automation: I get the following error log:

90809032 : user1 : Unable to provide attachment(s) in ""; instead, attachment(s) are available in "C:\\ProgramData\\Safe Software\\FME Server\\resources\\system\\temp\\emailattachments". The error was: Path not found:

 

 

Hope you could help! Marion

 

Badge +2

Hi @hollyatsafe , I guess I have a similar question: I have an automation defined: triggerer is an email.

 

I tried using the Creator, ParameterFetcher and JSON Fragmenter and want to use the "email.from" as the one to send the Email within the Emailer. Sending out an attachment which stems from another workflow.

However, this doesn't work:

within automation: I get the following error log:

90809032 : user1 : Unable to provide attachment(s) in ""; instead, attachment(s) are available in "C:\\ProgramData\\Safe Software\\FME Server\\resources\\system\\temp\\emailattachments". The error was: Path not found:

 

 

Hope you could help! Marion

 

Hi @mabaho,

I think we can simplify your workflow somewhat, with all the Triggers in Automations as well as providing the full event message as JSON, this JSON has already been flattened into its separate elements. Therefore rather than having to write a JSON query yourself, you can just parse the email.from value straight into the Emailer - it looks like you are already doing this with the Email Attachment so the process is the same.

The only trigger this does not apply to is a topic, since this can come from anything so the JSON structure is unknown, which is why the above is still useful in certain scenarios.

 

  1. In your workspace add a Creator > Emailer and created a User Parameter for the ‘To’ parameter:

     

  2. In Automations, from the drop down list, expose the Email folder and select ‘Sent from Address’

     

 

Second for the error you are receiving this looks like it is saying that no Email Attachment exists - was there one in the email sent? If you can share the full log file I may be able to provide more assistance here.

-Holly

Badge

Hi @mabaho,

I think we can simplify your workflow somewhat, with all the Triggers in Automations as well as providing the full event message as JSON, this JSON has already been flattened into its separate elements. Therefore rather than having to write a JSON query yourself, you can just parse the email.from value straight into the Emailer - it looks like you are already doing this with the Email Attachment so the process is the same.

The only trigger this does not apply to is a topic, since this can come from anything so the JSON structure is unknown, which is why the above is still useful in certain scenarios.

 

  1. In your workspace add a Creator > Emailer and created a User Parameter for the ‘To’ parameter:

     

  2. In Automations, from the drop down list, expose the Email folder and select ‘Sent from Address’

     

 

Second for the error you are receiving this looks like it is saying that no Email Attachment exists - was there one in the email sent? If you can share the full log file I may be able to provide more assistance here.

-Holly

Hi @hollyatsafe, Thanks for this help. This workes fine. However, I still don't get the data attached. Seemingly another error. I'll send you the log and wb through report-a-problem... Bye, Marion

Badge +2

Update: Alternatively if you would like to continue using a JSON Reader, you can set the source file path to $(FME_TOPIC_MESSAGE). This method may be preferred if the trigger contains a large amount of data that you wish to process in your workspace, as opposed to a single key and value pair - as the Reader flattens the JSON you will not need to expose all of the attributes individually.

When an FME Server Topic is triggered, the string of JSON is stored as a file in a temporary location on FME Server. The $(FME_TOPIC_MESSAGE) is an FME Server Parameter that references the file path to this JSON.

The $(FME_TOPIC_MESSAGE) parameter will only be populated with a value when it is triggered in FME Server, so to test this workspace in FME Desktop you will need to set this parameter to a dummy value that includes an example of the JSON. Please find attached an example workspace to demonstrate this.

fmetopicmessage.fmw

Badge +11

I currently understand the Notifications(Classic) where Subscription (workspace) watches Topics (message relay) which watches Publication (protocol).

Simplistic view: is the concept of FME Server Automations where Action (subscription/workspace) watches the Trigger (publication/protocol)?

Currently, I have Workspace that TestFilters the email json subject line and based on the values/structure pushes to a specific workflow.

In FME Server Automation, Actions "Filter Messages", Key "Email Subject", Contains "is limited what I could test for"

 

This method does work, Subscription (protocol) to Topic (relay) to Automation Trigger. With Workspace JSONFeature Dataset Source JSON $(FME_TOPIC_MESSAGE)

Badge +3

This all seems a little convoluted. Correct me if I'm wrong but I assumed fme was slowly phasing out notifications/topics in favor of simplifying things with automations.. but looking at the above we still need topics to achieve certain workflows.. I think many people were using the entire email as input to their JSON reader in the triggered WS(not just the sent to, or subject), so having some clear guidance around how to achieve this without TOPICs might be beneficial as I guess the end goal here is to move everything to automations.

I am having the same issue as other customers where the old notifications iss simple to get value from topic message and it processed the email and workspace. Does any document exist on how to use automations to achieve the same reading of the JSON file? I get the error file does not exist, what can be done for a workaround? Thanks

Badge +2

I am having the same issue as other customers where the old notifications iss simple to get value from topic message and it processed the email and workspace. Does any document exist on how to use automations to achieve the same reading of the JSON file? I get the error file does not exist, what can be done for a workaround? Thanks

Hi @timothy.woods​ !

Are you trying to set an automation up with the Topic (notified) trigger and pass the JSON to the workspace as an event value? Or are you wanting to continue using the JSON Reader? The error file does not exist stems from trying to read a path to the temporary JSON file created from topic messaged. However, in automations we can directly pass the actual JSON content to the workspace as an event value rather than reading the JSON file from a temporary location eliminating the need for the JSON Reader. Have you tried the recommendations from @hollyatsafe in the above comments?

Reply