Subscribe, Report and Notify: 1. Database-Backed Subscriptions

Liz Sanderson
Liz Sanderson
  • Updated

FME Version

  • FME 2017.x

Files

As of FME Server 2019+, this functionality can be completed using FME Server Automations. For more information, please see Tutorial: Getting Started with Automations. Note that this tutorial series will no longer be updated, if you encounter an error, please contact Safe Support.

 

Requirements

FME Desktop 2017
FME Server 2017
Completed Subscribe, Report and Notify: 0. Basics of Notifications
PostgreSQL with PostGIS extension installed with a database named gisdb

 

Configure/Setup

http_download_1444329610780_6032.png
Database with Subscriptions

Create a database that connects topic names with email addresses, which we call a subscription.

1) Open the 1_create_subscription_database.fmw workspace.

startingworkspace.png

2) Modify the PostgreSQL writer’s connection parameters to match your PostgreSQL database.
Note: the PostgreSQL host and port should be accessible from the machine you create workspaces on and the machine that has FME Server installed on it.

databasetransformer.png

transformerparameters.png

3) Open all three AttributeCreator transformers and change the email addresses to your own email address. For testing purposes, use the +keyword notations to make the email addresses look unique in your email client (eg: fmeserver+transit@gmail.com).

attributetransformerparameters.png

4) Run the workspace to create a table called subscription_database.


At this point you can manually edit the database if you wish to add or edit the subscribers.

Filtering and Notifications

 

Here we configure a workspace and publish it to FME Server. The workspace will be called when a message is sent to the topic.

1) Open the 1_process_messages.fmw workspace.

processmessagesworkspace.png

2) Open the Joiner transformer and modify the PostgreSQL reader’s connection parameters to match your PostgreSQL database.

joinertransformer.png

joinerparameters1.png

joinerparameters2.png

3) Note the FMEServerEmailGenerator transformer, which will create the specific JSON required by the Email subscription.

emailgeneratortransformer.png

4) Publish the workspace to FME Server:

  • Create a repository called notification_tutorial.
  • On the Register Services page, check on the Notification Service and click the Edit button.
    • Click the ellipsis (...) for the Subscribe to Topics parameter and select concert_communications, nature_news, and transit_tips.
    • Click OK .
  • If we take a look at the settings we can see that:
    • The workspace will be subscribed to three topics: concert_communications, nature_news, and transit_tips.
    • The incoming notification message will be read in by the Text File reader.
    • The workspace will publish a message to a topic when it completes successfully: email_out.
    • The feature written to the Text File writer will be sent to the email_out topic.
  • editpublishparameters.png

  • Click OK.
  • Click Publish.

5) Open the FME Server Web User Interface and create an Email subscription that is subscribed to the email_out topic. Go to Notifications > Subscriptions and click New.

6) Set the New Subscription parameters as follows:

  • Name: Email Out Subscribe Tutorial
  • Protocol: Email
  • Topics Subscribed To: email_out

newsubscriptionname.png

7) Set the Protocol Settings parameters as relevant to your email client. For more information on these parameters, check out the Email Subscriber documentation.

newsubscriptionprotocolsettings.png

 

Now you have a configuration that will:

  • Receive messages from the concert_communications, nature_news, and transit_tips topics.
  • Check the database to see which email addresses are subscribed to the topic the message came from.
  • Send an email notification to the subscribed email addresses.

 

Report a Message

Now we will send a test event to the topics.

1) Open the FME Server REST API from the FME Server Web User Interface by clicking: Developers> REST API > API> notifications: Notifications Manager > POST /notifications/topics/<topic>/message

2) For the body parameter enter:

{
“subject”: “important message, stop everything and read”,
“message”: “There was a sighting of a rare <b>warbleddash lizard</b> in South America!!!”
}

3) For the topic parameter enter: nature_news.

apiparameters.png

4) Click the Try it out! button.

5) You will be prompted to login. Login with your FME Server username and password. Click Lookup Existing Token. Click Close. Click Try it out! again.

6) You should receive an email to the address you specified for the nature_news topic back when you created the database. If you didn’t receive an email: try using Topic Monitoring on the Notifications > Topics page of the Web User Interface to monitor the four topics and also double check subscription settings.

7) Try sending another message to the transit_tips topic:

{
“subject”: “this just in…”
“message”: “Use transit to make my commute easier <i>:-)</i>”
}

apiparameters2.png

 

Now you have created a simple system for managing subscriptions to topics using a database!

 

 

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.