Package @google-cloud/pubsub (2.18.3)



[IAM (Identity and Access Management)]( allows you to set permissions on individual resources and offers a wider range of roles: editor, owner, publisher, subscriber, and viewer. This gives you greater flexibility and allows you to set more fine-grained access control.

For example: * Grant access on a per-topic or per-subscription basis, rather than for the whole Cloud project. * Grant access with limited capabilities, such as to only publish messages to a topic, or to only to consume messages from a subscription, but not to delete the topic or subscription.

*The IAM access control features described in this document are Beta, including the API methods to get and set IAM policies, and to test IAM permissions. Cloud Pub/Sub's use of IAM features is not covered by any SLA or deprecation policy, and may be subject to backward-incompatible changes.*


Message objects provide a simple interface for users to get message data and acknowledge the message.

Represents a CustomHttpPattern.

Represents a Http.

Represents a HttpRule.

Represents a ResourceDescriptor.

Represents a ResourceReference.

Represents a DescriptorProto.

Represents an ExtensionRange.

Represents a ReservedRange.

Represents a Duration.

Represents an Empty.

Represents an EnumDescriptorProto.

Represents an EnumReservedRange.

Represents an EnumOptions.

Represents an EnumValueDescriptorProto.

Represents an EnumValueOptions.

Represents an ExtensionRangeOptions.

Represents a FieldDescriptorProto.

Represents a FieldMask.

Represents a FieldOptions.

Represents a FileDescriptorProto.

Represents a FileDescriptorSet.

Represents a FileOptions.

Represents a GeneratedCodeInfo.

Represents an Annotation.

Represents a MessageOptions.

Represents a MethodDescriptorProto.

Represents a MethodOptions.

Represents an OneofDescriptorProto.

Represents an OneofOptions.

Represents a ServiceDescriptorProto.

Represents a ServiceOptions.

Represents a SourceCodeInfo.

Represents a Location.

Represents a Timestamp.

Represents an UninterpretedOption.

Represents a NamePart.

Represents an AcknowledgeRequest.

Represents a CreateSchemaRequest.

Represents a CreateSnapshotRequest.

Represents a DeadLetterPolicy.

Represents a DeleteSchemaRequest.

Represents a DeleteSnapshotRequest.

Represents a DeleteSubscriptionRequest.

Represents a DeleteTopicRequest.

Represents a DetachSubscriptionRequest.

Represents a DetachSubscriptionResponse.

Represents an ExpirationPolicy.

Represents a GetSchemaRequest.

Represents a GetSnapshotRequest.

Represents a GetSubscriptionRequest.

Represents a GetTopicRequest.

Represents a ListSchemasRequest.

Represents a ListSchemasResponse.

Represents a ListSnapshotsRequest.

Represents a ListSnapshotsResponse.

Represents a ListSubscriptionsRequest.

Represents a ListSubscriptionsResponse.

Represents a ListTopicSnapshotsRequest.

Represents a ListTopicSnapshotsResponse.

Represents a ListTopicsRequest.

Represents a ListTopicsResponse.

Represents a ListTopicSubscriptionsRequest.

Represents a ListTopicSubscriptionsResponse.

Represents a MessageStoragePolicy.

Represents a ModifyAckDeadlineRequest.

Represents a ModifyPushConfigRequest.

Represents a Publisher

Represents a PublishRequest.

Represents a PublishResponse.

Represents a PubsubMessage.

Represents a PullRequest.

Represents a PullResponse.

Represents a PushConfig.

Represents an OidcToken.

Represents a ReceivedMessage.

Represents a RetryPolicy.

Represents a Schema.

Represents a SchemaService

Represents a SchemaSettings.

Represents a SeekRequest.

Represents a SeekResponse.

Represents a Snapshot.

Represents a StreamingPullRequest.

Represents a StreamingPullResponse.

Represents a SubscriptionProperties.

Represents a Subscriber

Represents a Subscription.

Represents a Topic.

Represents an UpdateSnapshotRequest.

Represents an UpdateSubscriptionRequest.

Represents an UpdateTopicRequest.

Represents a ValidateMessageRequest.

Represents a ValidateMessageResponse.

Represents a ValidateSchemaRequest.

Represents a ValidateSchemaResponse.


Exception to be thrown during failed ordered publish.



[Cloud Pub/Sub]( is a reliable, many-to-many, asynchronous messaging service from Cloud Platform.


A Schema object allows you to interact with a Cloud Pub/Sub schema.

This should only be instantiated by the PubSub class. To obtain an instance for end user usage, call pubsub.schema().


A Snapshot object will give you access to your Cloud Pub/Sub snapshot.

Snapshots are sometimes retrieved when using various methods:

Snapshots may be created with:

  • You can use snapshots to seek a subscription to a specific point in time.



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]( 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.


A Topic object allows you to interact with a Cloud Pub/Sub topic.


The service that an application uses to manipulate topics, and to send messages to a topic. v1


Service for doing schema-related operations. v1


The service that an application uses to manipulate subscriptions and to consume messages from a subscription via the Pull method or by establishing a bi-directional stream using the StreamingPull method. v1





FlowControlOptions {number} [maxOutstandingMessages] The maximum number of messages to buffer before publisher flow control kicks in. {number} [maxOutstandingBytes] The maximum number of bytes to buffer before publisher flow control kicks in.


Shows which IAM permissions is allowed. The key to this object are the IAM permissions (string) and the values are booleans, true if permissions are granted to the corresponding key.


Properties of a CustomHttpPattern.

Properties of a Http.

Properties of a HttpRule.

Properties of a ResourceDescriptor.

Properties of a ResourceReference.

Properties of an ExtensionRange.

Properties of a ReservedRange.

Properties of an EnumReservedRange.

Properties of an Annotation.

Properties of a DescriptorProto.

Properties of a Duration.

Properties of an Empty.

Properties of an EnumDescriptorProto.

Properties of an EnumOptions.

Properties of an EnumValueDescriptorProto.

Properties of an EnumValueOptions.

Properties of an ExtensionRangeOptions.

Properties of a FieldDescriptorProto.

Properties of a FieldMask.

Properties of a FieldOptions.

Properties of a FileDescriptorProto.

Properties of a FileDescriptorSet.

Properties of a FileOptions.

Properties of a GeneratedCodeInfo.

Properties of a MessageOptions.

Properties of a MethodDescriptorProto.

Properties of a MethodOptions.

Properties of an OneofDescriptorProto.

Properties of an OneofOptions.

Properties of a ServiceDescriptorProto.

Properties of a ServiceOptions.

Properties of a SourceCodeInfo.

Properties of a Timestamp.

Properties of an UninterpretedOption.

Properties of a Location.

Properties of a NamePart.

Properties of an AcknowledgeRequest.

Properties of a CreateSchemaRequest.

Properties of a CreateSnapshotRequest.

Properties of a DeadLetterPolicy.

Properties of a DeleteSchemaRequest.

Properties of a DeleteSnapshotRequest.

Properties of a DeleteSubscriptionRequest.

Properties of a DeleteTopicRequest.

Properties of a DetachSubscriptionRequest.

Properties of a DetachSubscriptionResponse.

Properties of an ExpirationPolicy.

Properties of a GetSchemaRequest.

Properties of a GetSnapshotRequest.

Properties of a GetSubscriptionRequest.

Properties of a GetTopicRequest.

Properties of a ListSchemasRequest.

Properties of a ListSchemasResponse.

Properties of a ListSnapshotsRequest.

Properties of a ListSnapshotsResponse.

Properties of a ListSubscriptionsRequest.

Properties of a ListSubscriptionsResponse.

Properties of a ListTopicSnapshotsRequest.

Properties of a ListTopicSnapshotsResponse.

Properties of a ListTopicsRequest.

Properties of a ListTopicsResponse.

Properties of a ListTopicSubscriptionsRequest.

Properties of a ListTopicSubscriptionsResponse.

Properties of a MessageStoragePolicy.

Properties of a ModifyAckDeadlineRequest.

Properties of a ModifyPushConfigRequest.

Properties of a PublishRequest.

Properties of a PublishResponse.

Properties of a PubsubMessage.

Properties of a PullRequest.

Properties of a PullResponse.

Properties of a PushConfig.

Properties of a ReceivedMessage.

Properties of a RetryPolicy.

Properties of a Schema.

Properties of a SchemaSettings.

Properties of a SeekRequest.

Properties of a SeekResponse.

Properties of a Snapshot.

Properties of a StreamingPullRequest.

Properties of a StreamingPullResponse.

Properties of a Subscription.

Properties of a Topic.

Properties of an UpdateSnapshotRequest.

Properties of an UpdateSubscriptionRequest.

Properties of an UpdateTopicRequest.

Properties of a ValidateMessageRequest.

Properties of a ValidateMessageResponse.

Properties of a ValidateSchemaRequest.

Properties of a ValidateSchemaResponse.

Properties of an OidcToken.

Properties of a SubscriptionProperties.



Schema metadata that might be gathered from a Pub/Sub message. This is created for you from .



FieldBehavior enum.

History enum.

Style enum.

Label enum.

Type enum.

CType enum.

JSType enum.

OptimizeMode enum.

IdempotencyLevel enum.

Encoding enum.

Type enum.

SchemaView enum.



Encodings: {
    Json: "JSON";
    Binary: "BINARY";


SchemaTypes: {
    ProtocolBuffer: "PROTOCOL_BUFFER";
    Avro: "AVRO";


SchemaViews: {
    Basic: "BASIC";
    Full: "FULL";

Type Aliases


export declare type Attributes = Record

Strings are the only allowed values for keys and values in message attributes.


export declare type CreateSchemaResponse = google.pubsub.v1.Schema;


export declare type CreateSnapshotCallback = ResourceCallback


export declare type CreateSnapshotResponse = [Snapshot, google.pubsub.v1.ISnapshot];


export declare type CreateSubscriptionCallback = SubscriptionCallback;


export declare type CreateSubscriptionOptions = SubscriptionMetadata & {
    gaxOpts?: CallOptions;
    flowControl?: FlowControlOptions;


export declare type CreateSubscriptionResponse = SubscriptionResponse;


export declare type CreateTopicCallback = TopicCallback;


export declare type CreateTopicResponse = TopicResponse;


export declare type EmptyCallback = RequestCallback


export declare type EmptyResponse = [google.protobuf.IEmpty];


export declare type ExistsCallback = RequestCallback


export declare type ExistsResponse = [boolean];


export declare type GetPolicyCallback = RequestCallback


export declare type GetPolicyResponse = [Policy];


export declare type GetSnapshotsCallback = RequestCallback


export declare type GetSnapshotsResponse = PagedResponse


export declare type GetSubscriptionCallback = SubscriptionCallback;


export declare type GetSubscriptionMetadataCallback = MetadataCallback;


export declare type GetSubscriptionMetadataResponse = MetadataResponse;


export declare type GetSubscriptionOptions = CallOptions & {
    autoCreate?: boolean;


export declare type GetSubscriptionResponse = SubscriptionResponse;


export declare type GetSubscriptionsCallback = GetAllSubscriptionsCallback | GetTopicSubscriptionsCallback;


export declare type GetSubscriptionsResponse = GetAllSubscriptionsResponse | GetTopicSubscriptionsResponse;


export declare type GetTopicCallback = TopicCallback;


export declare type GetTopicMetadataCallback = MetadataCallback;


export declare type GetTopicMetadataResponse = MetadataResponse;


export declare type GetTopicOptions = CallOptions & {
    autoCreate?: boolean;


export declare type GetTopicResponse = TopicResponse;


export declare type GetTopicsCallback = RequestCallback


export declare type GetTopicsResponse = PagedResponse


export declare type GetTopicSubscriptionsCallback = RequestCallback


export declare type GetTopicSubscriptionsResponse = PagedResponse


export declare type ICreateSchemaRequest = google.pubsub.v1.ICreateSchemaRequest;


export declare type ISchema = google.pubsub.v1.ISchema;


export declare type Policy = {
    etag?: string | Buffer;
} & Omit

type CreateTopicCallback = (error: (Error|null), response?: google.pubsub.v1.Topic) => void;

Callback as used by .

type DeleteTopicCallback = (error: (Error|null), response?: google.protobuf.Empty) => void;

Callback as used by .

type DetachSubscriptionCallback = (error: (Error|null), response?: google.pubsub.v1.DetachSubscriptionResponse) => void;

Callback as used by .

type GetTopicCallback = (error: (Error|null), response?: google.pubsub.v1.Topic) => void;

Callback as used by .

type ListTopicsCallback = (error: (Error|null), response?: google.pubsub.v1.ListTopicsResponse) => void;

Callback as used by .

type ListTopicSnapshotsCallback = (error: (Error|null), response?: google.pubsub.v1.ListTopicSnapshotsResponse) => void;

Callback as used by .

type ListTopicSubscriptionsCallback = (error: (Error|null), response?: google.pubsub.v1.ListTopicSubscriptionsResponse) => void;

Callback as used by .

type PublishCallback = (error: (Error|null), response?: google.pubsub.v1.PublishResponse) => void;

Callback as used by .

type UpdateTopicCallback = (error: (Error|null), response?: google.pubsub.v1.Topic) => void;

Callback as used by .

type CreateSchemaCallback = (error: (Error|null), response?: google.pubsub.v1.Schema) => void;

Callback as used by .

type DeleteSchemaCallback = (error: (Error|null), response?: google.protobuf.Empty) => void;

Callback as used by .

type GetSchemaCallback = (error: (Error|null), response?: google.pubsub.v1.Schema) => void;

Callback as used by .

type ListSchemasCallback = (error: (Error|null), response?: google.pubsub.v1.ListSchemasResponse) => void;

Callback as used by .

type ValidateMessageCallback = (error: (Error|null), response?: google.pubsub.v1.ValidateMessageResponse) => void;

Callback as used by .

type ValidateSchemaCallback = (error: (Error|null), response?: google.pubsub.v1.ValidateSchemaResponse) => void;

Callback as used by .

type AcknowledgeCallback = (error: (Error|null), response?: google.protobuf.Empty) => void;

Callback as used by .

type CreateSnapshotCallback = (error: (Error|null), response?: google.pubsub.v1.Snapshot) => void;

Callback as used by .

type CreateSubscriptionCallback = (error: (Error|null), response?: google.pubsub.v1.Subscription) => void;

Callback as used by .

type DeleteSnapshotCallback = (error: (Error|null), response?: google.protobuf.Empty) => void;

Callback as used by .

type DeleteSubscriptionCallback = (error: (Error|null), response?: google.protobuf.Empty) => void;

Callback as used by .

type GetSnapshotCallback = (error: (Error|null), response?: google.pubsub.v1.Snapshot) => void;

Callback as used by .

type GetSubscriptionCallback = (error: (Error|null), response?: google.pubsub.v1.Subscription) => void;

Callback as used by .

type ListSnapshotsCallback = (error: (Error|null), response?: google.pubsub.v1.ListSnapshotsResponse) => void;

Callback as used by .

type ListSubscriptionsCallback = (error: (Error|null), response?: google.pubsub.v1.ListSubscriptionsResponse) => void;

Callback as used by .

type ModifyAckDeadlineCallback = (error: (Error|null), response?: google.protobuf.Empty) => void;

Callback as used by .

type ModifyPushConfigCallback = (error: (Error|null), response?: google.protobuf.Empty) => void;

Callback as used by .

type PullCallback = (error: (Error|null), response?: google.pubsub.v1.PullResponse) => void;

Callback as used by .

type SeekCallback = (error: (Error|null), response?: google.pubsub.v1.SeekResponse) => void;

Callback as used by .

type StreamingPullCallback = (error: (Error|null), response?: google.pubsub.v1.StreamingPullResponse) => void;

Callback as used by .

type UpdateSnapshotCallback = (error: (Error|null), response?: google.pubsub.v1.Snapshot) => void;

Callback as used by .

type UpdateSubscriptionCallback = (error: (Error|null), response?: google.pubsub.v1.Subscription) => void;

Callback as used by .


export declare type PublishCallback = RequestCallback


export declare type PushConfig = google.pubsub.v1.IPushConfig;


export declare type SchemaEncoding = keyof typeof google.pubsub.v1.Encoding;


export declare type SchemaType = keyof typeof google.pubsub.v1.Schema.Type;


export declare type SchemaView = keyof typeof google.pubsub.v1.SchemaView;


export declare type SeekCallback = RequestCallback


export declare type SeekResponse = [google.pubsub.v1.ISeekResponse];


export declare type SetPolicyCallback = RequestCallback


export declare type SetPolicyResponse = [Policy];


export declare type SetSubscriptionMetadataCallback = MetadataCallback;


export declare type SetSubscriptionMetadataResponse = MetadataResponse;


export declare type SetTopicMetadataCallback = MetadataCallback;


export declare type SetTopicMetadataResponse = MetadataResponse;


export declare type SubscriptionCloseCallback = (err?: Error) => void;


export declare type SubscriptionMetadata = {
    messageRetentionDuration?: google.protobuf.IDuration | number;
    pushEndpoint?: string;
    oidcToken?: OidcToken;
} & Omit


export declare type SubscriptionOptions = SubscriberOptions & {
    topic?: Topic;


export declare type TestIamPermissionsCallback = ResourceCallback


export declare type TestIamPermissionsResponse = [IamPermissionsMap,];


export declare type TopicMetadata = google.pubsub.v1.ITopic;