exchange-pubsub
A helper module to simplify @google-cloud/pubsub
Installation
npm i --save exchange-pubsub
Options
- topicBase = leading name of queue topic (default '')
- log = logger to use (defaults to console)
- defaultSubscribeOptions = (same as optional per-subscription options)
- raw - provide full message to listener. Default = false (just the data)
- autoAck - automatically acknowledge messages on return from listener. Default = true
- ignoreKeyFilename = don't set default pubSub keyFilename option
- pubSub = see @google-cloud/pubsub
- projectId will attempt to use process.env.GCLOUD_PROJECT if not set
- keyFilename will set to 'lib/gcloud-auth.json' if not set and ignoreKeyFilename is not set
Usage
const pubSub = require('exchange-pubsub');
pubSub.setOptions({
topicBase: 'myTopicBase.',
log: console,
defaultSubscribeOptions: {
raw: false,
autoAck: true,
},
});
pubSub.subscribe('myTopic', (msgData => {
console.log(msgData);
}));
pubSub.publish('myTopic', 'my message')
.then(() => { })
.catch(e => { });
Source: [demo.js](demo.js)