Subscribe, Report and Notify: 3. Subscribe and Unsubscribe

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.

Introduction

Manually updating the subscription database works okay if there are a few, static subscriptions. However, if you expect to have many users subscribing and unsubscribing, then you will need to automate updates to the subscription database. A workspace is the perfect tool for this purpose and we can make it web accessible with FME Server.

 

Methods for Confirmation

If you are providing a service to subscribe devices/email addresses, then you need to ensure that the owner of the device/email address is the one that actually subscribes. The same goes for unsubscribing.

For email subscriptions, there are two common methods for confirming subscription that both involve sending an email to the address provided:

  • the user can then click a link that contains a unique ID known to the server or
  • the user can reply to the email.

For SMS subscriptions, it is common to send a SMS with a code in it, which you then enter into a website. A link with a unique ID would work as well for smartphones.

For APNS/GCM subscriptions, your mobile device will ask you if you want to receive push notifications when the app is installed. The app should then provide an option to register for notifications, which should then submit a request to FME Server for subscription. The request needs to contain the device ID/token of the mobile device, which will be used in combination with the GCM and APNS subscribers to send a notification to the app. Since the device ID/token is only known by the apps on the actual device, confirmation is implicit in the request.

 

Database for Subscriptions

Create a database that connects topic names with email addresses, which we call a subscription. Each subscription has a confirmation token that will be used to confirm unsubscribe requests.

1) Open the 3_create_subscription_database.fmw workspace.

 

createsubscriptionworkspace.png

2) Modify the PostGIS writer’s connection parameters to match your PostGIS database.

postgiswriterparameters1.png

postgiswriterparameters2.png

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

Request Subscription

This step provides a web service for requesting subscription to notifications sent to a specific topic within a specific geographic area.

1) Open the 3_request_subscription.fmw workspace. Note that there are three published parameters that allow input: email, topic, wkt.

requestsubscriptionworkspace.png

2) Modify the PostGIS writer’s connection parameters to match your PostGIS database.

2-postgiswriterparameters1.png

2-postgiswriterparameters2.png

3) Open the FMEServerEmailGenerator transformer and modify the Message parameter, changing the http:// link to match your FME Server’s hostname. This is the link to confirm subscription.

fmeserveremailgenerator1.png

fmeserveremailgenerator2.png

fmeserveremailgenerator3.png

4) Publish the workspace to FME Server:

  • Repository: notification_tutorial
  • On the Register Services page, check on the Job Submitter Service and click the Edit button. Take a look at the settings:
    • 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.
  • Click Publish.

 

Now you have a web service that allows you to request a subscription and receive a confirmation email.

 

Subscribe Confirmation

Now provide a web service that will activate subscription requests using a confirmation token.

1) Open the 3_confirm_subscription.fmw workspace. Note that there is one published parameter: token.

confirmsubscriptionworkspace.png

2) Modify the FeatureReader and DatabaseDeleter transformers and PostGIS writer’s connection parameters to match your PostGIS database.

FeatureReader parameters:

featurereaderparameters1.png

featurereaderparameters2.png

Note: Make sure to select the corresponding subscription_request_database associated with your Table Qualifier - i.e. “public” in the above example.

featurereaderparameters3.png

DatabaseDeleter parameters:

databasedeleterparameters1.png

databasedeleterparameters2.png

Note: Make sure to select the corresponding subscription_request_database associated with your Table Qualifier - i.e. “public” in the above example.

featurereaderparameters3.png

PostGIS writer's parameters:

3-postgiswriterparameters1.png

3-postgiswriterparameters2.png

3) Pulish the workspace to FME Server:

  • Repository: notification_tutorial
  • On the Register Services page, make sure the Data Streaming Service is selected.
  • Click Publish.

 

Unsubscribe Confirmation

This step provides a web service that will deactivate subscription requests using a confirmation token.

1) Open the 3_remove_subscription.fmw workspace. Note that there is one published parameter: token.

 

removesubscriptionworkspace.png

2) Modify the FeatureReader/DatabaseDeleter transformers and PostGIS writer’s connection parameters to match your PostGIS database as you did with the previous workspace.

3) Publish the workspace to FME Server:

  • Repository: notification_tutorial
  • On the Register Services page, make sure the Data Streaming Service is selected.
  • Click Publish.

 

Spatial Filtering and Notifications

You should also adjust your email notifications to provide a link to unsubscribe.

1) Open the 3_process_messages.fmw

 

processmessagesworkspace.png

2) Modify the FeatureReader transformer to match your PostGIS database as you did with the previous workspaces.

3) Open the FMEServerEmailGenerator transformer and edit the Message parameter so that the unsubscribe URL references your FME Server.

fmeserveremailgenerator1.png

fmeserveremailgenerator2.png

fmeserveremailgenerator35.png

4) Publish the workspace to FME Server:

  • Repository: notification_tutorial
  • On the Register Services page, click Edit… for Notification Services.

notificationservicesedit.png

  • Click the ellipsis (...) for Subscribe to Topics and select concert_communications, nature_news, and transit_tips

notificationservicesedit2.png

  • Click OK.
  • Click Publish.

 

Subscribe, Report and Unsubscribe

Subscribe

The web service that allows users to subscribe can be integrated into a user interface with a web map to create a very user-friendly experience. In this case we’ll keep it simple and use the web user interface to make the request.

1) Open the Web User Interface and go to the Run Workspace page. Fill out the parameters as follows:

  • Repository: notification _tutorial
  • Workspace: 3_request_subscription.fmw
  • Service: Job Submitter

runworkspaceparameters1.png

2) Fill out the Published Parameters as follows:

  • Email address to subscribe: <your email address>
  • Topic to subscribe to: concert_communications
  • Area to subscribe to (WKT): POLYGON ((127.65 26.09,127.81 26.16,140.39 35.17,140.84 35.74,145.81 43.37,145.34 44.34,141.97 45.49,141.69 45.4,129.3 34.56,128.65 32.7,127.65 26.09))

Note: the above WKT is the geofence of a rough outline of Japan.

runworkspaceparameters2.png

3) Click Run.

4) Translation successful. Your subscription is confirmed and activated.

Report a Message

1) Open the FME Server REST API: Developers > REST API > API > notifications: Notification Manager > POST/notifications/topics/<topic>/message

2) For the body parameter enter

{
"subject": "One last tour...",
"message": "<b><a href=”http://rush.com”>RUSH</a><b> enters the <i>land of the rising sun</i> for <u>one night only</u>!!",
"latitude":"36",
"longitude":"140"
}

3) For the topic parameter enter: concert_communications

apiparameters1.png

4) Click the Try it out! button.

5) You will prompted to login if you haven’t already. (Remember: username and password are the same as your FME Server account). Afterwards click Try it out! again.

6) You should receive an email to the address you specified for the concert_communications topic back when you created the database.

 

Unsubscribe

1) In the email you received there should be a link to unsubscribe. Click that link.

2) Now let’s verify that you were unsubscribed by repeating the steps in the Report a Message section above.

You shouldn’t receive any email as your subscription was removed.

Where to go from here

So now you understand what it takes to create a system for a basic subscription service with spatial business rules.

Here are some other concepts that you might consider introducing into your own subscribe, report and notify system:

  • Add temporal rules so that subscriptions only apply at certain times.
  • Expire subscriptions after a certain time period.
  • Add more spatial rules such as proximity, inclusion vs. exclusion.
  • Introduce a tracking database to facilitate rules such as direction, frequency, and change detection.
  • Store the geofences in a separate database for use by multiple subscriptions.
  • Add rules that apply to specific reporters (email addresses / device ids).


To give you some further ideas, check out the following demos:

Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.