Send feedback Class Subscription (2.17.0) Stay organized with collections Save and categorize content based on your preferences. Version 2.17.0keyboard_arrow_down 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 the message event. 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 the options.flowControl.maxMessages option.
If your subscription is seeing more re-deliveries than preferable, you might try increasing your options.ackDeadline value or decreasing the options.streamingOptions.maxStreams value.
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 each PubSub instance 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 the options.streamingOptions.maxStreams value on each Subscription object.
Inheritance EventEmitter > Subscription Package @google-cloud/pubsub! Constructors (constructor)(pubsub, name, options)
constructor ( pubsub : PubSub , name : string , options ?: SubscriptionOptions ); Constructs a new instance of the Subscription class
Parameters Name Description pubsub PubSub name string options SubscriptionOptions
Properties iam Property Value isOpen Indicates if the Subscription is open and receiving messages.
{boolean}
Property Value
metadata ?: google . pubsub . v1 . ISubscription ; Property Value Type Description google.pubsub.v1.ISubscription
name Property Value projectId Property Value pubsub Property Value request
request : typeof PubSub . prototype . request ; Property Value Type Description typeof PubSub#request
topic Property Value Type Description Topic | string
Methods close() Returns Type Description Promise <void>
close(callback)
close ( callback : SubscriptionCloseCallback ) : void ; Parameter Name Description callback SubscriptionCloseCallback
Returns create(options)
create ( options ?: CreateSubscriptionOptions ) : Promise<CreateSubscriptionResponse> ; Parameter Name Description options CreateSubscriptionOptions
Returns Type Description Promise <CreateSubscriptionResponse >
create(callback)
create ( callback : CreateSubscriptionCallback ) : void ; Parameter Name Description callback CreateSubscriptionCallback
Returns create(options, callback)
create ( options : CreateSubscriptionOptions , callback : CreateSubscriptionCallback ) : void ; Parameters Name Description options CreateSubscriptionOptions callback CreateSubscriptionCallback
Returns createSnapshot(name, gaxOpts)
createSnapshot ( name : string , gaxOpts ?: CallOptions ) : Promise<CreateSnapshotResponse> ; Parameters Name Description name string gaxOpts CallOptions
Returns Type Description Promise <CreateSnapshotResponse >
createSnapshot(name, callback)
createSnapshot ( name : string , callback : CreateSnapshotCallback ) : void ; Parameters Name Description name string callback CreateSnapshotCallback
Returns createSnapshot(name, gaxOpts, callback)
createSnapshot ( name : string , gaxOpts : CallOptions , callback : CreateSnapshotCallback ) : void ; Parameters Name Description name string gaxOpts CallOptions callback CreateSnapshotCallback
Returns delete(gaxOpts)
delete ( gaxOpts ?: CallOptions ) : Promise<EmptyResponse> ; Parameter Name Description gaxOpts CallOptions
Returns Type Description Promise <EmptyResponse >
delete(callback)
delete ( callback : EmptyCallback ) : void ; Parameter Name Description callback EmptyCallback
Returns delete(gaxOpts, callback)
delete ( gaxOpts : CallOptions , callback : EmptyCallback ) : void ; Parameters Name Description gaxOpts CallOptions callback EmptyCallback
Returns detached()
detached () : Promise<DetachedResponse> ; Returns Type Description Promise <DetachedResponse >
detached(callback)
detached ( callback : DetachedCallback ) : void ; Parameter Name Description callback DetachedCallback
Returns exists()
exists () : Promise<ExistsResponse> ; Returns Type Description Promise <ExistsResponse >
exists(callback)
exists ( callback : ExistsCallback ) : void ; Parameter Name Description callback ExistsCallback
Returns
static formatMetadata_ ( metadata : SubscriptionMetadata ) : google . pubsub . v1 . ISubscription ; Parameter Name Description metadata SubscriptionMetadata
Returns Type Description google.pubsub.v1.ISubscription
static formatName_ ( projectId : string , name : string ) : string ; Parameters Name Description projectId string name string
Returns get(gaxOpts)
get ( gaxOpts ?: GetSubscriptionOptions ) : Promise<GetSubscriptionResponse> ; Parameter Name Description gaxOpts GetSubscriptionOptions
Returns Type Description Promise <GetSubscriptionResponse >
get(callback)
get ( callback : GetSubscriptionCallback ) : void ; Parameter Name Description callback GetSubscriptionCallback
Returns get(gaxOpts, callback)
get ( gaxOpts : GetSubscriptionOptions , callback : GetSubscriptionCallback ) : void ; Parameters Name Description gaxOpts GetSubscriptionOptions callback GetSubscriptionCallback
Returns
getMetadata ( gaxOpts ?: CallOptions ) : Promise<GetSubscriptionMetadataResponse> ; Parameter Name Description gaxOpts CallOptions
Returns Type Description Promise <GetSubscriptionMetadataResponse >
getMetadata ( callback : GetSubscriptionMetadataCallback ) : void ; Parameter Name Description callback GetSubscriptionMetadataCallback
Returns
getMetadata ( gaxOpts : CallOptions , callback : GetSubscriptionMetadataCallback ) : void ; Parameters Name Description gaxOpts CallOptions callback GetSubscriptionMetadataCallback
Returns modifyPushConfig(config, gaxOpts)
modifyPushConfig ( config : PushConfig , gaxOpts ?: CallOptions ) : Promise<EmptyResponse> ; Parameters Name Description config PushConfig gaxOpts CallOptions
Returns Type Description Promise <EmptyResponse >
modifyPushConfig(config, callback)
modifyPushConfig ( config : PushConfig , callback : EmptyCallback ) : void ; Parameters Name Description config PushConfig callback EmptyCallback
Returns modifyPushConfig(config, gaxOpts, callback)
modifyPushConfig ( config : PushConfig , gaxOpts : CallOptions , callback : EmptyCallback ) : void ; Parameters Name Description config PushConfig gaxOpts CallOptions callback EmptyCallback
Returns open() 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 new message event listener which will also re-open the Subscription.
Returns seek(snapshot, gaxOpts)
seek ( snapshot : string | Date , gaxOpts ?: CallOptions ) : Promise<SeekResponse> ; Parameters Name Description snapshot string | Date gaxOpts CallOptions
Returns Type Description Promise <SeekResponse >
seek(snapshot, callback)
seek ( snapshot : string | Date , callback : SeekCallback ) : void ; Parameters Name Description snapshot string | Date callback SeekCallback
Returns seek(snapshot, gaxOpts, callback)
seek ( snapshot : string | Date , gaxOpts : CallOptions , callback : SeekCallback ) : void ; Parameters Name Description snapshot string | Date gaxOpts CallOptions callback SeekCallback
Returns
setMetadata ( metadata : SubscriptionMetadata , gaxOpts ?: CallOptions ) : Promise<SetSubscriptionMetadataResponse> ; Parameters Name Description metadata SubscriptionMetadata gaxOpts CallOptions
Returns Type Description Promise <SetSubscriptionMetadataResponse >
setMetadata ( metadata : SubscriptionMetadata , callback : SetSubscriptionMetadataCallback ) : void ; Parameters Name Description metadata SubscriptionMetadata callback SetSubscriptionMetadataCallback
Returns
setMetadata ( metadata : SubscriptionMetadata , gaxOpts : CallOptions , callback : SetSubscriptionMetadataCallback ) : void ; Parameters Name Description metadata SubscriptionMetadata gaxOpts CallOptions callback SetSubscriptionMetadataCallback
Returns setOptions(options)
setOptions ( options : SubscriberOptions ) : void ; Sets the Subscription options.
Parameter Returns snapshot(name)
snapshot ( name : string ) : Snapshot ; Create a Snapshot object. See to create a snapshot.
Parameter Name Description name string The name of the snapshot.
Returns Send feedback
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License , and code samples are licensed under the Apache 2.0 License . For details, see the Google Developers Site Policies . Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-10-30 UTC.
Need to tell us more? [[["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-10-30 UTC."],[],[]]