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 > SubscriptionPackage
@google-cloud/pubsub!Constructors
(constructor)(pubsub, name, options)
constructor(pubsub: PubSub, name: string, options?: SubscriptionOptions);
Constructs a new instance of the Subscription
class
Name | Description |
pubsub |
PubSub
|
name |
string
|
options |
SubscriptionOptions
|
Properties
iam
iam: IAM;
Type | Description |
IAM |
isOpen
get isOpen(): boolean;
Indicates if the Subscription is open and receiving messages.
{boolean}
Type | Description |
boolean |
metadata
metadata?: google.pubsub.v1.ISubscription;
Type | Description |
google.pubsub.v1.ISubscription |
name
name: string;
Type | Description |
string |
projectId
get projectId(): string;
{string}
Type | Description |
string |
pubsub
pubsub: PubSub;
Type | Description |
PubSub |
request
request: typeof PubSub.prototype.request;
Type | Description |
typeof PubSub#request |
topic
topic?: Topic | string;
Type | Description |
Topic | string |
Methods
close()
close(): Promise<void>;
Type | Description |
Promise<void> |
close(callback)
close(callback: SubscriptionCloseCallback): void;
Name | Description |
callback |
SubscriptionCloseCallback
|
Type | Description |
void |
create(options)
create(options?: CreateSubscriptionOptions): Promise<CreateSubscriptionResponse>;
Name | Description |
options |
CreateSubscriptionOptions
|
Type | Description |
Promise<CreateSubscriptionResponse> |
create(callback)
create(callback: CreateSubscriptionCallback): void;
Name | Description |
callback |
CreateSubscriptionCallback
|
Type | Description |
void |
create(options, callback)
create(options: CreateSubscriptionOptions, callback: CreateSubscriptionCallback): void;
Name | Description |
options |
CreateSubscriptionOptions
|
callback |
CreateSubscriptionCallback
|
Type | Description |
void |
createSnapshot(name, gaxOpts)
createSnapshot(name: string, gaxOpts?: CallOptions): Promise<CreateSnapshotResponse>;
Name | Description |
name |
string
|
gaxOpts |
CallOptions
|
Type | Description |
Promise<CreateSnapshotResponse> |
createSnapshot(name, callback)
createSnapshot(name: string, callback: CreateSnapshotCallback): void;
Name | Description |
name |
string
|
callback |
CreateSnapshotCallback
|
Type | Description |
void |
createSnapshot(name, gaxOpts, callback)
createSnapshot(name: string, gaxOpts: CallOptions, callback: CreateSnapshotCallback): void;
Name | Description |
name |
string
|
gaxOpts |
CallOptions
|
callback |
CreateSnapshotCallback
|
Type | Description |
void |
delete(gaxOpts)
delete(gaxOpts?: CallOptions): Promise<EmptyResponse>;
Name | Description |
gaxOpts |
CallOptions
|
Type | Description |
Promise<EmptyResponse> |
delete(callback)
delete(callback: EmptyCallback): void;
Name | Description |
callback |
EmptyCallback
|
Type | Description |
void |
delete(gaxOpts, callback)
delete(gaxOpts: CallOptions, callback: EmptyCallback): void;
Name | Description |
gaxOpts |
CallOptions
|
callback |
EmptyCallback
|
Type | Description |
void |
detached()
detached(): Promise<DetachedResponse>;
Type | Description |
Promise<DetachedResponse> |
detached(callback)
detached(callback: DetachedCallback): void;
Name | Description |
callback |
DetachedCallback
|
Type | Description |
void |
exists()
exists(): Promise<ExistsResponse>;
Type | Description |
Promise<ExistsResponse> |
exists(callback)
exists(callback: ExistsCallback): void;
Name | Description |
callback |
ExistsCallback
|
Type | Description |
void |
formatMetadata_(metadata)
static formatMetadata_(metadata: SubscriptionMetadata): google.pubsub.v1.ISubscription;
Name | Description |
metadata |
SubscriptionMetadata
|
Type | Description |
google.pubsub.v1.ISubscription |
formatName_(projectId, name)
static formatName_(projectId: string, name: string): string;
Name | Description |
projectId |
string
|
name |
string
|
Type | Description |
string |
get(gaxOpts)
get(gaxOpts?: GetSubscriptionOptions): Promise<GetSubscriptionResponse>;
Name | Description |
gaxOpts |
GetSubscriptionOptions
|
Type | Description |
Promise<GetSubscriptionResponse> |
get(callback)
get(callback: GetSubscriptionCallback): void;
Name | Description |
callback |
GetSubscriptionCallback
|
Type | Description |
void |
get(gaxOpts, callback)
get(gaxOpts: GetSubscriptionOptions, callback: GetSubscriptionCallback): void;
Name | Description |
gaxOpts |
GetSubscriptionOptions
|
callback |
GetSubscriptionCallback
|
Type | Description |
void |
getMetadata(gaxOpts)
getMetadata(gaxOpts?: CallOptions): Promise<GetSubscriptionMetadataResponse>;
Name | Description |
gaxOpts |
CallOptions
|
Type | Description |
Promise<GetSubscriptionMetadataResponse> |
getMetadata(callback)
getMetadata(callback: GetSubscriptionMetadataCallback): void;
Name | Description |
callback |
GetSubscriptionMetadataCallback
|
Type | Description |
void |
getMetadata(gaxOpts, callback)
getMetadata(gaxOpts: CallOptions, callback: GetSubscriptionMetadataCallback): void;
Name | Description |
gaxOpts |
CallOptions
|
callback |
GetSubscriptionMetadataCallback
|
Type | Description |
void |
modifyPushConfig(config, gaxOpts)
modifyPushConfig(config: PushConfig, gaxOpts?: CallOptions): Promise<EmptyResponse>;
Name | Description |
config |
PushConfig
|
gaxOpts |
CallOptions
|
Type | Description |
Promise<EmptyResponse> |
modifyPushConfig(config, callback)
modifyPushConfig(config: PushConfig, callback: EmptyCallback): void;
Name | Description |
config |
PushConfig
|
callback |
EmptyCallback
|
Type | Description |
void |
modifyPushConfig(config, gaxOpts, callback)
modifyPushConfig(config: PushConfig, gaxOpts: CallOptions, callback: EmptyCallback): void;
Name | Description |
config |
PushConfig
|
gaxOpts |
CallOptions
|
callback |
EmptyCallback
|
Type | Description |
void |
open()
open(): void;
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.
Type | Description |
void |
seek(snapshot, gaxOpts)
seek(snapshot: string | Date, gaxOpts?: CallOptions): Promise<SeekResponse>;
Name | Description |
snapshot |
string | Date
|
gaxOpts |
CallOptions
|
Type | Description |
Promise<SeekResponse> |
seek(snapshot, callback)
seek(snapshot: string | Date, callback: SeekCallback): void;
Name | Description |
snapshot |
string | Date
|
callback |
SeekCallback
|
Type | Description |
void |
seek(snapshot, gaxOpts, callback)
seek(snapshot: string | Date, gaxOpts: CallOptions, callback: SeekCallback): void;
Name | Description |
snapshot |
string | Date
|
gaxOpts |
CallOptions
|
callback |
SeekCallback
|
Type | Description |
void |
setMetadata(metadata, gaxOpts)
setMetadata(metadata: SubscriptionMetadata, gaxOpts?: CallOptions): Promise<SetSubscriptionMetadataResponse>;
Name | Description |
metadata |
SubscriptionMetadata
|
gaxOpts |
CallOptions
|
Type | Description |
Promise<SetSubscriptionMetadataResponse> |
setMetadata(metadata, callback)
setMetadata(metadata: SubscriptionMetadata, callback: SetSubscriptionMetadataCallback): void;
Name | Description |
metadata |
SubscriptionMetadata
|
callback |
SetSubscriptionMetadataCallback
|
Type | Description |
void |
setMetadata(metadata, gaxOpts, callback)
setMetadata(metadata: SubscriptionMetadata, gaxOpts: CallOptions, callback: SetSubscriptionMetadataCallback): void;
Name | Description |
metadata |
SubscriptionMetadata
|
gaxOpts |
CallOptions
|
callback |
SetSubscriptionMetadataCallback
|
Type | Description |
void |
setOptions(options)
setOptions(options: SubscriberOptions): void;
Sets the Subscription options.
Name | Description |
options |
SubscriberOptions
The options. |
Type | Description |
void |
snapshot(name)
snapshot(name: string): Snapshot;
Create a Snapshot object. See to create a snapshot.
Name | Description |
name |
string
The name of the snapshot. |
Type | Description |
Snapshot | {Snapshot} |