Message Content

The ability to interpret and process message content is a key reason for using FME workspaces as a Subscriber. They can receive the message and then transform it in whatever way is required, incorporating spatial data and spatial conditions as necessary.


Passing Messages

A topic passes on messages to a Subscription. When it does that for this protocol, the topic message is written into a temporary JSON file, and the name of that file passed to a workspace via a published parameter.

There are two ways to set up a workspace to retrieve the filename information.

The first way to obtain the message file location is to send it to a user parameter of your own choice, using a checkbox when the workspace Subscription is created:

The second method uses an FME Server parameter called FME_TOPIC_MESSAGE. This is one of the fixed FME Server parameters exposed inside FME Workbench:

Remember, this is only passing the name of the file containing the message - it does not include the message itself. For that, you have to read the contents of that JSON file.

For instance, you could add a JSON (or Text File) Reader to your workspace and choose its source dataset parameter as the one to receive the name of the JSON file. That way the data is read directly into the workspace.

Alternatively, you could use a transformer such as the AttributeFileReader to read the file contents.


Interpreting the Message

Having read the message into Workbench, it's then necessary to deal with it.

As noted, a Workspace Subscription writes message content to a temporary file and passes the name of that file to the workspace through a published parameter.

An incoming message can be scanned and processed with a number of different transformers. If the messages are in JSON format there are transformers such as the JSONExtractor and JSONFlattener. Similarly there are XMLFlattener and XMLFragmenter transformers for XML content.

These transformers will convert the message from a JSON (or XML) string and into attributes that FME Workbench is able to process.

Here - for example - an author has added AttributeFileReader and JSONFlattener transformers to their workspace. The AttributeFileReader reads the JSON content (using FME_TOPIC_MESSAGE to identify the file) and the JSONFlattener transformer processes the JSON to extract the message as an attribute called subscriber_content:

If the incoming message was an email then the JSON content may look like this:

{
"fns_type": "email_publisher",
"email_publisher_to": "[email protected]",
"email_publisher_subject": "MIME message from sender",
"email_publisher_content{0}": "Testing Email",
"email_publisher_content_type{0}": "text/plain",
"email_publisher_from": "[email protected]",
"email_publisher_received": "Thu May 18 11:15:46 PDT 2018",
"email_publisher_sent": "Thu May 18 11:15:46 PDT 2018",
}

Notice how it includes the email from and to fields, plus the content itself.

When converted into FME attributes using the JSONFlattener transformer the result – as shown in the FME Data Inspector – will look something like this:

Now the content is available to the workspace as a set of attributes and can be processed as required.


Using the Message

What you do with the message depends on your required setup. If the topic is merely a trigger, and the message is unimportant, it could be ignored. However, in most cases, the message content is important.

There are almost limitless ways FME could be used to process an incoming message. However, one useful example to consider is when the message contains the name of a dataset that the workspace should read. There are two possible scenarios here.

If an email arrives with a dataset attached, the attachment will be stored on the file system, and part of the JSON content will specify the attachment as a path:

"email_publisher_attachment{0}": "C:\\Temp\\demo246129673106713_canada.dwg"

Similarly, the message might include the name of a dataset that needs to be read (without it being an attachment). In both cases, a reader can't be used because we need to extract the name of the dataset before we can read it, so a FeatureReader transformer - with its ability to read data mid-workspace - becomes the perfect solution.

Another interesting scenario is where the message contains an X/Y coordinate - for example the location of a person. Here, the X/Y coordinate could be converted into a point feature with the VertexCreator transformer, and from there, any number of FME transformers could be used to carry out spatial processing such as a geofence.

results matching ""

    No results matching ""