exchange-pubsub
A helper module to simplify @google-cloud/pubsub
Installation
npm i --save exchange-pubsub
Options
- log = logger to use (defaults to console, set to false to disable)
- 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
- subNameWithTopic - automatically add topic name to subscription name. Default = true
- connectionInterval - automatically resubscribe every xx seconds of inactivity. 0 = off (default).
- 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
- flowControl: maxMessages = 50 by default
Usage
const pubSub = ;// Optional:pubSub; // simple usage:pubSub; pubSub ;
The default usage uses the topic as the subscription name which means it will be processed by a single subscriber (if multiple subscribers use the same name).
You can also specify the name manually, or have a random name generated:
// specify subscription name and options:pubSub; // random subscription namepubSub; // CAUTION: careful with binding...// DON'T DO: pubSub.subscribe('myTopic', true, myClass.function)// Instead, use one of the following:pubSub;pubSub;
Source: demo.js