Files
Introduction
In FME Flow (formerly FME Server) you can use the notification service to push data in and out of FME Flow in the form of a message when an event occurs. This can be achieved by defining a topic, setting up the subscription and reviewing the notification. For more detailed information on how the Notification Service works please review the documentation.
Step-by-step Instructions
Part 1: Defining a Topic
A topic gives publishers a target for sending notifications to and gives subscribers a source to receive notifications from. Topics can be defined using the following steps:
1. Open the FME Flow Web User Interface at http://<hostname>:<port>/fmeserver and log in.
2. Click Notifications > Topics > Create.
3. Give the topic a name such as NotificationTutorial, and a description.
4. Click OK to create the topic.
At this point, you can start sending notifications to the new topic, but there is no subscription setup to accept the notification messages.
Part 2: Sending a Notification to FME Flow
Notifications can be sent to FME Flow using the FME Flow REST API V4 with the below request:
http://<hostname>/fmeapiv4/topics/NotificationTutorial/messageAlternatively, we can use the FMEFlowNotifier transformer. In most cases, a publication (defined in the Web User Interface) will send a message to a topic. However, the Test Topic option can be used when developing the solution:
1. Click Notifications > Topics.
2. Select the topic you created previously, NotificationTutorial, and click Test Topic.
3. Enter some text to send in a notification message and click OK.
Part 3: Receiving a Notification
Inspecting a Notification
Common message formats include XML and JSON. Inspecting and understanding the contents of a notification message is key to being able to build a workspace that can process notifications.
Messages can be inspected using the Topic Monitoring ability in the Web User Interface:
1. In a new browser window/tab, open Notifications > Topic Monitoring; this window needs to stay open for Topic Monitoring to continue running.
2. Select the topic you want to monitor, NotificationTutorial, and click the play button to start monitoring the topic. Any messages sent to the topic will be displayed.
4. In a different window/tab, go to Notifications > Topics and use the Test Topic option mentioned previously to send a message.
Processing a Notification
An FME workspace is used to process notification messages. What you do with the message is up to you. You could write it to a database. You could pass it on to another service. You could tweet the message. You could compare it to other data and decide to take an action. You are only limited by your imagination.
Sample Notification Message
To create the workspace you need a sample message that can be utilized in transformers throughout the workspace - this message is often JSON or XML. A quick way to generate the sample message is to use Topic Monitoring, mentioned previously, or you can copy a sample from somewhere else, and then save the sample message into a text file.
Creating The Workspace
In order to process the messages you will need to follow these steps:
1. In FME Workbench, open up the CreateNotification.fmwt workspace and skip to step 5 or create a new workspace that reads the sample notification message using a Text File reader. Ensure that you set the Text File reader parameter 'Read Whole File at Once' to 'Yes'.
2. The source dataset path is published by default; leave it published. This will allow you to map the message from the topic into the workspace.
3. If your notification message is in JSON or XML format, then you can use a JSONFlattener or XMLFlattener transformer to convert the hierarchical model to a relational model (i.e. feature) and expose the attributes that are created.
4. Add in any additional transformers you want and a writer if required.
5. Publish the workspace to FME Flow in a repository called “training” and call the workspace “NotificationWorkspace”. There are two options for setting up Registered Services:
- Option 1: Do not register with any services, click Yes when the No Services Currently Selected dialog appears. Continue on to Configuring the Subscription.
- Option 2: Register with the Notification Service. Click Edit… and for Subscribe to Topic select the NotificationTutorial, then move on to Test the Subscription, the subscription will be listed as username.repository.workspace
Configuring the Subscription
To have the workspace process messages you need to create a workspace subscription:
1. Click Notifications (Classic) > Subscriptions.
2. Click Create to create a new subscription. Give it a name such as NotificationSubscription.
3. Under Protocol, select FME Workspace.
4. Select the topic you defined previously, NotificationTutorial, for the Topics Subscribed To parameter.
5. Under Protocol Settings, set the Repository as training and the Workspace as NotificationTutorial. Ensure that Get Value from Topic Message is enabled.
6. Click Create to create the subscription. The subscription will be listed as NotificationSubscription.
Test the Subscription
1. Use the Test Topic option to send a message
2. Check the Jobs page to confirm that the workspace ran successfully. This will be the same result for both Option 1 or 2 when setting up the Subscription.
Congratulations! You have now successfully created a subscription that will run a workspace when a specific topic is triggered!