node.js - Google Cloud Pub/Sub API - Push E-mail -
i'm using node.js create app gets push gmail each time email received, checks against third party database in crm , creates new field in crm if e-mail contained there. i'm having trouble using google's new cloud pub/sub, seems way push gmail without constant polling.
i've gone through instructions here: https://cloud.google.com/pubsub/prereqs don't understand how supposed work app on desktop. seems pub/sub can connect verified domain, can't connect directly toto .js script have on computer. i've saved api key in json file , use following:
var gcloud = require('gcloud'); var pubsub; // google compute engine: pubsub = gcloud.pubsub({ projectid: 'my-project', }); // or elsewhere: pubsub = gcloud.pubsub({ projectid: 'my-project', keyfilename: '/path/to/keyfile.json' }); // create new topic. pubsub.createtopic('my-new-topic', function(err, topic) {}); // reference existing topic. var topic = pubsub.topic('my-existing-topic'); // publish message topic. topic.publish('new message!', function(err) {}); // subscribe topic. topic.subscribe('new-subscription', function(err, subscription) { // register listeners start pulling messages. function onerror(err) {} function onmessage(message) {} subscription.on('error', onerror); subscription.on('message', onmessage); // remove listeners stop pulling messages. subscription.removelistener('message', onmessage); subscription.removelistener('error', onerror); });
however, errors if isn't connecting server , on api list see errors, no actual successes. i'm doing wrong, idea might be?
thank in advance!
tl;dr
your cannot subscribe push notifications client side.
set https server handle messages. messages sent url endpoint configure, representing server's location. server must reachable via dns name , must present signed ssl certificate. (app engine applications preconfigured ssl certificates.)
just subscribe push notifications on server, , when notification, can figure out concerns. data notifications user concerns, , relevant historyid, so:
// data notifications give you. {"emailaddress": "user@example.com", "historyid": "9876543210"}
then e.g. emit event through socket.io relevant user if online, , have him sync supplied historyid on client side.
Comments
Post a Comment