A Subscription object will give you access to your Cloud Pub/Sub subscription.
Subscriptions are sometimes retrieved when using various methods:
Subscription objects may be created directly with:
All Subscription objects are instances of an [EventEmitter](http://nodejs.org/api/events.html). The subscription will pull for messages automatically as long as there is at least one listener assigned for themessageevent. Available events:
Upon receipt of a message: on(event: 'message', listener: (message:Message) => void): this;
Upon receipt of an error: on(event: 'error', listener: (error: Error) => void): this;
Upon the closing of the subscriber: on(event: 'close', listener: Function): this;
By default Subscription objects allow you to process 100 messages at the same time. You can fine tune this value by adjusting theoptions.flowControl.maxMessagesoption.
If your subscription is seeing more re-deliveries than preferable, you might try increasing youroptions.ackDeadlinevalue or decreasing theoptions.streamingOptions.maxStreamsvalue.
Subscription objects handle ack management, by automatically extending the ack deadline while the message is being processed, to then issue the ack or nack of such message when the processing is done. **Note:** message redelivery is still possible.
By default eachPubSubinstance can handle 100 open streams, with default options this translates to less than 20 Subscriptions per PubSub instance. If you wish to create more Subscriptions than that, you can either create multiple PubSub instances or lower theoptions.streamingOptions.maxStreamsvalue on each Subscription object.
Opens the Subscription to receive messages. In general this method shouldn't need to be called, unless you wish to receive messages after calling . Alternatively one could just assign a newmessageevent listener which will also re-open the Subscription.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,[]]