span8
span4
span8
span4
Every time a feature (row) is changed in a table in PostGIS, Node.js receives information about the feature.In the javascript file, when Node.js receives a feature from PostGIS it uses the request module to make a GET request to FME Server to ask for a token.With the returned token, Node.js is able to make a POST request to FME Server, posting information about the created, deleted or modified feature to a topic.
var pg = require ('pg');var request = require('request');var pgConString = "postgres://username:password@server:port/database";pg.connect(pgConString, function(err, client) { if(err) { console.log(err);} client.on('notification', function(msg) { db_body = JSON.parse(msg.payload);request.get('http://FMEserver/fmetoken/generate?user=username&password=password&update=false' , {json:true}, function (error, response, body) { console.log(response.body);token = response.body;topicURL = 'http://FMEserver/fmerest/v3/notifications/topics/SAMPLE_TOPIC/message?fmetoken=' + token console.log("topic url body is " + topicURL);request.post(topicURL , {body:db_body, json:true}, function (error, response, body) { if(response.statusCode == 201){ } else { console.log(db_body);console.log('Status Code: '+ response.statusCode);} });});});var query = client.query("LISTEN watchers2");//PostGIS channel });
See the Tutorial start page for more information on requirements.
In FME Server, create a Topic that can receive notifications about database table changes.
Modify the postgis2topic.js file to match your database requirements.
In a command prompt window, navigate to the folder where the node executable is.In the command window type: node
If nothing happens, that's good.Any errors in the code will get reported here.
In FME Server, navigate to the Topic Monitoring tab and start monitoring the topic.
Now you will need to edit the data in the watched table.You could to this using FME or a GIS Package.As data gets saved or written into the database you should see topic messages appear in the FME Server Web UI.
You should see topic messages appear as soon as a feature is edited in PostGIS.
You can view a video demonstrationhere.
Streaming features from PostGIS to FME using WebSockets
Streaming features from PostGIS to Amazon SQS - Process in FME
FME Server as a WebHook for littleBits
PostGIS to FME Server in Real Time (Node.js) Tutorial
Publish a littleBits workspace as an FME Server Workspace Subscription
Posting to the littleBits cloudBit
© 2019 Safe Software Inc |Legal