@google-cloud/pubsub

  • Version 6.3.2
  • Published
  • 978 kB
  • 18 dependencies
  • Apache-2.0 license

Install

npm i @google-cloud/pubsub
yarn add @google-cloud/pubsub
pnpm add @google-cloud/pubsub

Overview

Cloud Pub/Sub Client Library for Node.js

Index

Variables

Classes

Interfaces

Type Aliases

Namespaces

Variables

variable AckResponses

const AckResponses: {
PermissionDenied: 'PERMISSION_DENIED';
FailedPrecondition: 'FAILED_PRECONDITION';
Success: 'SUCCESS';
Invalid: 'INVALID';
Other: 'OTHER';
};

    variable Encodings

    const Encodings: { Json: 'JSON'; Binary: 'BINARY' };

      variable SchemaTypes

      const SchemaTypes: { ProtocolBuffer: 'PROTOCOL_BUFFER'; Avro: 'AVRO' };

        variable SchemaViews

        const SchemaViews: { Basic: 'BASIC'; Full: 'FULL' };

          variable SubscriptionCloseBehaviors

          const SubscriptionCloseBehaviors: {
          NackImmediately: 'NACK';
          WaitForProcessing: 'WAIT';
          };

            Classes

            class AckError

            class AckError extends Error {}
            • Thrown when an error is detected in an ack/nack/modack call, when exactly-once delivery is enabled on the subscription. This will only be thrown for actual errors that can't be retried.

            constructor

            constructor(errorCode: AckResponse, message?: string);

              property errorCode

              errorCode: AckResponse;

                class DebugMessage

                class DebugMessage {}
                • Represents a debug message the user might want to print out for logging while debugging or whatnot. These will always come by way of the 'error' channel on streams or other event emitters. It's completely fine to ignore them, as some will just be verbose logging info, but they may help figure out what's going wrong. Support may also ask you to catch these channels, which you can do like so:

                  subscription.on('debug', msg => console.log(msg.message));

                  These values are _not_ guaranteed to remain stable, even within a major version, so don't depend on them for your program logic. Debug outputs may be added or removed at any time, without warning.

                constructor

                constructor(message: string, error?: Error);

                  property error

                  error?: Error;

                    property message

                    message: string;

                      class Duration

                      class Duration {}
                      • Duration class with an interface similar to the tc39 Temporal proposal. Since it's not fully finalized, and polyfills have inconsistent compatibility, for now this shim class will be used to set durations in Pub/Sub.

                        This class will remain here for at least the next major version, eventually to be replaced by the tc39 Temporal.Duration built-in.

                        https://tc39.es/proposal-temporal/docs/duration.html https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal/Duration

                      property hours

                      readonly hours: number;
                      • Equivalent to total('hour').

                      property milliseconds

                      readonly milliseconds: number;
                      • Equivalent to total('millisecond').

                      property minutes

                      readonly minutes: number;
                      • Equivalent to total('minute').

                      property seconds

                      readonly seconds: number;
                      • Equivalent to total('second').

                      method add

                      add: (other: DurationLike | Duration) => Duration;
                      • Adds another Duration to this one and returns a new Duration.

                        Parameter other

                        A Duration or Duration-like object, like from() takes.

                        Returns

                        A new Duration.

                      method compare

                      static compare: (first: Duration, second: Duration) => 0 | 1 | -1;
                      • Compare two Duration objects. Returns -1 if the first is less than the second, zero if they are equal, 1 if the first is greater than the second.

                        Unlike tc39, this version does not accept options for relativeTo.

                      method from

                      static from: (durationLike: DurationLike | Duration) => Duration;
                      • Creates a Duration from a DurationLike, which is an object containing zero or more of the following: hours, seconds, minutes, millis.

                      method subtract

                      subtract: (other: DurationLike | Duration) => Duration;
                      • Subtracts another Duration from this one and returns a new Duration.

                        Parameter other

                        A Duration or Duration-like object, like from() takes.

                        Returns

                        A new Duration.

                      method total

                      total: (totalOf: TotalOfUnit) => number;
                      • Calculates the total number of units of type 'totalOf' that would fit inside this duration. The tc39 options parameter is not supported.

                      method totalOf

                      totalOf: (totalOf: TotalOfUnit) => number;
                      • Calculates the total number of units of type 'totalOf' that would fit inside this duration.

                        No longer part of the tc39 spec, superseded by total().

                        Deprecated

                      class IAM

                      class IAM {}
                      • [IAM (Identity and Access Management)](https://cloud.google.com/pubsub/access_control) 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.*

                        Parameter pubsub

                        PubSub Object.

                        Parameter id

                        The name of the topic or subscription.

                        Example 1

                        const {PubSub} = require('@google-cloud/pubsub');
                        const pubsub = new PubSub();
                        const topic = pubsub.topic('my-topic');
                        // topic.iam
                        const subscription = pubsub.subscription('my-subscription');
                        // subscription.iam

                        See Also

                      constructor

                      constructor(pubsub: PubSub, nameOrNameable: string | Nameable);

                        property id

                        readonly id: string;

                          property pubsub

                          pubsub: PubSub;

                            property request

                            request: <T, R = void>(
                            config: RequestConfig,
                            callback: RequestCallback<T, R>
                            ) => void;

                              method getPolicy

                              getPolicy: {
                              (gaxOpts?: CallOptions): Promise<GetPolicyResponse>;
                              (callback: NormalCallback<Policy>): void;
                              (gaxOpts: CallOptions, callback: NormalCallback<Policy>): void;
                              };
                              • Get the IAM policy

                                Parameter gaxOptions

                                Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.

                                Parameter callback

                                Callback function.

                                Returns

                                {Promise}

                                Example 1

                                const {PubSub} = require('@google-cloud/pubsub');
                                const pubsub = new PubSub();
                                const topic = pubsub.topic('my-topic');
                                const subscription = topic.subscription('my-subscription');
                                topic.iam.getPolicy(function(err, policy, apiResponse) {});
                                subscription.iam.getPolicy(function(err, policy, apiResponse) {});
                                //-
                                // If the callback is omitted, we'll return a Promise.
                                //-
                                topic.iam.getPolicy().then(function(data) {
                                const policy = data[0];
                                const apiResponse = data[1];
                                });

                                See Also

                              method setPolicy

                              setPolicy: {
                              (policy: Policy, gaxOpts?: CallOptions): Promise<SetPolicyResponse>;
                              (
                              policy: Policy,
                              gaxOpts: CallOptions,
                              callback: NormalCallback<Policy>
                              ): void;
                              (policy: Policy, callback: NormalCallback<Policy>): void;
                              };
                              • Set the IAM policy

                                Parameter policy

                                The [policy](https://cloud.google.com/pubsub/docs/reference/rest/v1/Policy).

                                Parameter

                                {array} [policy.bindings] Bindings associate members with roles.

                                Parameter

                                {Array} [policy.rules] Rules to be applied to the policy.

                                Parameter

                                {string} [policy.etag] Etags are used to perform a read-modify-write.

                                Parameter gaxOptions

                                Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.

                                Parameter callback

                                Callback function.

                                Returns

                                {Promise}

                                Throws

                                {Error} If no policy is provided.

                                Example 1

                                const {PubSub} = require('@google-cloud/pubsub');
                                const pubsub = new PubSub();
                                const topic = pubsub.topic('my-topic');
                                const subscription = topic.subscription('my-subscription');
                                const myPolicy = {
                                bindings: [
                                {
                                role: 'roles/pubsub.subscriber',
                                members:
                                ['serviceAccount:myotherproject@appspot.gserviceaccount.com']
                                }
                                ]
                                };
                                topic.iam.setPolicy(myPolicy, function(err, policy, apiResponse) {});
                                subscription.iam.setPolicy(myPolicy, function(err, policy, apiResponse)
                                {});
                                //-
                                // If the callback is omitted, we'll return a Promise.
                                //-
                                topic.iam.setPolicy(myPolicy).then(function(data) {
                                const policy = data[0];
                                const apiResponse = data[1];
                                });

                                See Also

                              method testPermissions

                              testPermissions: {
                              (
                              permissions: string | string[],
                              gaxOpts?: CallOptions
                              ): Promise<TestIamPermissionsResponse>;
                              (
                              permissions: string | string[],
                              gaxOpts: CallOptions,
                              callback: TestIamPermissionsCallback
                              ): void;
                              (permissions: string | string[], callback: TestIamPermissionsCallback): void;
                              };
                              • Test a set of permissions for a resource.

                                Permissions with wildcards such as * or storage.* are not allowed.

                                Parameter permissions

                                The permission(s) to test for.

                                Parameter gaxOptions

                                Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.

                                Parameter callback

                                Callback function.

                                Returns

                                {Promise}

                                Throws

                                {Error} If permissions are not provided.

                                Example 1

                                const {PubSub} = require('@google-cloud/pubsub');
                                const pubsub = new PubSub();
                                const topic = pubsub.topic('my-topic');
                                const subscription = topic.subscription('my-subscription');
                                //-
                                // Test a single permission.
                                //-
                                const test = 'pubsub.topics.update';
                                topic.iam.testPermissions(test, function(err, permissions, apiResponse) {
                                console.log(permissions);
                                // {
                                // "pubsub.topics.update": true
                                // }
                                });
                                //-
                                // Test several permissions at once.
                                //-
                                const tests = [
                                'pubsub.subscriptions.consume',
                                'pubsub.subscriptions.update'
                                ];
                                subscription.iam.testPermissions(tests, function(err, permissions) {
                                console.log(permissions);
                                // {
                                // "pubsub.subscriptions.consume": true,
                                // "pubsub.subscriptions.update": false
                                // }
                                });
                                //-
                                // If the callback is omitted, we'll return a Promise.
                                //-
                                topic.iam.testPermissions(test).then(function(data) {
                                const permissions = data[0];
                                const apiResponse = data[1];
                                });

                                See Also

                              class Message

                              class Message implements tracing.MessageWithAttributes {}
                              • Message objects provide a simple interface for users to get message data and acknowledge the message.

                                Example 1

                                subscription.on('message', message => {
                                // {
                                // ackId: 'RUFeQBJMJAxESVMrQwsqWBFOBCEhPjA',
                                // attributes: {key: 'value'},
                                // data: Buffer.from('Hello, world!'),
                                // id: '1551297743043',
                                // orderingKey: 'ordering-key',
                                // publishTime: new PreciseDate('2019-02-27T20:02:19.029534186Z'),
                                // received: 1551297743043,
                                // length: 13
                                // }
                                });

                              constructor

                              constructor(
                              sub: Subscriber,
                              { ackId, message, deliveryAttempt }: google.pubsub.v1.IReceivedMessage
                              );
                              • Parameter sub

                                The parent subscriber.

                                Parameter message

                                The raw message response.

                              property ackId

                              ackId: string;

                                property attributes

                                attributes: { [key: string]: string };

                                  property data

                                  data: Buffer;

                                    property deliveryAttempt

                                    deliveryAttempt: number;

                                      property handledPromise

                                      readonly handledPromise: Promise<void>;
                                      • Resolves when the message has been handled fully; a handled message may not have any further operations performed on it.

                                      property id

                                      id: string;

                                        property length

                                        readonly length: number;
                                        • The length of the message data.

                                          {number}

                                        property orderingKey

                                        orderingKey?: string;

                                          property parentSpan

                                          parentSpan?: tracing.Span;
                                          • Tracks a telemetry tracing parent span through the receive process. This will be the original publisher-side span if we have one; otherwise we'll create a "publisher" span to hang new subscriber spans onto.

                                            This needs to be declared explicitly here, because having a public class implement a private interface seems to confuse TypeScript. (And it's needed in unit tests.)

                                          property publishTime

                                          publishTime: PreciseDate;

                                            property received

                                            received: number;

                                              property subSpans

                                              subSpans: SubscriberSpans;
                                              • Tracks subscriber-specific telemetry objects through the library.

                                              method ack

                                              ack: () => void;
                                              • Acknowledges the message.

                                                Example 1

                                                subscription.on('message', message => {
                                                message.ack();
                                                });

                                              method ackFailed

                                              ackFailed: (error: AckError) => void;
                                              • Sets this message's exactly once delivery acks to permanent failure. This is meant for internal library use only.

                                              method ackWithResponse

                                              ackWithResponse: () => Promise<AckResponse>;
                                              • Acknowledges the message, expecting a response (for exactly-once delivery subscriptions). If exactly-once delivery is not enabled, this will immediately resolve successfully.

                                                Example 1

                                                subscription.on('message', async (message) => {
                                                const response = await message.ackWithResponse();
                                                });

                                              method dispatched

                                              dispatched: () => void;
                                              • When this message is dispensed to user callback code, this should be called. The time between the dispatch and the handledPromise resolving is when the message is with the user.

                                              method endParentSpan

                                              endParentSpan: () => void;
                                              • Ends any open subscribe telemetry tracing span.

                                              method isDispatched

                                              isDispatched: () => boolean;
                                              • Returns

                                                True if this message has been dispatched to user callback code.

                                              method modAck

                                              modAck: (deadline: number) => void;
                                              • Modifies the ack deadline. At present time, this should generally not be called by users.

                                                Parameter deadline

                                                The number of seconds to extend the deadline.

                                              method modAckWithResponse

                                              modAckWithResponse: (deadline: number) => Promise<AckResponse>;
                                              • Modifies the ack deadline, expecting a response (for exactly-once delivery subscriptions). If exactly-once delivery is not enabled, this will immediately resolve successfully. At present time, this should generally not be called by users.

                                                Parameter deadline

                                                The number of seconds to extend the deadline.

                                              method nack

                                              nack: () => void;
                                              • Removes the message from our inventory and schedules it to be redelivered.

                                                Example 1

                                                subscription.on('message', message => {
                                                message.nack();
                                                });

                                              method nackWithResponse

                                              nackWithResponse: () => Promise<AckResponse>;
                                              • Removes the message from our inventory and schedules it to be redelivered, with the modAck response being returned (for exactly-once delivery subscriptions). If exactly-once delivery is not enabled, this will immediately resolve successfully.

                                                Example 1

                                                subscription.on('message', async (message) => {
                                                const response = await message.nackWithResponse();
                                                });

                                              class PublishError

                                              class PublishError extends Error implements grpc.ServiceError {}
                                              • Exception to be thrown during failed ordered publish.

                                                Error

                                              constructor

                                              constructor(key: string, err: grpc.ServiceError);

                                                property code

                                                code: grpc.status;

                                                  property details

                                                  details: string;

                                                    property error

                                                    error: grpc.ServiceError;

                                                      property metadata

                                                      metadata: grpc.Metadata;

                                                        property orderingKey

                                                        orderingKey: string;

                                                          class PubSub

                                                          class PubSub {}
                                                          • [Cloud Pub/Sub](https://developers.google.com/pubsub/overview) is a reliable, many-to-many, asynchronous messaging service from Cloud Platform.

                                                            Parameter options

                                                            Configuration options.

                                                            Example 1

                                                            Import the client library

                                                            const {PubSub} = require('@google-cloud/pubsub');

                                                            Example 2

                                                            Create a client that uses Application Default Credentials (ADC):

                                                            const pubsub = new PubSub();

                                                            Example 3

                                                            Create a client with explicit credentials:

                                                            const pubsub = new PubSub({
                                                            projectId: 'your-project-id',
                                                            keyFilename: '/path/to/keyfile.json'
                                                            });

                                                            Example 4

                                                            include:samples/quickstart.js region_tag:pubsub_quickstart_create_topic Full quickstart example:

                                                            See Also

                                                          constructor

                                                          constructor(options?: ClientConfig);

                                                            property api

                                                            api: { [key: string]: gax.ClientStub };

                                                              property auth

                                                              auth: GoogleAuth;

                                                                property getSnapshotsStream

                                                                getSnapshotsStream: () => ObjectStream<Snapshot>;

                                                                  property getSubscriptionsStream

                                                                  getSubscriptionsStream: () => ObjectStream<Subscription>;

                                                                    property getTopicsStream

                                                                    getTopicsStream: () => ObjectStream<Topic>;

                                                                      property isEmulator

                                                                      isEmulator: boolean;

                                                                        property isIdResolved

                                                                        readonly isIdResolved: boolean;
                                                                        • Returns true if we have actually resolved the full project name.

                                                                          Returns

                                                                          {boolean} true if the name is resolved.

                                                                        property isOpen

                                                                        isOpen: boolean;

                                                                          property name

                                                                          name?: string;

                                                                            property options

                                                                            options: ClientConfig;

                                                                              property projectId

                                                                              projectId: string;

                                                                                property Promise

                                                                                Promise?: PromiseConstructor;

                                                                                  method close

                                                                                  close: {
                                                                                  (): Promise<void>;
                                                                                  (callback: NormalCallback<google.protobuf.IEmpty>): void;
                                                                                  };
                                                                                  • Closes the PubSub client, releasing any underlying gRPC connections.

                                                                                    Note that once you close a PubSub object, it may not be used again. Any pending operations (e.g. queued publish messages) will fail. If you have topic or subscription objects that may have pending operations, you should call close() on those first if you want any pending messages to be delivered correctly. The PubSub class doesn't track those.

                                                                                    Note that this method primarily closes the gRPC clients (Publisher and Subscriber) used for API requests. It does **not** automatically handle the graceful shutdown of active subscriptions.

                                                                                    For graceful shutdown of subscriptions with specific timeout behavior (e.g., ensuring buffered messages are nacked before closing), please refer to the Subscription#close method. It is recommended to call Subscription.close({timeout: ...}) directly on your active Subscription objects *before* calling PubSub.close() if you require that specific shutdown behavior.

                                                                                    Calling PubSub.close() without first closing active subscriptions might result in abrupt termination of message processing for those subscriptions. Any pending operations on associated Topic or Subscription objects (e.g., queued publish messages or unacked subscriber messages) may fail after PubSub.close() is called.

                                                                                    EmptyCallback

                                                                                    Parameter err

                                                                                    Request error, if any.

                                                                                    Returns

                                                                                    {Promise} Resolves when the clients are closed.

                                                                                  method closeAllClients_

                                                                                  closeAllClients_: () => Promise<void>;
                                                                                  • Close all open client objects.

                                                                                    Returns

                                                                                    {Promise}

                                                                                  method createSchema

                                                                                  createSchema: (
                                                                                  schemaId: string,
                                                                                  type: SchemaType,
                                                                                  definition: string,
                                                                                  gaxOpts?: CallOptions
                                                                                  ) => Promise<Schema>;
                                                                                  • Create a schema in the project.

                                                                                    Parameter schemaId

                                                                                    The name or ID of the subscription.

                                                                                    Parameter type

                                                                                    The type of the schema (Protobuf, Avro, etc).

                                                                                    Parameter definition

                                                                                    The text describing the schema in terms of the type.

                                                                                    Parameter options

                                                                                    Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.

                                                                                    Returns

                                                                                    {Promise}

                                                                                    Throws

                                                                                    {Error} If a schema ID or name is not provided.

                                                                                    Throws

                                                                                    {Error} If an invalid SchemaType is provided.

                                                                                    Throws

                                                                                    {Error} If an invalid schema definition is provided.

                                                                                    Example 1

                                                                                    Create a schema.

                                                                                    const {PubSub} = require('@google-cloud/pubsub');
                                                                                    const pubsub = new PubSub();
                                                                                    await pubsub.createSchema(
                                                                                    'messageType',
                                                                                    SchemaTypes.Avro,
                                                                                    '{...avro definition...}'
                                                                                    );

                                                                                    See Also

                                                                                  method createSubscription

                                                                                  createSubscription: {
                                                                                  (
                                                                                  topic: Topic | string,
                                                                                  name: string,
                                                                                  options?: CreateSubscriptionOptions
                                                                                  ): Promise<CreateSubscriptionResponse>;
                                                                                  (topic: string | Topic, name: string, callback: SubscriptionCallback): void;
                                                                                  (
                                                                                  topic: string | Topic,
                                                                                  name: string,
                                                                                  options: CreateSubscriptionOptions,
                                                                                  callback: SubscriptionCallback
                                                                                  ): void;
                                                                                  };
                                                                                  • Create a subscription to a topic.

                                                                                    Parameter topic

                                                                                    The Topic to create a subscription to.

                                                                                    Parameter name

                                                                                    The name of the subscription.

                                                                                    Parameter options

                                                                                    See a [Subscription resource](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions).

                                                                                    Parameter callback

                                                                                    Callback function.

                                                                                    Returns

                                                                                    {Promise}

                                                                                    Throws

                                                                                    {Error} If a Topic instance or topic name is not provided.

                                                                                    Throws

                                                                                    {Error} If a subscription name is not provided.

                                                                                    Example 1

                                                                                    Subscribe to a topic.

                                                                                    const {PubSub} = require('@google-cloud/pubsub');
                                                                                    const pubsub = new PubSub();
                                                                                    const topic = 'messageCenter';
                                                                                    const name = 'newMessages';
                                                                                    const callback = function(err, subscription, apiResponse) {};
                                                                                    pubsub.createSubscription(topic, name, callback);

                                                                                    Example 2

                                                                                    If the callback is omitted, we'll return a Promise.

                                                                                    pubsub.createSubscription(topic, name)
                                                                                    .then(function(data) {
                                                                                    const subscription = data[0];
                                                                                    const apiResponse = data[1];
                                                                                    });

                                                                                    See Also

                                                                                  method createTopic

                                                                                  createTopic: {
                                                                                  (
                                                                                  name: string | TopicMetadata,
                                                                                  gaxOpts?: CallOptions
                                                                                  ): Promise<CreateTopicResponse>;
                                                                                  (name: any, callback: TopicCallback): void;
                                                                                  (name: any, gaxOpts: CallOptions, callback: TopicCallback): void;
                                                                                  };
                                                                                  • Create a topic with the given name.

                                                                                    Parameter name

                                                                                    Name of the topic.

                                                                                    Parameter gaxOpts

                                                                                    Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.

                                                                                    Parameter callback

                                                                                    Callback function.

                                                                                    Returns

                                                                                    {Promise}

                                                                                    Example 1

                                                                                    const {PubSub} = require('@google-cloud/pubsub');
                                                                                    const pubsub = new PubSub();
                                                                                    pubsub.createTopic('my-new-topic', function(err, topic, apiResponse) {
                                                                                    if (!err) {
                                                                                    // The topic was created successfully.
                                                                                    }
                                                                                    });
                                                                                    //-
                                                                                    // If the callback is omitted, we'll return a Promise.
                                                                                    //-
                                                                                    pubsub.createTopic('my-new-topic').then(function(data) {
                                                                                    const topic = data[0];
                                                                                    const apiResponse = data[1];
                                                                                    });

                                                                                    See Also

                                                                                  method detachSubscription

                                                                                  detachSubscription: {
                                                                                  (name: string, gaxOpts?: CallOptions): Promise<DetachSubscriptionResponse>;
                                                                                  (name: string, callback: NormalCallback<google.protobuf.IEmpty>): void;
                                                                                  (
                                                                                  name: string,
                                                                                  gaxOpts: CallOptions,
                                                                                  callback: NormalCallback<google.protobuf.IEmpty>
                                                                                  ): void;
                                                                                  };
                                                                                  • Detach a subscription with the given name.

                                                                                    Parameter name

                                                                                    Name of the subscription.

                                                                                    Parameter gaxOpts

                                                                                    Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.

                                                                                    Parameter callback

                                                                                    Callback function.

                                                                                    Returns

                                                                                    {Promise}

                                                                                    Example 1

                                                                                    const {PubSub} = require('@google-cloud/pubsub');
                                                                                    const pubsub = new PubSub();
                                                                                    pubsub.detachSubscription('my-sub', (err, topic, apiResponse) => {
                                                                                    if (!err) {
                                                                                    // The topic was created successfully.
                                                                                    }
                                                                                    });
                                                                                    //-
                                                                                    // If the callback is omitted, we'll return a Promise.
                                                                                    //-
                                                                                    pubsub.detachSubscription('my-sub').then(data => {
                                                                                    const apiResponse = data[0];
                                                                                    });

                                                                                    See Also

                                                                                  method determineBaseUrl_

                                                                                  determineBaseUrl_: () => void;
                                                                                  • Determine the appropriate endpoint to use for API requests, first trying the apiEndpoint parameter. If that isn't set, we try the Pub/Sub emulator environment variable (PUBSUB_EMULATOR_HOST). If that is also null, we try the standard gcloud alpha pubsub environment variable (CLOUDSDK_API_ENDPOINT_OVERRIDES_PUBSUB). Otherwise the default production API is used.

                                                                                    Note that if the URL doesn't end in '.googleapis.com', we will assume that it's an emulator and disable strict SSL checks.

                                                                                  method formatName_

                                                                                  static formatName_: (name: string) => string;

                                                                                    method getClient_

                                                                                    getClient_: (config: GetClientConfig, callback: GetClientCallback) => void;
                                                                                    • Get the PubSub client object.

                                                                                      Parameter config

                                                                                      Configuration object.

                                                                                      Parameter

                                                                                      {object} config.gaxOpts GAX options.

                                                                                      Parameter

                                                                                      {function} config.method The gax method to call.

                                                                                      Parameter

                                                                                      {object} config.reqOpts Request options.

                                                                                      Parameter callback

                                                                                      The callback function.

                                                                                    method getClientAsync_

                                                                                    getClientAsync_: (config: GetClientConfig) => Promise<gax.ClientStub>;
                                                                                    • Get the PubSub client object.

                                                                                      Parameter config

                                                                                      Configuration object.

                                                                                      Parameter

                                                                                      {object} config.gaxOpts GAX options.

                                                                                      Parameter

                                                                                      {function} config.method The gax method to call.

                                                                                      Parameter

                                                                                      {object} config.reqOpts Request options.

                                                                                      Returns

                                                                                      {Promise}

                                                                                    method getClientConfig

                                                                                    getClientConfig: () => Promise<ClientConfig>;
                                                                                    • Retrieve a client configuration, suitable for passing into a GAPIC 'v1' class constructor. This will fill out projectId, emulator URLs, and so forth.

                                                                                      Returns

                                                                                      {Promise} the filled client configuration.

                                                                                    method getSchemaClient

                                                                                    getSchemaClient: () => Promise<SchemaServiceClient>;
                                                                                    • Gets a schema client, creating one if needed. This is a shortcut for new v1.SchemaServiceClient(await pubsub.getClientConfig()).

                                                                                      Returns

                                                                                      {Promise}

                                                                                    method getSnapshots

                                                                                    getSnapshots: {
                                                                                    (options?: PageOptions): Promise<GetSnapshotsResponse>;
                                                                                    (
                                                                                    callback:
                                                                                    | NormalCallback<Snapshot>
                                                                                    | PagedCallback<Snapshot, google.pubsub.v1.IListSnapshotsResponse>
                                                                                    ): void;
                                                                                    (
                                                                                    options: PageOptions,
                                                                                    callback:
                                                                                    | NormalCallback<Snapshot>
                                                                                    | PagedCallback<Snapshot, google.pubsub.v1.IListSnapshotsResponse>
                                                                                    ): void;
                                                                                    };
                                                                                    • Get a list of snapshots.

                                                                                      Parameter query

                                                                                      Query object for listing snapshots.

                                                                                      Parameter callback

                                                                                      Callback function.

                                                                                      Returns

                                                                                      {Promise}

                                                                                      Example 1

                                                                                      const {PubSub} = require('@google-cloud/pubsub');
                                                                                      const pubsub = new PubSub();
                                                                                      pubsub.getSnapshots(function(err, snapshots) {
                                                                                      if (!err) {
                                                                                      // snapshots is an array of Snapshot objects.
                                                                                      }
                                                                                      });
                                                                                      //-
                                                                                      // If the callback is omitted, we'll return a Promise.
                                                                                      //-
                                                                                      pubsub.getSnapshots().then(function(data) {
                                                                                      const snapshots = data[0];
                                                                                      });

                                                                                    method getSubscriptions

                                                                                    getSubscriptions: {
                                                                                    (options?: GetSubscriptionsOptions): Promise<GetSubscriptionsResponse>;
                                                                                    (callback: GetSubscriptionsCallback): void;
                                                                                    (options: GetSubscriptionsOptions, callback: GetSubscriptionsCallback): void;
                                                                                    };
                                                                                    • Get a list of the subscriptions registered to all of your project's topics. You may optionally provide a query object as the first argument to customize the response.

                                                                                      Your provided callback will be invoked with an error object if an API error occurred or an array of Subscription objects.

                                                                                      To get subscriptions for a topic, see Topic.

                                                                                      Parameter query

                                                                                      Query object for listing subscriptions.

                                                                                      Parameter callback

                                                                                      Callback function.

                                                                                      Returns

                                                                                      {Promise}

                                                                                      Example 1

                                                                                      const {PubSub} = require('@google-cloud/pubsub');
                                                                                      const pubsub = new PubSub();
                                                                                      pubsub.getSubscriptions(function(err, subscriptions) {
                                                                                      if (!err) {
                                                                                      // subscriptions is an array of Subscription objects.
                                                                                      }
                                                                                      });
                                                                                      //-
                                                                                      // If the callback is omitted, we'll return a Promise.
                                                                                      //-
                                                                                      pubsub.getSubscriptions().then(function(data) {
                                                                                      const subscriptions = data[0];
                                                                                      });

                                                                                      See Also

                                                                                    method getTopics

                                                                                    getTopics: {
                                                                                    (options?: PageOptions): Promise<GetTopicsResponse>;
                                                                                    (
                                                                                    callback:
                                                                                    | NormalCallback<Topic>
                                                                                    | PagedCallback<Topic, google.pubsub.v1.IListTopicsResponse>
                                                                                    ): void;
                                                                                    (
                                                                                    options: PageOptions,
                                                                                    callback:
                                                                                    | NormalCallback<Topic>
                                                                                    | PagedCallback<Topic, google.pubsub.v1.IListTopicsResponse>
                                                                                    ): void;
                                                                                    };
                                                                                    • Get a list of the topics registered to your project. You may optionally provide a query object as the first argument to customize the response.

                                                                                      Parameter query

                                                                                      Query object for listing topics.

                                                                                      Parameter callback

                                                                                      Callback function.

                                                                                      Returns

                                                                                      {Promise}

                                                                                      Example 1

                                                                                      const {PubSub} = require('@google-cloud/pubsub');
                                                                                      const pubsub = new PubSub();
                                                                                      pubsub.getTopics(function(err, topics) {
                                                                                      if (!err) {
                                                                                      // topics is an array of Topic objects.
                                                                                      }
                                                                                      });
                                                                                      //-
                                                                                      // Customize the query.
                                                                                      //-
                                                                                      pubsub.getTopics({
                                                                                      pageSize: 3
                                                                                      }, function(err, topics) {});
                                                                                      //-
                                                                                      // If the callback is omitted, we'll return a Promise.
                                                                                      //-
                                                                                      pubsub.getTopics().then(function(data) {
                                                                                      const topics = data[0];
                                                                                      });

                                                                                      See Also

                                                                                    method listSchemas

                                                                                    listSchemas: (
                                                                                    view?: SchemaView,
                                                                                    options?: CallOptions
                                                                                    ) => AsyncIterable<google.pubsub.v1.ISchema>;

                                                                                    method request

                                                                                    request: <T, R = void>(
                                                                                    config: RequestConfig,
                                                                                    callback: RequestCallback<T, R>
                                                                                    ) => void;
                                                                                    • Funnel all API requests through this method, to be sure we have a project ID.

                                                                                      Parameter config

                                                                                      Configuration object.

                                                                                      Parameter

                                                                                      {object} config.gaxOpts GAX options.

                                                                                      Parameter

                                                                                      {function} config.method The gax method to call.

                                                                                      Parameter

                                                                                      {object} config.reqOpts Request options.

                                                                                      Parameter callback

                                                                                      The callback function.

                                                                                    method schema

                                                                                    schema: (idOrName: string) => Schema;
                                                                                    • Create a Schema object, representing a schema within the project. See PubSub#createSchema or Schema#create to create a schema.

                                                                                      Parameter name

                                                                                      The ID or name of the schema.

                                                                                      Returns

                                                                                      {Schema} A Schema instance.

                                                                                      Throws

                                                                                      {Error} If a name is not provided.

                                                                                      Example 1

                                                                                      const {PubSub} = require('@google-cloud/pubsub');
                                                                                      const pubsub = new PubSub();
                                                                                      const schema = pubsub.schema('my-schema');

                                                                                    method snapshot

                                                                                    snapshot: (name: string) => Snapshot;
                                                                                    • Create a Snapshot object. See Subscription#createSnapshot to create a snapshot.

                                                                                      Parameter name

                                                                                      The name of the snapshot.

                                                                                      Returns

                                                                                      {Snapshot} A Snapshot instance.

                                                                                      Throws

                                                                                      {Error} If a name is not provided.

                                                                                      Example 1

                                                                                      const {PubSub} = require('@google-cloud/pubsub');
                                                                                      const pubsub = new PubSub();
                                                                                      const snapshot = pubsub.snapshot('my-snapshot');

                                                                                    method subscription

                                                                                    subscription: (name: string, options?: SubscriptionOptions) => Subscription;
                                                                                    • Create a Subscription object. This command by itself will not run any API requests. You will receive a Subscription object, which will allow you to interact with a subscription.

                                                                                      Parameter name

                                                                                      Name of the subscription.

                                                                                      Parameter options

                                                                                      Configuration object.

                                                                                      Returns

                                                                                      {Subscription} A Subscription instance.

                                                                                      Throws

                                                                                      {Error} If subscription name is omitted.

                                                                                      Example 1

                                                                                      const {PubSub} = require('@google-cloud/pubsub');
                                                                                      const pubsub = new PubSub();
                                                                                      const subscription = pubsub.subscription('my-subscription');
                                                                                      // Register a listener for `message` events.
                                                                                      subscription.on('message', function(message) {
                                                                                      // Called every time a message is received.
                                                                                      // message.id = ID of the message.
                                                                                      // message.ackId = ID used to acknowledge the message receival.
                                                                                      // message.data = Contents of the message.
                                                                                      // message.attributes = Attributes of the message.
                                                                                      // message.publishTime = Date when Pub/Sub received the message.
                                                                                      });

                                                                                    method topic

                                                                                    topic: (name: string, options?: PublishOptions) => Topic;
                                                                                    • Create a Topic object. See PubSub#createTopic to create a topic.

                                                                                      Parameter name

                                                                                      The name of the topic.

                                                                                      Parameter options

                                                                                      Publisher configuration object.

                                                                                      Returns

                                                                                      {Topic} A Topic instance.

                                                                                      Throws

                                                                                      {Error} If a name is not provided.

                                                                                      Example 1

                                                                                      const {PubSub} = require('@google-cloud/pubsub');
                                                                                      const pubsub = new PubSub();
                                                                                      const topic = pubsub.topic('my-topic');

                                                                                    method validateSchema

                                                                                    validateSchema: (
                                                                                    schema: google.pubsub.v1.ISchema,
                                                                                    gaxOpts?: CallOptions
                                                                                    ) => Promise<void>;
                                                                                    • Validate a schema definition.

                                                                                      Parameter schema

                                                                                      The schema definition you wish to validate.

                                                                                      Parameter options

                                                                                      Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.

                                                                                      Returns

                                                                                      {Promise}

                                                                                      Throws

                                                                                      {Error} if the validation fails.

                                                                                      See Also

                                                                                    class Schema

                                                                                    class Schema {}
                                                                                    • 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().

                                                                                      Parameter pubsub

                                                                                      The PubSub object creating this object.

                                                                                      Parameter id

                                                                                      name or ID of the schema.

                                                                                      Example 1

                                                                                      Creating an instance of this class.

                                                                                      const {PubSub} = require('@google-cloud/pubsub');
                                                                                      const pubsub = new PubSub();
                                                                                      const schema = pubsub.schema('my-schema');

                                                                                      Example 2

                                                                                      Getting the details of a schema. Note that Schema methods do not provide a callback interface. Use .then() or await.

                                                                                      const {PubSub} = require('@google-cloud/pubsub');
                                                                                      const pubsub = new PubSub();
                                                                                      const schema = pubsub.schema('my-schema');
                                                                                      schema.get(SchemaViews.Basic).then(console.log);

                                                                                    constructor

                                                                                    constructor(pubsub: PubSub, idOrName: string);

                                                                                      property id

                                                                                      id: string;

                                                                                        property name_

                                                                                        name_?: string;

                                                                                          property pubsub

                                                                                          pubsub: PubSub;

                                                                                            method create

                                                                                            create: (
                                                                                            type: SchemaType,
                                                                                            definition: string,
                                                                                            gaxOpts?: CallOptions
                                                                                            ) => Promise<void>;
                                                                                            • Create a schema.

                                                                                              Parameter type

                                                                                              The type of the schema (Protobuf, Avro, etc).

                                                                                              Parameter definition

                                                                                              The text describing the schema in terms of the type.

                                                                                              Parameter options

                                                                                              Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.

                                                                                              Returns

                                                                                              {Promise}

                                                                                              Throws

                                                                                              {Error} if the schema type is incorrect.

                                                                                              Throws

                                                                                              {Error} if the definition is invalid.

                                                                                              Example 1

                                                                                              Create a schema.

                                                                                              const {PubSub} = require('@google-cloud/pubsub');
                                                                                              const pubsub = new PubSub();
                                                                                              const schema = pubsub.schema('messageType');
                                                                                              await schema.create(
                                                                                              SchemaTypes.Avro,
                                                                                              '{...avro definition...}'
                                                                                              );

                                                                                              See Also

                                                                                            method delete

                                                                                            delete: (gaxOpts?: CallOptions) => Promise<void>;

                                                                                            method formatName_

                                                                                            static formatName_: (projectId: string, nameOrId: string) => string;

                                                                                              method get

                                                                                              get: (view?: SchemaView, gaxOpts?: CallOptions) => Promise<ISchema>;
                                                                                              • Get full information about the schema from the service.

                                                                                                Parameter view

                                                                                                The type of schema object requested, which should be an enum value from SchemaViews. Defaults to Full.

                                                                                                Parameter options

                                                                                                Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.

                                                                                                Returns

                                                                                                {Promise}

                                                                                                See Also

                                                                                              method getName

                                                                                              getName: () => Promise<string>;
                                                                                              • Return the fully qualified name of this schema.

                                                                                                Note that we have to verify that we have a projectId before returning this, so we have to check that first.

                                                                                                {Promise} a Promise that resolves to the full schema name

                                                                                              method metadataFromMessage

                                                                                              static metadataFromMessage: (attributes: Attributes) => SchemaMessageMetadata;
                                                                                              • Translates the schema attributes in messages delivered from Pub/Sub. All resulting fields may end up being blank.

                                                                                              method validateMessage

                                                                                              validateMessage: (
                                                                                              message: string,
                                                                                              encoding: google.pubsub.v1.Encoding | keyof typeof google.pubsub.v1.Encoding,
                                                                                              gaxOpts?: CallOptions
                                                                                              ) => Promise<void>;
                                                                                              • Validate a message against this schema's definition.

                                                                                                If you would like to validate a message against an arbitrary schema, please use the SchemaServiceClient GAPIC class directly, using your PubSub instance's configuration, via PubSub#getClientConfig.

                                                                                                Parameter message

                                                                                                The message to validate.

                                                                                                Parameter encoding

                                                                                                The encoding of the message to validate.

                                                                                                Parameter options

                                                                                                Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.

                                                                                                Returns

                                                                                                {Promise}

                                                                                                Throws

                                                                                                {Error} if the validation fails.

                                                                                                Throws

                                                                                                {Error} if other parameters are invalid.

                                                                                                See Also

                                                                                              class Snapshot

                                                                                              class Snapshot {}
                                                                                              • A Snapshot object will give you access to your Cloud Pub/Sub snapshot.

                                                                                                Snapshots are sometimes retrieved when using various methods:

                                                                                                - PubSub#getSnapshots - PubSub#getSnapshotsStream - PubSub#snapshot

                                                                                                Snapshots may be created with:

                                                                                                - Subscription#createSnapshot

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

                                                                                                - Subscription#seek

                                                                                                Example 1

                                                                                                //-
                                                                                                // From {@link PubSub#getSnapshots}:
                                                                                                //-
                                                                                                pubsub.getSnapshots((err, snapshots) => {
                                                                                                // `snapshots` is an array of Snapshot objects.
                                                                                                });
                                                                                                //-
                                                                                                // From {@link PubSub#getSnapshotsStream}:
                                                                                                //-
                                                                                                pubsub.getSnapshotsStream()
                                                                                                .on('error', console.error)
                                                                                                .on('data', (snapshot) => {
                                                                                                // `snapshot` is a Snapshot object.
                                                                                                });
                                                                                                //-
                                                                                                // From {@link PubSub#snapshot}:
                                                                                                //-
                                                                                                const snapshot = pubsub.snapshot('my-snapshot');
                                                                                                // snapshot is a Snapshot object.
                                                                                                //-
                                                                                                // Create a snapshot with {module:pubsub/subscription#createSnapshot}:
                                                                                                //-
                                                                                                const subscription = pubsub.subscription('my-subscription');
                                                                                                subscription.createSnapshot('my-snapshot', (err, snapshot) => {
                                                                                                if (!err) {
                                                                                                // `snapshot` is a Snapshot object.
                                                                                                }
                                                                                                });
                                                                                                //-
                                                                                                // Seek to your snapshot:
                                                                                                //-
                                                                                                const subscription = pubsub.subscription('my-subscription');
                                                                                                subscription.seek('my-snapshot', (err) => {
                                                                                                if (err) {
                                                                                                // Error handling omitted.
                                                                                                }
                                                                                                });

                                                                                              constructor

                                                                                              constructor(parent: PubSub | Subscription, name: string);

                                                                                                property metadata

                                                                                                metadata?: google.pubsub.v1.ISnapshot;

                                                                                                  property name

                                                                                                  name: string;

                                                                                                    property parent

                                                                                                    parent: PubSub | Subscription;

                                                                                                      method create

                                                                                                      create: {
                                                                                                      (gaxOpts?: CallOptions): Promise<CreateSnapshotResponse>;
                                                                                                      (callback: CreateSnapshotCallback): void;
                                                                                                      (gaxOpts: CallOptions, callback: CreateSnapshotCallback): void;
                                                                                                      };
                                                                                                      • Create a snapshot with the given name.

                                                                                                        **This is only available if you accessed this object through Subscription#snapshot.**

                                                                                                        Snapshot#create

                                                                                                        Parameter name

                                                                                                        Name of the snapshot.

                                                                                                        Parameter callback

                                                                                                        The callback function.

                                                                                                        Parameter

                                                                                                        {?error} callback.err An error from the API call, may be null.

                                                                                                        Parameter

                                                                                                        {Snapshot} callback.snapshot The newly created snapshot.

                                                                                                        Parameter

                                                                                                        {object} callback.apiResponse The full API response from the service.

                                                                                                        Example 1

                                                                                                        const subscription = pubsub.subscription('my-subscription');
                                                                                                        const snapshot = subscription.snapshot('my-snapshot');
                                                                                                        const callback = (err, snapshot, apiResponse) => {
                                                                                                        if (!err) {
                                                                                                        // The snapshot was created successfully.
                                                                                                        }
                                                                                                        };
                                                                                                        snapshot.create('my-snapshot', callback);
                                                                                                        //-
                                                                                                        // If the callback is omitted, we'll return a Promise.
                                                                                                        //-
                                                                                                        snapshot.create('my-snapshot').then((data) => {
                                                                                                        const snapshot = data[0];
                                                                                                        const apiResponse = data[1];
                                                                                                        });

                                                                                                      method delete

                                                                                                      delete: {
                                                                                                      (): Promise<EmptyResponse>;
                                                                                                      (callback: NormalCallback<google.protobuf.IEmpty>): void;
                                                                                                      };
                                                                                                      • Delete the snapshot.

                                                                                                        Parameter callback

                                                                                                        The callback function.

                                                                                                        Parameter

                                                                                                        {?error} callback.err An error returned while making this request.

                                                                                                        Parameter

                                                                                                        {object} callback.apiResponse The full API response from the service.

                                                                                                        Example 1

                                                                                                        snapshot.delete((err, apiResponse) => {});
                                                                                                        //-
                                                                                                        // If the callback is omitted, we'll return a Promise.
                                                                                                        //-
                                                                                                        snapshot.delete().then((data) => {
                                                                                                        const apiResponse = data[0];
                                                                                                        });

                                                                                                      method formatName_

                                                                                                      static formatName_: (projectId: string, name: string) => string;

                                                                                                        method seek

                                                                                                        seek: {
                                                                                                        (gaxOpts?: CallOptions): Promise<SeekResponse>;
                                                                                                        (callback: NormalCallback<google.pubsub.v1.ISeekResponse>): void;
                                                                                                        (
                                                                                                        gaxOpts: CallOptions,
                                                                                                        callback: NormalCallback<google.pubsub.v1.ISeekResponse>
                                                                                                        ): void;
                                                                                                        };
                                                                                                        • Seeks an existing subscription to the snapshot.

                                                                                                          **This is only available if you accessed this object through Subscription#snapshot.**

                                                                                                          Snapshot#seek

                                                                                                          Parameter callback

                                                                                                          The callback function.

                                                                                                          Parameter

                                                                                                          {?error} callback.err An error from the API call, may be null.

                                                                                                          Parameter

                                                                                                          {object} callback.apiResponse The full API response from the service.

                                                                                                          Example 1

                                                                                                          const subscription = pubsub.subscription('my-subscription');
                                                                                                          const snapshot = subscription.snapshot('my-snapshot');
                                                                                                          snapshot.seek((err, apiResponse) => {});
                                                                                                          //-
                                                                                                          // If the callback is omitted, we'll return a Promise.
                                                                                                          //-
                                                                                                          snapshot.seek().then((data) => {
                                                                                                          const apiResponse = data[0];
                                                                                                          });

                                                                                                        class StatusError

                                                                                                        class StatusError extends Error implements grpc.ServiceError {}
                                                                                                        • Error wrapper for gRPC status objects.

                                                                                                          Parameter status

                                                                                                          The gRPC status object.

                                                                                                        constructor

                                                                                                        constructor(status: grpc.StatusObject);

                                                                                                          property code

                                                                                                          code: grpc.status;

                                                                                                            property details

                                                                                                            details: string;

                                                                                                              property metadata

                                                                                                              metadata: grpc.Metadata;

                                                                                                                class Subscription

                                                                                                                class Subscription extends EventEmitter {}
                                                                                                                • A Subscription object will give you access to your Cloud Pub/Sub subscription.

                                                                                                                  Subscriptions are sometimes retrieved when using various methods:

                                                                                                                  - PubSub#getSubscriptions - Topic#getSubscriptions

                                                                                                                  Subscription objects may be created directly with:

                                                                                                                  - PubSub#createSubscription - Topic#createSubscription

                                                                                                                  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 receipt of a (non-fatal) debug warning: on(event: 'debug', listener: (msg: DebugMessage) => void): this;

                                                                                                                  Upon the closing of the subscriber: on(event: 'close', listener: Function): this;

                                                                                                                  By default Subscription objects allow you to process 1000 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.

                                                                                                                  Parameter pubsub

                                                                                                                  PubSub object.

                                                                                                                  Parameter name

                                                                                                                  The name of the subscription.

                                                                                                                  Parameter options

                                                                                                                  Options for handling messages.

                                                                                                                  Example 1

                                                                                                                  From PubSub#getSubscriptions

                                                                                                                  const {PubSub} = require('@google-cloud/pubsub');
                                                                                                                  const pubsub = new PubSub();
                                                                                                                  pubsub.getSubscriptions((err, subscriptions) => {
                                                                                                                  // `subscriptions` is an array of Subscription objects.
                                                                                                                  });

                                                                                                                  Example 2

                                                                                                                  From Topic#getSubscriptions

                                                                                                                  const topic = pubsub.topic('my-topic');
                                                                                                                  topic.getSubscriptions((err, subscriptions) => {
                                                                                                                  // `subscriptions` is an array of Subscription objects.
                                                                                                                  });

                                                                                                                  Example 3

                                                                                                                  Topic#createSubscription

                                                                                                                  const topic = pubsub.topic('my-topic');
                                                                                                                  topic.createSubscription('new-subscription', (err, subscription) => {
                                                                                                                  // `subscription` is a Subscription object.
                                                                                                                  });

                                                                                                                  Example 4

                                                                                                                  Topic#subscription

                                                                                                                  const topic = pubsub.topic('my-topic');
                                                                                                                  const subscription = topic.subscription('my-subscription');
                                                                                                                  // `subscription` is a Subscription object.

                                                                                                                  Example 5

                                                                                                                  Once you have obtained a subscription object, you may begin to register listeners. This will automatically trigger pulling for messages.

                                                                                                                  // Register an error handler.
                                                                                                                  subscription.on('error', (err) => {});
                                                                                                                  // Register a debug handler, to catch non-fatal errors and other messages.
                                                                                                                  subscription.on('debug', msg => { console.log(msg.message); });
                                                                                                                  // Register a close handler in case the subscriber closes unexpectedly
                                                                                                                  subscription.on('close', () => {});
                                                                                                                  // Register a listener for `message` events.
                                                                                                                  function onMessage(message) {
                                                                                                                  // Called every time a message is received.
                                                                                                                  // message.id = ID of the message.
                                                                                                                  // message.ackId = ID used to acknowledge the message receival.
                                                                                                                  // message.data = Contents of the message.
                                                                                                                  // message.attributes = Attributes of the message.
                                                                                                                  // message.publishTime = Date when Pub/Sub received the message.
                                                                                                                  // Ack the message:
                                                                                                                  // message.ack();
                                                                                                                  // This doesn't ack the message, but allows more messages to be retrieved
                                                                                                                  // if your limit was hit or if you don't want to ack the message.
                                                                                                                  // message.nack();
                                                                                                                  }
                                                                                                                  subscription.on('message', onMessage);
                                                                                                                  // Remove the listener from receiving `message` events.
                                                                                                                  subscription.removeListener('message', onMessage);

                                                                                                                  Example 6

                                                                                                                  To apply a fine level of flow control, consider the following configuration

                                                                                                                  const subscription = topic.subscription('my-sub', {
                                                                                                                  flowControl: {
                                                                                                                  maxMessages: 1,
                                                                                                                  // this tells the client to manage and lock any excess messages
                                                                                                                  allowExcessMessages: false
                                                                                                                  }
                                                                                                                  });

                                                                                                                constructor

                                                                                                                constructor(pubsub: PubSub, name: string, options?: SubscriptionOptions);

                                                                                                                  property iam

                                                                                                                  iam: IAM;

                                                                                                                    property isOpen

                                                                                                                    readonly isOpen: boolean;
                                                                                                                    • Indicates if the Subscription is open and receiving messages.

                                                                                                                      {boolean}

                                                                                                                    property metadata

                                                                                                                    metadata?: google.pubsub.v1.ISubscription;

                                                                                                                      property name

                                                                                                                      readonly name: string;

                                                                                                                        property projectId

                                                                                                                        readonly projectId: string;
                                                                                                                        • {string}

                                                                                                                        property pubsub

                                                                                                                        pubsub: PubSub;

                                                                                                                          property request

                                                                                                                          request: <T, R = void>(
                                                                                                                          config: RequestConfig,
                                                                                                                          callback: RequestCallback<T, R>
                                                                                                                          ) => void;

                                                                                                                            property topic

                                                                                                                            topic?: string | Topic;

                                                                                                                              method close

                                                                                                                              close: { (): Promise<void>; (callback: SubscriptionCloseCallback): void };
                                                                                                                              • Closes the Subscription. Once this is called you will no longer receive message events unless you call {Subscription#open} or add new message listeners.

                                                                                                                                Parameter callback

                                                                                                                                The callback function, if not using the Promise-based call signature.

                                                                                                                                Parameter

                                                                                                                                {?error} [callback.err] An error returned while closing the Subscription.

                                                                                                                                Example 1

                                                                                                                                await subscription.close();

                                                                                                                              method create

                                                                                                                              create: {
                                                                                                                              (options?: CreateSubscriptionOptions): Promise<CreateSubscriptionResponse>;
                                                                                                                              (callback: SubscriptionCallback): void;
                                                                                                                              (options: CreateSubscriptionOptions, callback: SubscriptionCallback): void;
                                                                                                                              };
                                                                                                                              • Create a subscription.

                                                                                                                                Parameter name

                                                                                                                                The name of the subscription.

                                                                                                                                Parameter options

                                                                                                                                See a [Subscription resource](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions).

                                                                                                                                Parameter callback

                                                                                                                                Callback function.

                                                                                                                                Returns

                                                                                                                                {Promise}

                                                                                                                                Throws

                                                                                                                                {Error} If subscription name is omitted.

                                                                                                                                Example 1

                                                                                                                                const {PubSub} = require('@google-cloud/pubsub');
                                                                                                                                const pubsub = new PubSub();
                                                                                                                                const topic = pubsub.topic('my-topic');
                                                                                                                                const subscription = topic.subscription('newMessages');
                                                                                                                                const callback = function(err, subscription, apiResponse) {};
                                                                                                                                subscription.create(callback);

                                                                                                                                Example 2

                                                                                                                                With options

                                                                                                                                subscription.create({
                                                                                                                                ackDeadlineSeconds: 90
                                                                                                                                }, callback);

                                                                                                                                Example 3

                                                                                                                                If the callback is omitted, we'll return a Promise.

                                                                                                                                const [sub, apiResponse] = await subscription.create();

                                                                                                                                See Also

                                                                                                                              method createSnapshot

                                                                                                                              createSnapshot: {
                                                                                                                              (name: string, gaxOpts?: CallOptions): Promise<CreateSnapshotResponse>;
                                                                                                                              (name: string, callback: CreateSnapshotCallback): void;
                                                                                                                              (name: string, gaxOpts: CallOptions, callback: CreateSnapshotCallback): void;
                                                                                                                              };
                                                                                                                              • Create a snapshot with the given name.

                                                                                                                                Parameter name

                                                                                                                                Name of the snapshot.

                                                                                                                                Parameter gaxOpts

                                                                                                                                Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.

                                                                                                                                Parameter callback

                                                                                                                                Callback function.

                                                                                                                                Returns

                                                                                                                                {Promise}

                                                                                                                                Example 1

                                                                                                                                const {PubSub} = require('@google-cloud/pubsub');
                                                                                                                                const pubsub = new PubSub();
                                                                                                                                const topic = pubsub.topic('my-topic');
                                                                                                                                const subscription = topic.subscription('my-subscription');
                                                                                                                                const callback = (err, snapshot, apiResponse) => {
                                                                                                                                if (!err) {
                                                                                                                                // The snapshot was created successfully.
                                                                                                                                }
                                                                                                                                };
                                                                                                                                subscription.createSnapshot('my-snapshot', callback);
                                                                                                                                //-
                                                                                                                                // If the callback is omitted, we'll return a Promise.
                                                                                                                                //-
                                                                                                                                subscription.createSnapshot('my-snapshot').then((data) => {
                                                                                                                                const snapshot = data[0];
                                                                                                                                const apiResponse = data[1];
                                                                                                                                });

                                                                                                                              method delete

                                                                                                                              delete: {
                                                                                                                              (gaxOpts?: CallOptions): Promise<EmptyResponse>;
                                                                                                                              (callback: NormalCallback<google.protobuf.IEmpty>): void;
                                                                                                                              (
                                                                                                                              gaxOpts: CallOptions,
                                                                                                                              callback: NormalCallback<google.protobuf.IEmpty>
                                                                                                                              ): void;
                                                                                                                              };
                                                                                                                              • Delete the subscription. Pull requests from the current subscription will be errored once unsubscription is complete.

                                                                                                                                Parameter gaxOpts

                                                                                                                                Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.

                                                                                                                                Parameter callback

                                                                                                                                The callback function.

                                                                                                                                Parameter

                                                                                                                                {?error} callback.err An error returned while making this request.

                                                                                                                                Parameter

                                                                                                                                {object} callback.apiResponse Raw API response.

                                                                                                                                Example 1

                                                                                                                                const {PubSub} = require('@google-cloud/pubsub');
                                                                                                                                const pubsub = new PubSub();
                                                                                                                                const topic = pubsub.topic('my-topic');
                                                                                                                                const subscription = topic.subscription('my-subscription');
                                                                                                                                subscription.delete((err, apiResponse) => {});
                                                                                                                                //-
                                                                                                                                // If the callback is omitted, we'll return a Promise.
                                                                                                                                //-
                                                                                                                                subscription.delete().then((data) => {
                                                                                                                                const apiResponse = data[0];
                                                                                                                                });

                                                                                                                                See Also

                                                                                                                              method detached

                                                                                                                              detached: {
                                                                                                                              (): Promise<DetachedResponse>;
                                                                                                                              (callback: NormalCallback<boolean>): void;
                                                                                                                              };
                                                                                                                              • Check if a subscription is detached.

                                                                                                                                Parameter callback

                                                                                                                                Callback function.

                                                                                                                                Returns

                                                                                                                                {Promise}

                                                                                                                                Example 1

                                                                                                                                const {PubSub} = require('@google-cloud/pubsub');
                                                                                                                                const pubsub = new PubSub();
                                                                                                                                const topic = pubsub.topic('my-topic');
                                                                                                                                const subscription = topic.subscription('my-subscription');
                                                                                                                                subscription.detached((err, exists) => {});
                                                                                                                                //-
                                                                                                                                // If the callback is omitted, we'll return a Promise.
                                                                                                                                //-
                                                                                                                                subscription.detached().then((data) => {
                                                                                                                                const detached = data[0];
                                                                                                                                });

                                                                                                                              method exists

                                                                                                                              exists: {
                                                                                                                              (): Promise<ExistsResponse>;
                                                                                                                              (callback: NormalCallback<boolean>): void;
                                                                                                                              };
                                                                                                                              • Check if a subscription exists.

                                                                                                                                Parameter callback

                                                                                                                                Callback function.

                                                                                                                                Returns

                                                                                                                                {Promise}

                                                                                                                                Example 1

                                                                                                                                const {PubSub} = require('@google-cloud/pubsub');
                                                                                                                                const pubsub = new PubSub();
                                                                                                                                const topic = pubsub.topic('my-topic');
                                                                                                                                const subscription = topic.subscription('my-subscription');
                                                                                                                                subscription.exists((err, exists) => {});
                                                                                                                                //-
                                                                                                                                // If the callback is omitted, we'll return a Promise.
                                                                                                                                //-
                                                                                                                                subscription.exists().then((data) => {
                                                                                                                                const exists = data[0];
                                                                                                                                });

                                                                                                                              method formatMetadata_

                                                                                                                              static formatMetadata_: (
                                                                                                                              metadata: SubscriptionMetadata
                                                                                                                              ) => google.pubsub.v1.ISubscription;

                                                                                                                                method formatName_

                                                                                                                                static formatName_: (projectId: string, name: string) => string;

                                                                                                                                  method get

                                                                                                                                  get: {
                                                                                                                                  (gaxOpts?: GetSubscriptionOptions): Promise<GetSubscriptionResponse>;
                                                                                                                                  (callback: SubscriptionCallback): void;
                                                                                                                                  (gaxOpts: any, callback: SubscriptionCallback): void;
                                                                                                                                  };
                                                                                                                                  • Get a subscription if it exists.

                                                                                                                                    Parameter gaxOpts

                                                                                                                                    Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.

                                                                                                                                    Parameter

                                                                                                                                    {boolean} [gaxOpts.autoCreate=false] Automatically create the subscription if it does not already exist.

                                                                                                                                    Parameter callback

                                                                                                                                    Callback function.

                                                                                                                                    Returns

                                                                                                                                    {Promise}

                                                                                                                                    Example 1

                                                                                                                                    const {PubSub} = require('@google-cloud/pubsub');
                                                                                                                                    const pubsub = new PubSub();
                                                                                                                                    const topic = pubsub.topic('my-topic');
                                                                                                                                    const subscription = topic.subscription('my-subscription');
                                                                                                                                    subscription.get((err, subscription, apiResponse) => {
                                                                                                                                    // The `subscription` data has been populated.
                                                                                                                                    });
                                                                                                                                    //-
                                                                                                                                    // If the callback is omitted, we'll return a Promise.
                                                                                                                                    //-
                                                                                                                                    subscription.get().then((data) => {
                                                                                                                                    const subscription = data[0];
                                                                                                                                    const apiResponse = data[1];
                                                                                                                                    });

                                                                                                                                  method getMetadata

                                                                                                                                  getMetadata: {
                                                                                                                                  (gaxOpts?: CallOptions): Promise<GetSubscriptionMetadataResponse>;
                                                                                                                                  (callback: NormalCallback<google.pubsub.v1.ISubscription>): void;
                                                                                                                                  (
                                                                                                                                  gaxOpts: CallOptions,
                                                                                                                                  callback: NormalCallback<google.pubsub.v1.ISubscription>
                                                                                                                                  ): void;
                                                                                                                                  };
                                                                                                                                  • Fetches the subscriptions metadata.

                                                                                                                                    Parameter gaxOpts

                                                                                                                                    Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.

                                                                                                                                    Parameter callback

                                                                                                                                    Callback function.

                                                                                                                                    Returns

                                                                                                                                    {Promise}

                                                                                                                                    Example 1

                                                                                                                                    const {PubSub} = require('@google-cloud/pubsub');
                                                                                                                                    const pubsub = new PubSub();
                                                                                                                                    const topic = pubsub.topic('my-topic');
                                                                                                                                    const subscription = topic.subscription('my-subscription');
                                                                                                                                    subscription.getMetadata((err, apiResponse) => {
                                                                                                                                    if (err) {
                                                                                                                                    // Error handling omitted.
                                                                                                                                    }
                                                                                                                                    });
                                                                                                                                    //-
                                                                                                                                    // If the callback is omitted, we'll return a Promise.
                                                                                                                                    //-
                                                                                                                                    subscription.getMetadata().then((data) => {
                                                                                                                                    const apiResponse = data[0];
                                                                                                                                    });

                                                                                                                                  method modifyPushConfig

                                                                                                                                  modifyPushConfig: {
                                                                                                                                  (
                                                                                                                                  config: google.pubsub.v1.IPushConfig,
                                                                                                                                  gaxOpts?: CallOptions
                                                                                                                                  ): Promise<EmptyResponse>;
                                                                                                                                  (
                                                                                                                                  config: google.pubsub.v1.IPushConfig,
                                                                                                                                  callback: NormalCallback<google.protobuf.IEmpty>
                                                                                                                                  ): void;
                                                                                                                                  (
                                                                                                                                  config: google.pubsub.v1.IPushConfig,
                                                                                                                                  gaxOpts: CallOptions,
                                                                                                                                  callback: NormalCallback<google.protobuf.IEmpty>
                                                                                                                                  ): void;
                                                                                                                                  };
                                                                                                                                  • Modify the push config for the subscription.

                                                                                                                                    Parameter config

                                                                                                                                    The push config.

                                                                                                                                    Parameter

                                                                                                                                    {string} config.pushEndpoint A URL locating the endpoint to which messages should be published.

                                                                                                                                    Parameter

                                                                                                                                    {object} config.attributes [PushConfig attributes](https://cloud.google.com/pubsub/docs/reference/rpc/google.pubsub.v1#google.pubsub.v1.PushConfig).

                                                                                                                                    Parameter

                                                                                                                                    {object} config.oidcToken If specified, Pub/Sub will generate and attach an OIDC JWT token as an Authorization header in the HTTP request for every pushed message. This object should have the same structure as [OidcToken]google.pubsub.v1.OidcToken

                                                                                                                                    Parameter gaxOpts

                                                                                                                                    Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.

                                                                                                                                    Parameter callback

                                                                                                                                    Callback function.

                                                                                                                                    Returns

                                                                                                                                    {Promise}

                                                                                                                                    Example 1

                                                                                                                                    const {PubSub} = require('@google-cloud/pubsub');
                                                                                                                                    const pubsub = new PubSub();
                                                                                                                                    const topic = pubsub.topic('my-topic');
                                                                                                                                    const subscription = topic.subscription('my-subscription');
                                                                                                                                    const pushConfig = {
                                                                                                                                    pushEndpoint: 'https://mydomain.com/push',
                                                                                                                                    attributes: {
                                                                                                                                    key: 'value'
                                                                                                                                    },
                                                                                                                                    oidcToken: {
                                                                                                                                    serviceAccountEmail: 'myproject@appspot.gserviceaccount.com',
                                                                                                                                    audience: 'myaudience'
                                                                                                                                    }
                                                                                                                                    };
                                                                                                                                    subscription.modifyPushConfig(pushConfig, (err, apiResponse) => {
                                                                                                                                    if (err) {
                                                                                                                                    // Error handling omitted.
                                                                                                                                    }
                                                                                                                                    });
                                                                                                                                    //-
                                                                                                                                    // If the callback is omitted, we'll return a Promise.
                                                                                                                                    //-
                                                                                                                                    subscription.modifyPushConfig(pushConfig).then((data) => {
                                                                                                                                    const apiResponse = data[0];
                                                                                                                                    });

                                                                                                                                  method 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 Subscription#close. Alternatively one could just assign a new message event listener which will also re-open the Subscription.

                                                                                                                                    Example 1

                                                                                                                                    subscription.on('message', message => message.ack());
                                                                                                                                    // Close the subscription.
                                                                                                                                    subscription.close(err => {
                                                                                                                                    if (err) {
                                                                                                                                    // Error handling omitted.
                                                                                                                                    }
                                                                                                                                    The subscription has been closed and messages will no longer be received.
                                                                                                                                    });
                                                                                                                                    // Resume receiving messages.
                                                                                                                                    subscription.open();

                                                                                                                                  method seek

                                                                                                                                  seek: {
                                                                                                                                  (snapshot: string | Date, gaxOpts?: CallOptions): Promise<SeekResponse>;
                                                                                                                                  (
                                                                                                                                  snapshot: string | Date,
                                                                                                                                  callback: NormalCallback<google.pubsub.v1.ISeekResponse>
                                                                                                                                  ): void;
                                                                                                                                  (
                                                                                                                                  snapshot: string | Date,
                                                                                                                                  gaxOpts: CallOptions,
                                                                                                                                  callback: NormalCallback<google.pubsub.v1.ISeekResponse>
                                                                                                                                  ): void;
                                                                                                                                  };
                                                                                                                                  • Seeks an existing subscription to a point in time or a given snapshot.

                                                                                                                                    Parameter snapshot

                                                                                                                                    The point to seek to. This will accept the name of the snapshot or a Date object.

                                                                                                                                    Parameter gaxOpts

                                                                                                                                    Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.

                                                                                                                                    Parameter callback

                                                                                                                                    Callback function.

                                                                                                                                    Returns

                                                                                                                                    {Promise}

                                                                                                                                    Example 1

                                                                                                                                    const callback = (err, resp) => {
                                                                                                                                    if (!err) {
                                                                                                                                    // Seek was successful.
                                                                                                                                    }
                                                                                                                                    };
                                                                                                                                    subscription.seek('my-snapshot', callback);
                                                                                                                                    //-
                                                                                                                                    // Alternatively, to specify a certain point in time, you can provide a
                                                                                                                                    Date
                                                                                                                                    // object.
                                                                                                                                    //-
                                                                                                                                    const date = new Date('October 21 2015');
                                                                                                                                    subscription.seek(date, callback);

                                                                                                                                  method setMetadata

                                                                                                                                  setMetadata: {
                                                                                                                                  (
                                                                                                                                  metadata: SubscriptionMetadata,
                                                                                                                                  gaxOpts?: CallOptions
                                                                                                                                  ): Promise<SetSubscriptionMetadataResponse>;
                                                                                                                                  (
                                                                                                                                  metadata: SubscriptionMetadata,
                                                                                                                                  callback: NormalCallback<google.pubsub.v1.ISubscription>
                                                                                                                                  ): void;
                                                                                                                                  (
                                                                                                                                  metadata: SubscriptionMetadata,
                                                                                                                                  gaxOpts: CallOptions,
                                                                                                                                  callback: NormalCallback<google.pubsub.v1.ISubscription>
                                                                                                                                  ): void;
                                                                                                                                  };
                                                                                                                                  • Update the subscription object.

                                                                                                                                    Parameter metadata

                                                                                                                                    The subscription metadata.

                                                                                                                                    Parameter gaxOpts

                                                                                                                                    Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.

                                                                                                                                    Parameter callback

                                                                                                                                    Callback function.

                                                                                                                                    Returns

                                                                                                                                    {Promise}

                                                                                                                                    Example 1

                                                                                                                                    const metadata = {
                                                                                                                                    key: 'value'
                                                                                                                                    };
                                                                                                                                    subscription.setMetadata(metadata, (err, apiResponse) => {
                                                                                                                                    if (err) {
                                                                                                                                    // Error handling omitted.
                                                                                                                                    }
                                                                                                                                    });
                                                                                                                                    //-
                                                                                                                                    // If the callback is omitted, we'll return a Promise.
                                                                                                                                    //-
                                                                                                                                    subscription.setMetadata(metadata).then((data) => {
                                                                                                                                    const apiResponse = data[0];
                                                                                                                                    });

                                                                                                                                  method setOptions

                                                                                                                                  setOptions: (options: SubscriberOptions) => void;
                                                                                                                                  • Sets the Subscription options.

                                                                                                                                    Parameter options

                                                                                                                                    The options.

                                                                                                                                  method snapshot

                                                                                                                                  snapshot: (name: string) => Snapshot;
                                                                                                                                  • Create a Snapshot object. See Subscription#createSnapshot to create a snapshot.

                                                                                                                                    Parameter name

                                                                                                                                    The name of the snapshot.

                                                                                                                                    Returns

                                                                                                                                    {Snapshot}

                                                                                                                                    Throws

                                                                                                                                    {Error} If a name is not provided.

                                                                                                                                    Example 1

                                                                                                                                    const snapshot = subscription.snapshot('my-snapshot');

                                                                                                                                  class Topic

                                                                                                                                  class Topic {}
                                                                                                                                  • A Topic object allows you to interact with a Cloud Pub/Sub topic.

                                                                                                                                    Parameter pubsub

                                                                                                                                    PubSub object.

                                                                                                                                    Parameter name

                                                                                                                                    Name of the topic.

                                                                                                                                    Parameter options

                                                                                                                                    Publisher configuration object.

                                                                                                                                    Example 1

                                                                                                                                    const {PubSub} = require('@google-cloud/pubsub');
                                                                                                                                    const pubsub = new PubSub();
                                                                                                                                    const topic = pubsub.topic('my-topic');

                                                                                                                                    Example 2

                                                                                                                                    To enable message ordering, set enableMessageOrdering to true. Please note that this does not persist to an actual topic.

                                                                                                                                    const topic = pubsub.topic('ordered-topic', {enableMessageOrdering: true});

                                                                                                                                  constructor

                                                                                                                                  constructor(pubsub: PubSub, name: string, options?: PublishOptions);

                                                                                                                                    property getSubscriptionsStream

                                                                                                                                    getSubscriptionsStream: () => ObjectStream<Subscription>;

                                                                                                                                      property iam

                                                                                                                                      iam: IAM;

                                                                                                                                        property metadata

                                                                                                                                        metadata?: google.pubsub.v1.ITopic;

                                                                                                                                          property name

                                                                                                                                          readonly name: string;

                                                                                                                                            property parent

                                                                                                                                            parent: PubSub;

                                                                                                                                              property publisher

                                                                                                                                              publisher: Publisher;

                                                                                                                                                property pubsub

                                                                                                                                                pubsub: PubSub;

                                                                                                                                                  property request

                                                                                                                                                  request: <T, R = void>(
                                                                                                                                                  config: RequestConfig,
                                                                                                                                                  callback: RequestCallback<T, R>
                                                                                                                                                  ) => void;

                                                                                                                                                    method create

                                                                                                                                                    create: {
                                                                                                                                                    (gaxOpts?: CallOptions): Promise<CreateTopicResponse>;
                                                                                                                                                    (callback: TopicCallback): void;
                                                                                                                                                    (gaxOpts: CallOptions, callback: TopicCallback): void;
                                                                                                                                                    };
                                                                                                                                                    • Create a topic.

                                                                                                                                                      Parameter gaxOpts

                                                                                                                                                      Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.

                                                                                                                                                      Parameter callback

                                                                                                                                                      Callback function.

                                                                                                                                                      Returns

                                                                                                                                                      {Promise}

                                                                                                                                                      Example 1

                                                                                                                                                      const {PubSub} = require('@google-cloud/pubsub');
                                                                                                                                                      const pubsub = new PubSub();
                                                                                                                                                      const topic = pubsub.topic('my-topic');
                                                                                                                                                      topic.create((err, topic, apiResponse) => {
                                                                                                                                                      if (!err) {
                                                                                                                                                      // The topic was created successfully.
                                                                                                                                                      }
                                                                                                                                                      });
                                                                                                                                                      //-
                                                                                                                                                      // If the callback is omitted, we'll return a Promise.
                                                                                                                                                      //-
                                                                                                                                                      topic.create().then((data) => {
                                                                                                                                                      const topic = data[0];
                                                                                                                                                      const apiResponse = data[1];
                                                                                                                                                      });

                                                                                                                                                    method createSubscription

                                                                                                                                                    createSubscription: {
                                                                                                                                                    (name: string, callback: SubscriptionCallback): void;
                                                                                                                                                    (
                                                                                                                                                    name: string,
                                                                                                                                                    options?: CreateSubscriptionOptions
                                                                                                                                                    ): Promise<SubscriptionResponse>;
                                                                                                                                                    (
                                                                                                                                                    name: string,
                                                                                                                                                    options: CreateSubscriptionOptions,
                                                                                                                                                    callback: SubscriptionCallback
                                                                                                                                                    ): void;
                                                                                                                                                    };
                                                                                                                                                    • Create a subscription to this topic.

                                                                                                                                                      Parameter name

                                                                                                                                                      The name of the subscription.

                                                                                                                                                      Parameter options

                                                                                                                                                      See a [Subscription resource](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions).

                                                                                                                                                      Parameter callback

                                                                                                                                                      Callback function.

                                                                                                                                                      Returns

                                                                                                                                                      {Promise}

                                                                                                                                                      Throws

                                                                                                                                                      {Error} If subscription name is omitted.

                                                                                                                                                      Example 1

                                                                                                                                                      const {PubSub} = require('@google-cloud/pubsub');
                                                                                                                                                      const pubsub = new PubSub();
                                                                                                                                                      const topic = pubsub.topic('my-topic');
                                                                                                                                                      const callback = function(err, subscription, apiResponse) {};
                                                                                                                                                      // Without specifying any options.
                                                                                                                                                      topic.createSubscription('newMessages', callback);
                                                                                                                                                      // With options.
                                                                                                                                                      topic.createSubscription('newMessages', {
                                                                                                                                                      ackDeadlineSeconds: 90
                                                                                                                                                      }, callback);
                                                                                                                                                      //-
                                                                                                                                                      // If the callback is omitted, we'll return a Promise.
                                                                                                                                                      //-
                                                                                                                                                      topic.createSubscription('newMessages').then((data) => {
                                                                                                                                                      const subscription = data[0];
                                                                                                                                                      const apiResponse = data[1];
                                                                                                                                                      });

                                                                                                                                                      See Also

                                                                                                                                                    method delete

                                                                                                                                                    delete: {
                                                                                                                                                    (callback: NormalCallback<google.protobuf.IEmpty>): void;
                                                                                                                                                    (gaxOpts?: CallOptions): Promise<EmptyResponse>;
                                                                                                                                                    (
                                                                                                                                                    gaxOpts: CallOptions,
                                                                                                                                                    callback: NormalCallback<google.protobuf.IEmpty>
                                                                                                                                                    ): void;
                                                                                                                                                    };
                                                                                                                                                    • Delete the topic. This will not delete subscriptions to this topic.

                                                                                                                                                      Parameter gaxOpts

                                                                                                                                                      Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.

                                                                                                                                                      Parameter callback

                                                                                                                                                      The callback function.

                                                                                                                                                      Parameter

                                                                                                                                                      {?error} callback.err An error returned while making this request.

                                                                                                                                                      Parameter

                                                                                                                                                      {object} callback.apiResponse Raw API response.

                                                                                                                                                      Example 1

                                                                                                                                                      const {PubSub} = require('@google-cloud/pubsub');
                                                                                                                                                      const pubsub = new PubSub();
                                                                                                                                                      const topic = pubsub.topic('my-topic');
                                                                                                                                                      topic.delete((err, apiResponse) => {});
                                                                                                                                                      //-
                                                                                                                                                      // If the callback is omitted, we'll return a Promise.
                                                                                                                                                      //-
                                                                                                                                                      topic.delete().then((data) => {
                                                                                                                                                      const apiResponse = data[0];
                                                                                                                                                      });

                                                                                                                                                      See Also

                                                                                                                                                    method exists

                                                                                                                                                    exists: {
                                                                                                                                                    (): Promise<ExistsResponse>;
                                                                                                                                                    (callback: NormalCallback<boolean>): void;
                                                                                                                                                    };
                                                                                                                                                    • Check if a topic exists.

                                                                                                                                                      Parameter callback

                                                                                                                                                      Callback function.

                                                                                                                                                      Returns

                                                                                                                                                      {Promise}

                                                                                                                                                      Example 1

                                                                                                                                                      const {PubSub} = require('@google-cloud/pubsub');
                                                                                                                                                      const pubsub = new PubSub();
                                                                                                                                                      const topic = pubsub.topic('my-topic');
                                                                                                                                                      topic.exists((err, exists) => {});
                                                                                                                                                      //-
                                                                                                                                                      // If the callback is omitted, we'll return a Promise.
                                                                                                                                                      //-
                                                                                                                                                      topic.exists().then((data) => {
                                                                                                                                                      const exists = data[0];
                                                                                                                                                      });

                                                                                                                                                    method flowControlled

                                                                                                                                                    flowControlled: () => FlowControlledPublisher;
                                                                                                                                                    • Creates a FlowControlledPublisher for this Topic.

                                                                                                                                                      FlowControlledPublisher is a helper that lets you control how many messages are simultaneously queued to send, to avoid ballooning memory usage on a low bandwidth connection to Pub/Sub.

                                                                                                                                                      Note that it's perfectly fine to create more than one on the same Topic. The actual flow control settings on the Topic will apply across all FlowControlledPublisher objects on that Topic.

                                                                                                                                                      Returns

                                                                                                                                                      {FlowControlledPublisher} The flow control helper.

                                                                                                                                                    method flush

                                                                                                                                                    flush: {
                                                                                                                                                    (): Promise<void>;
                                                                                                                                                    (callback: NormalCallback<google.protobuf.IEmpty>): void;
                                                                                                                                                    };
                                                                                                                                                    • Immediately sends all remaining queued data. This is mostly useful if you are planning to call close() on the PubSub object that holds the server connections.

                                                                                                                                                      Parameter callback

                                                                                                                                                      Callback function.

                                                                                                                                                      Returns

                                                                                                                                                      {Promise}

                                                                                                                                                    method formatName_

                                                                                                                                                    static formatName_: (projectId: string, name: string) => string;
                                                                                                                                                    • Format the name of a topic. A Topic's full name is in the format of 'projects/{projectId}/topics/{topicName}'.

                                                                                                                                                      {string}

                                                                                                                                                    method get

                                                                                                                                                    get: {
                                                                                                                                                    (callback: TopicCallback): void;
                                                                                                                                                    (gaxOpts?: any): Promise<TopicResponse>;
                                                                                                                                                    (gaxOpts: any, callback: TopicCallback): void;
                                                                                                                                                    };
                                                                                                                                                    • Get a topic if it exists.

                                                                                                                                                      Parameter gaxOpts

                                                                                                                                                      Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.

                                                                                                                                                      Parameter

                                                                                                                                                      {boolean} [gaxOpts.autoCreate=false] Automatically create the topic does not already exist.

                                                                                                                                                      Parameter callback

                                                                                                                                                      Callback function.

                                                                                                                                                      Returns

                                                                                                                                                      {Promise}

                                                                                                                                                      Example 1

                                                                                                                                                      const {PubSub} = require('@google-cloud/pubsub');
                                                                                                                                                      const pubsub = new PubSub();
                                                                                                                                                      const topic = pubsub.topic('my-topic');
                                                                                                                                                      topic.get((err, topic, apiResponse) => {
                                                                                                                                                      // The `topic` data has been populated.
                                                                                                                                                      });
                                                                                                                                                      //-
                                                                                                                                                      // If the callback is omitted, we'll return a Promise.
                                                                                                                                                      //-
                                                                                                                                                      topic.get().then((data) => {
                                                                                                                                                      const topic = data[0];
                                                                                                                                                      const apiResponse = data[1];
                                                                                                                                                      });

                                                                                                                                                    method getMetadata

                                                                                                                                                    getMetadata: {
                                                                                                                                                    (callback: NormalCallback<google.pubsub.v1.ITopic>): void;
                                                                                                                                                    (
                                                                                                                                                    gaxOpts: CallOptions,
                                                                                                                                                    callback: NormalCallback<google.pubsub.v1.ITopic>
                                                                                                                                                    ): void;
                                                                                                                                                    (gaxOpts?: CallOptions): Promise<MetadataResponse>;
                                                                                                                                                    };
                                                                                                                                                    • Get the official representation of this topic from the API.

                                                                                                                                                      Parameter gaxOpts

                                                                                                                                                      Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.

                                                                                                                                                      Parameter callback

                                                                                                                                                      Callback function.

                                                                                                                                                      Returns

                                                                                                                                                      {Promise}

                                                                                                                                                      Example 1

                                                                                                                                                      const {PubSub} = require('@google-cloud/pubsub');
                                                                                                                                                      const pubsub = new PubSub();
                                                                                                                                                      const topic = pubsub.topic('my-topic');
                                                                                                                                                      topic.getMetadata((err, apiResponse) => {});
                                                                                                                                                      //-
                                                                                                                                                      // If the callback is omitted, we'll return a Promise.
                                                                                                                                                      //-
                                                                                                                                                      topic.getMetadata().then((data) => {
                                                                                                                                                      const apiResponse = data[0];
                                                                                                                                                      });

                                                                                                                                                      See Also

                                                                                                                                                    method getPublishOptionDefaults

                                                                                                                                                    getPublishOptionDefaults: () => PublishOptions;
                                                                                                                                                    • Get the default publisher options. These may be modified and passed back into Topic#setPublishOptions.

                                                                                                                                                      Example 1

                                                                                                                                                      const {PubSub} = require('@google-cloud/pubsub');
                                                                                                                                                      const pubsub = new PubSub();
                                                                                                                                                      const topic = pubsub.topic('my-topic');
                                                                                                                                                      const defaults = topic.getPublishOptionDefaults();
                                                                                                                                                      defaults.batching.maxMilliseconds = 10;
                                                                                                                                                      topic.setPublishOptions(defaults);

                                                                                                                                                    method getSubscriptions

                                                                                                                                                    getSubscriptions: {
                                                                                                                                                    (callback: GetTopicSubscriptionsCallback): void;
                                                                                                                                                    (
                                                                                                                                                    options: PageOptions,
                                                                                                                                                    callback:
                                                                                                                                                    | NormalCallback<Subscription>
                                                                                                                                                    | PagedCallback<
                                                                                                                                                    Subscription,
                                                                                                                                                    google.pubsub.v1.IListTopicSubscriptionsResponse
                                                                                                                                                    >
                                                                                                                                                    ): void;
                                                                                                                                                    (options?: PageOptions): Promise<GetTopicSubscriptionsResponse>;
                                                                                                                                                    };
                                                                                                                                                    • Get a list of the subscriptions registered to this topic. You may optionally provide a query object as the first argument to customize the response.

                                                                                                                                                      Your provided callback will be invoked with an error object if an API error occurred or an array of {module:pubsub/subscription} objects.

                                                                                                                                                      Parameter query

                                                                                                                                                      Query object for listing subscriptions.

                                                                                                                                                      Parameter callback

                                                                                                                                                      Callback function.

                                                                                                                                                      Returns

                                                                                                                                                      {Promise}

                                                                                                                                                      Example 1

                                                                                                                                                      const {PubSub} = require('@google-cloud/pubsub');
                                                                                                                                                      const pubsub = new PubSub();
                                                                                                                                                      const topic = pubsub.topic('my-topic');
                                                                                                                                                      topic.getSubscriptions((err, subscriptions) => {
                                                                                                                                                      // subscriptions is an array of `Subscription` objects.
                                                                                                                                                      });
                                                                                                                                                      // Customize the query.
                                                                                                                                                      topic.getSubscriptions({
                                                                                                                                                      pageSize: 3
                                                                                                                                                      }, callback);
                                                                                                                                                      //-
                                                                                                                                                      // If the callback is omitted, we'll return a Promise.
                                                                                                                                                      //-
                                                                                                                                                      topic.getSubscriptions().then((data) => {
                                                                                                                                                      const subscriptions = data[0];
                                                                                                                                                      });

                                                                                                                                                      See Also

                                                                                                                                                    method publish

                                                                                                                                                    publish: {
                                                                                                                                                    (data: Buffer, attributes?: Attributes): Promise<string>;
                                                                                                                                                    (data: Buffer, callback: NormalCallback<string>): void;
                                                                                                                                                    (
                                                                                                                                                    data: Buffer,
                                                                                                                                                    attributes: Attributes,
                                                                                                                                                    callback: NormalCallback<string>
                                                                                                                                                    ): void;
                                                                                                                                                    };
                                                                                                                                                    • Publish the provided message.

                                                                                                                                                      Parameter data

                                                                                                                                                      The message data. This must come in the form of a Buffer object.

                                                                                                                                                      Parameter attributes

                                                                                                                                                      Attributes for this message.

                                                                                                                                                      Parameter callback

                                                                                                                                                      Callback function.

                                                                                                                                                      Returns

                                                                                                                                                      {Promise}

                                                                                                                                                      Throws

                                                                                                                                                      {TypeError} If data is not a Buffer object.

                                                                                                                                                      Throws

                                                                                                                                                      {TypeError} If any value in attributes object is not a string.

                                                                                                                                                      Example 1

                                                                                                                                                      const {PubSub} = require('@google-cloud/pubsub');
                                                                                                                                                      const pubsub = new PubSub();
                                                                                                                                                      const topic = pubsub.topic('my-topic');
                                                                                                                                                      const data = Buffer.from('Hello, world!');
                                                                                                                                                      const callback = (err, messageId) => {
                                                                                                                                                      if (err) {
                                                                                                                                                      // Error handling omitted.
                                                                                                                                                      }
                                                                                                                                                      };
                                                                                                                                                      topic.publish(data, callback);

                                                                                                                                                      Example 2

                                                                                                                                                      Optionally you can provide an object containing attributes for the message. Note that all values in the object must be strings.

                                                                                                                                                      const attributes = {
                                                                                                                                                      key: 'value'
                                                                                                                                                      };
                                                                                                                                                      topic.publish(data, attributes, callback);

                                                                                                                                                      Example 3

                                                                                                                                                      If the callback is omitted, we'll return a Promise.

                                                                                                                                                      topic.publish(data).then((messageId) => {});

                                                                                                                                                      Deprecated

                                                                                                                                                      Please use Topic#publishMessage.

                                                                                                                                                    method publishJSON

                                                                                                                                                    publishJSON: {
                                                                                                                                                    (json: object, attributes?: Attributes): Promise<string>;
                                                                                                                                                    (json: object, callback: NormalCallback<string>): void;
                                                                                                                                                    (
                                                                                                                                                    json: object,
                                                                                                                                                    attributes: Attributes,
                                                                                                                                                    callback: NormalCallback<string>
                                                                                                                                                    ): void;
                                                                                                                                                    };
                                                                                                                                                    • Publish the provided JSON. It should be noted that all messages published are done so in the form of a Buffer. This is simply a convenience method that will transform JSON into a Buffer before publishing. Subscription objects will always return message data in the form of a Buffer, so any JSON published will require manual deserialization.

                                                                                                                                                      Parameter json

                                                                                                                                                      The JSON data to publish.

                                                                                                                                                      Parameter attributes

                                                                                                                                                      Attributes for this message.

                                                                                                                                                      Parameter callback

                                                                                                                                                      Callback function.

                                                                                                                                                      Returns

                                                                                                                                                      {Promise}

                                                                                                                                                      Throws

                                                                                                                                                      {Error} If non-object data is provided.

                                                                                                                                                      Example 1

                                                                                                                                                      const {PubSub} = require('@google-cloud/pubsub');
                                                                                                                                                      const pubsub = new PubSub();
                                                                                                                                                      const topic = pubsub.topic('my-topic');
                                                                                                                                                      const data = {
                                                                                                                                                      foo: 'bar'
                                                                                                                                                      };
                                                                                                                                                      const callback = (err, messageId) => {
                                                                                                                                                      if (err) {
                                                                                                                                                      // Error handling omitted.
                                                                                                                                                      }
                                                                                                                                                      };
                                                                                                                                                      topic.publishJSON(data, callback);

                                                                                                                                                      Example 2

                                                                                                                                                      Optionally you can provide an object containing attributes for the message. Note that all values in the object must be strings.

                                                                                                                                                      const attributes = {
                                                                                                                                                      key: 'value'
                                                                                                                                                      };
                                                                                                                                                      topic.publishJSON(data, attributes, callback);

                                                                                                                                                      Example 3

                                                                                                                                                      If the callback is omitted, we'll return a Promise.

                                                                                                                                                      topic.publishJSON(data).then((messageId) => {});

                                                                                                                                                      Deprecated

                                                                                                                                                      Please use the json option via Topic#publishMessage.

                                                                                                                                                    method publishMessage

                                                                                                                                                    publishMessage: {
                                                                                                                                                    (message: MessageOptions): Promise<string>;
                                                                                                                                                    (message: MessageOptions, callback: NormalCallback<string>): void;
                                                                                                                                                    };
                                                                                                                                                    • Publish the provided message.

                                                                                                                                                      Parameter message

                                                                                                                                                      Message object.

                                                                                                                                                      Parameter callback

                                                                                                                                                      Callback function.

                                                                                                                                                      Returns

                                                                                                                                                      {Promise}

                                                                                                                                                      Throws

                                                                                                                                                      {TypeError} If data is not a Buffer object.

                                                                                                                                                      Throws

                                                                                                                                                      {TypeError} If any value in attributes object is not a string.

                                                                                                                                                      Example 1

                                                                                                                                                      const {PubSub} = require('@google-cloud/pubsub');
                                                                                                                                                      const pubsub = new PubSub();
                                                                                                                                                      const topic = pubsub.topic('my-topic');
                                                                                                                                                      const data = Buffer.from('Hello, world!');
                                                                                                                                                      const callback = (err, messageId) => {
                                                                                                                                                      if (err) {
                                                                                                                                                      // Error handling omitted.
                                                                                                                                                      }
                                                                                                                                                      };
                                                                                                                                                      topic.publishMessage({data}, callback);

                                                                                                                                                      Example 2

                                                                                                                                                      Publish JSON message data.

                                                                                                                                                      const json = {foo: 'bar'};
                                                                                                                                                      topic.publishMessage({json}, callback);

                                                                                                                                                      Example 3

                                                                                                                                                      To publish messages in order (this is still experimental), make sure message ordering is enabled and provide an ordering key

                                                                                                                                                      const topic = pubsub.topic('ordered-topic', {messageOrdering: true});
                                                                                                                                                      const orderingKey = 'my-key';
                                                                                                                                                      topic.publishMessage({data, orderingKey}, callback);

                                                                                                                                                      Example 4

                                                                                                                                                      If the callback is omitted, we'll return a Promise.

                                                                                                                                                      const messageId = await topic.publishMessage({data});

                                                                                                                                                    method resumePublishing

                                                                                                                                                    resumePublishing: (orderingKey: string) => void;
                                                                                                                                                    • In the event that the client fails to publish an ordered message, all subsequent publish calls using the same ordering key will fail. Calling this method will disregard the publish failure, allowing the supplied ordering key to be used again in the future.

                                                                                                                                                      Parameter orderingKey

                                                                                                                                                      The ordering key in question.

                                                                                                                                                      Example 1

                                                                                                                                                      const {PubSub} = require('@google-cloud/pubsub');
                                                                                                                                                      const pubsub = new PubSub();
                                                                                                                                                      const topic = pubsub.topic('my-topic', {messageOrdering: true});
                                                                                                                                                      const orderingKey = 'foo';
                                                                                                                                                      const data = Buffer.from('Hello, order!');
                                                                                                                                                      topic.publishMessage({data, orderingKey}, err => {
                                                                                                                                                      if (err) {
                                                                                                                                                      topic.resumePublishing(orderingKey);
                                                                                                                                                      }
                                                                                                                                                      });

                                                                                                                                                    method setMetadata

                                                                                                                                                    setMetadata: {
                                                                                                                                                    (
                                                                                                                                                    options: google.pubsub.v1.ITopic,
                                                                                                                                                    gaxOpts?: CallOptions
                                                                                                                                                    ): Promise<SetTopicMetadataResponse>;
                                                                                                                                                    (
                                                                                                                                                    options: google.pubsub.v1.ITopic,
                                                                                                                                                    callback: NormalCallback<google.pubsub.v1.ITopic>
                                                                                                                                                    ): void;
                                                                                                                                                    (
                                                                                                                                                    options: google.pubsub.v1.ITopic,
                                                                                                                                                    gaxOpts: CallOptions,
                                                                                                                                                    callback: NormalCallback<google.pubsub.v1.ITopic>
                                                                                                                                                    ): void;
                                                                                                                                                    };
                                                                                                                                                    • Updates the topic.

                                                                                                                                                      Parameter metadata

                                                                                                                                                      The fields to update. This should be structured like a Topic object.

                                                                                                                                                      Parameter gaxOpts

                                                                                                                                                      Request configuration options, outlined here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.

                                                                                                                                                      Parameter callback

                                                                                                                                                      Callback function.

                                                                                                                                                      Returns

                                                                                                                                                      {Promise}

                                                                                                                                                      Example 1

                                                                                                                                                      const {PubSub} = require('@google-cloud/pubsub');
                                                                                                                                                      const pubsub = new PubSub();
                                                                                                                                                      const topic = pubsub.topic('my-topic');
                                                                                                                                                      const metadata = {
                                                                                                                                                      labels: {foo: 'bar'}
                                                                                                                                                      };
                                                                                                                                                      topic.setMetadata(metadata, err => {
                                                                                                                                                      if (err) {
                                                                                                                                                      // Error handling omitted.
                                                                                                                                                      }
                                                                                                                                                      });

                                                                                                                                                      Example 2

                                                                                                                                                      If the callback is omitted, we'll return a Promise.

                                                                                                                                                      topic.setMetadata(metadata).then((data) => {
                                                                                                                                                      const apiResponse = data[0];
                                                                                                                                                      });

                                                                                                                                                      See Also

                                                                                                                                                    method setPublishOptions

                                                                                                                                                    setPublishOptions: (options: PublishOptions) => void;
                                                                                                                                                    • Set the publisher options.

                                                                                                                                                      Parameter options

                                                                                                                                                      The publisher options.

                                                                                                                                                      Example 1

                                                                                                                                                      const {PubSub} = require('@google-cloud/pubsub');
                                                                                                                                                      const pubsub = new PubSub();
                                                                                                                                                      const topic = pubsub.topic('my-topic');
                                                                                                                                                      topic.setPublishOptions({
                                                                                                                                                      batching: {
                                                                                                                                                      maxMilliseconds: 10
                                                                                                                                                      }
                                                                                                                                                      });

                                                                                                                                                    method subscription

                                                                                                                                                    subscription: (name: string, options?: SubscriptionOptions) => Subscription;
                                                                                                                                                    • Create a Subscription object. This command by itself will not run any API requests. You will receive a {module:pubsub/subscription} object, which will allow you to interact with a subscription.

                                                                                                                                                      Parameter name

                                                                                                                                                      Name of the subscription.

                                                                                                                                                      Parameter options

                                                                                                                                                      Configuration object. {Subscription}

                                                                                                                                                      Throws

                                                                                                                                                      {Error} If subscription name is omitted.

                                                                                                                                                      Example 1

                                                                                                                                                      const {PubSub} = require('@google-cloud/pubsub');
                                                                                                                                                      const pubsub = new PubSub();
                                                                                                                                                      const topic = pubsub.topic('my-topic');
                                                                                                                                                      const subscription = topic.subscription('my-subscription');
                                                                                                                                                      // Register a listener for `message` events.
                                                                                                                                                      subscription.on('message', (message) => {
                                                                                                                                                      // Called every time a message is received.
                                                                                                                                                      // message.id = ID of the message.
                                                                                                                                                      // message.ackId = ID used to acknowledge the message receival.
                                                                                                                                                      // message.data = Contents of the message.
                                                                                                                                                      // message.attributes = Attributes of the message.
                                                                                                                                                      // message.publishTime = Timestamp when Pub/Sub received the message.
                                                                                                                                                      });

                                                                                                                                                    Interfaces

                                                                                                                                                    interface BatchPublishOptions

                                                                                                                                                    interface BatchPublishOptions {}

                                                                                                                                                      property maxBytes

                                                                                                                                                      maxBytes?: number;

                                                                                                                                                        property maxMessages

                                                                                                                                                        maxMessages?: number;

                                                                                                                                                          property maxMilliseconds

                                                                                                                                                          maxMilliseconds?: number;

                                                                                                                                                            interface ClientConfig

                                                                                                                                                            interface ClientConfig extends Omit<gax.GrpcClientOptions, 'port'> {}

                                                                                                                                                              property apiEndpoint

                                                                                                                                                              apiEndpoint?: string;

                                                                                                                                                                property emulatorMode

                                                                                                                                                                emulatorMode?: boolean;
                                                                                                                                                                • Configures the emulator mode behaviour: - If false, disable emulator mode always - If true, enable emulator mode always - If unset, use heuristics to decide Emulator mode notably sets insecure SSL authentication so that you can try the library out without needing a cert.

                                                                                                                                                                  Also notably, if a TPC universeDomain is set, then this will be counted as !emulatorMode for the purposes of the heuristics. If you want emulator mode but with a TPC universe domain set, set this to true as well.

                                                                                                                                                                property enableOpenTelemetryTracing

                                                                                                                                                                enableOpenTelemetryTracing?: boolean;
                                                                                                                                                                • Enables OpenTelemetry tracing (newer, more full implementation). This defaults to false/undefined

                                                                                                                                                                property port

                                                                                                                                                                port?: string | number;

                                                                                                                                                                  property servicePath

                                                                                                                                                                  servicePath?: string;

                                                                                                                                                                    property sslCreds

                                                                                                                                                                    sslCreds?: gax.grpc.ChannelCredentials;

                                                                                                                                                                      interface DurationLike

                                                                                                                                                                      interface DurationLike {}
                                                                                                                                                                      • Simplified interface analogous to the tc39 Temporal.Duration parameter to from(). This doesn't support the full gamut (years, days).

                                                                                                                                                                      property hours

                                                                                                                                                                      hours?: number;

                                                                                                                                                                        property millis

                                                                                                                                                                        millis?: number;
                                                                                                                                                                        • tc39 has renamed this to milliseconds.

                                                                                                                                                                          Deprecated

                                                                                                                                                                        property milliseconds

                                                                                                                                                                        milliseconds?: number;

                                                                                                                                                                          property minutes

                                                                                                                                                                          minutes?: number;

                                                                                                                                                                            property seconds

                                                                                                                                                                            seconds?: number;

                                                                                                                                                                              interface FlowControlOptions

                                                                                                                                                                              interface FlowControlOptions {}
                                                                                                                                                                              • 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.

                                                                                                                                                                              property maxOutstandingBytes

                                                                                                                                                                              maxOutstandingBytes?: number;

                                                                                                                                                                                property maxOutstandingMessages

                                                                                                                                                                                maxOutstandingMessages?: number;

                                                                                                                                                                                  interface IamPermissionsMap

                                                                                                                                                                                  interface IamPermissionsMap {}
                                                                                                                                                                                  • 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.

                                                                                                                                                                                  index signature

                                                                                                                                                                                  [key: string]: boolean;

                                                                                                                                                                                    interface PageOptions

                                                                                                                                                                                    interface PageOptions {}

                                                                                                                                                                                      property autoPaginate

                                                                                                                                                                                      autoPaginate?: boolean;

                                                                                                                                                                                        property gaxOpts

                                                                                                                                                                                        gaxOpts?: CallOptions;

                                                                                                                                                                                          property pageSize

                                                                                                                                                                                          pageSize?: number;

                                                                                                                                                                                            property pageToken

                                                                                                                                                                                            pageToken?: string;

                                                                                                                                                                                              interface PublishOptions

                                                                                                                                                                                              interface PublishOptions {}

                                                                                                                                                                                                property batching

                                                                                                                                                                                                batching?: BatchPublishOptions;

                                                                                                                                                                                                  property flowControlOptions

                                                                                                                                                                                                  flowControlOptions?: FlowControlOptions;

                                                                                                                                                                                                    property gaxOpts

                                                                                                                                                                                                    gaxOpts?: CallOptions;

                                                                                                                                                                                                      property messageOrdering

                                                                                                                                                                                                      messageOrdering?: boolean;

                                                                                                                                                                                                        interface SchemaMessageMetadata

                                                                                                                                                                                                        interface SchemaMessageMetadata {}

                                                                                                                                                                                                        property encoding

                                                                                                                                                                                                        encoding: SchemaEncoding | undefined;
                                                                                                                                                                                                        • Encoding; this will be Encodings.Json or Encodings.Binary.

                                                                                                                                                                                                        property name

                                                                                                                                                                                                        name?: string;

                                                                                                                                                                                                        property revision

                                                                                                                                                                                                        revision?: string;
                                                                                                                                                                                                        • Schema revision; this goes with name as needed.

                                                                                                                                                                                                        interface SubscriberOptions

                                                                                                                                                                                                        interface SubscriberOptions {}
                                                                                                                                                                                                        • {object} SubscriberOptions {number} [ackDeadline=10] Acknowledge deadline in seconds. If left unset, the initial value will be 10 seconds, but it will evolve into the 99th percentile time it takes to acknowledge a message, subject to the limitations of minAckDeadline and maxAckDeadline. If ackDeadline is set by the user, then the min/max values will be set to match it. New code should prefer setting minAckDeadline and maxAckDeadline directly. {Duration} [minAckDeadline] The minimum time that ackDeadline should ever have, while it's under library control. {Duration} [maxAckDeadline] The maximum time that ackDeadline should ever have, while it's under library control. {Duration} [maxExtensionTime] The maximum time that ackDeadline should ever have, while it's under library control. {BatchOptions} [batching] Request batching options; this is for batching acks and modacks being sent back to the server. {FlowControlOptions} [flowControl] Flow control options. {boolean} [useLegacyFlowControl] Disables enforcing flow control settings at the Cloud PubSub server and uses the less accurate method of only enforcing flow control at the client side. {MessageStreamOptions} [streamingOptions] Streaming options. If no options are passed, it behaves like SubscriberCloseBehaviors.Wait. {SubscriberCloseOptions} [options] Determines the basic behavior of the close() function. {SubscriberCloseBehavior} [options.behavior] The behavior of the close operation. - NackImmediately: Sends nacks for all messages held by the client library, and wait for them to send. (default to match old behavior) - WaitForProcessing: Continues normal ack/nack and leasing processes until close to the timeout, then switches to NackImmediately behavior to close down. Use SubscriberCloseBehaviors for enum values. {Duration} [options.timeout] In the case of Timeout, the maximum duration to wait for pending ack/nack requests to complete before resolving (or rejecting) the promise.

                                                                                                                                                                                                        property batching

                                                                                                                                                                                                        batching?: BatchOptions;

                                                                                                                                                                                                          property closeOptions

                                                                                                                                                                                                          closeOptions?: SubscriberCloseOptions;

                                                                                                                                                                                                            property flowControl

                                                                                                                                                                                                            flowControl?: FlowControlOptions;

                                                                                                                                                                                                              property maxAckDeadline

                                                                                                                                                                                                              maxAckDeadline?: Duration;

                                                                                                                                                                                                                property maxExtensionTime

                                                                                                                                                                                                                maxExtensionTime?: Duration;

                                                                                                                                                                                                                  property minAckDeadline

                                                                                                                                                                                                                  minAckDeadline?: Duration;

                                                                                                                                                                                                                    property streamingOptions

                                                                                                                                                                                                                    streamingOptions?: MessageStreamOptions;

                                                                                                                                                                                                                      property useLegacyFlowControl

                                                                                                                                                                                                                      useLegacyFlowControl?: boolean;

                                                                                                                                                                                                                        interface Subscription

                                                                                                                                                                                                                        interface Subscription {}

                                                                                                                                                                                                                          method on

                                                                                                                                                                                                                          on: {
                                                                                                                                                                                                                          (event: 'message', listener: (message: Message) => void): this;
                                                                                                                                                                                                                          (event: 'error', listener: (error: StatusError) => void): this;
                                                                                                                                                                                                                          (event: 'close', listener: () => void): this;
                                                                                                                                                                                                                          (event: 'debug', listener: (msg: DebugMessage) => void): this;
                                                                                                                                                                                                                          (
                                                                                                                                                                                                                          event: 'newListener',
                                                                                                                                                                                                                          listener: (event: string | symbol, listener: Function) => void
                                                                                                                                                                                                                          ): this;
                                                                                                                                                                                                                          (
                                                                                                                                                                                                                          event: 'removeListener',
                                                                                                                                                                                                                          listener: (event: string | symbol, listener: Function) => void
                                                                                                                                                                                                                          ): this;
                                                                                                                                                                                                                          (event: string, listener: void): this;
                                                                                                                                                                                                                          };

                                                                                                                                                                                                                            Type Aliases

                                                                                                                                                                                                                            type AckResponse

                                                                                                                                                                                                                            type AckResponse = ValueOf<typeof AckResponses>;

                                                                                                                                                                                                                              type Attributes

                                                                                                                                                                                                                              type Attributes = Record<string, string>;
                                                                                                                                                                                                                              • Strings are the only allowed values for keys and values in message attributes.

                                                                                                                                                                                                                              type CreateSchemaResponse

                                                                                                                                                                                                                              type CreateSchemaResponse = google.pubsub.v1.Schema;

                                                                                                                                                                                                                                type CreateSnapshotCallback

                                                                                                                                                                                                                                type CreateSnapshotCallback = ResourceCallback<Snapshot, google.pubsub.v1.ISnapshot>;

                                                                                                                                                                                                                                  type CreateSnapshotResponse

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

                                                                                                                                                                                                                                    type CreateSubscriptionCallback

                                                                                                                                                                                                                                    type CreateSubscriptionCallback = SubscriptionCallback;

                                                                                                                                                                                                                                      type CreateSubscriptionOptions

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

                                                                                                                                                                                                                                        type CreateSubscriptionResponse

                                                                                                                                                                                                                                        type CreateSubscriptionResponse = SubscriptionResponse;

                                                                                                                                                                                                                                          type CreateTopicCallback

                                                                                                                                                                                                                                          type CreateTopicCallback = TopicCallback;

                                                                                                                                                                                                                                            type CreateTopicResponse

                                                                                                                                                                                                                                            type CreateTopicResponse = TopicResponse;

                                                                                                                                                                                                                                              type EmptyCallback

                                                                                                                                                                                                                                              type EmptyCallback = RequestCallback<google.protobuf.IEmpty>;

                                                                                                                                                                                                                                                type EmptyResponse

                                                                                                                                                                                                                                                type EmptyResponse = [google.protobuf.IEmpty];

                                                                                                                                                                                                                                                  type ExistsCallback

                                                                                                                                                                                                                                                  type ExistsCallback = RequestCallback<boolean>;

                                                                                                                                                                                                                                                    type ExistsResponse

                                                                                                                                                                                                                                                    type ExistsResponse = [boolean];

                                                                                                                                                                                                                                                      type GetPolicyCallback

                                                                                                                                                                                                                                                      type GetPolicyCallback = RequestCallback<Policy>;

                                                                                                                                                                                                                                                        type GetPolicyResponse

                                                                                                                                                                                                                                                        type GetPolicyResponse = [Policy];

                                                                                                                                                                                                                                                          type GetSnapshotsCallback

                                                                                                                                                                                                                                                          type GetSnapshotsCallback = RequestCallback<
                                                                                                                                                                                                                                                          Snapshot,
                                                                                                                                                                                                                                                          google.pubsub.v1.IListSnapshotsResponse
                                                                                                                                                                                                                                                          >;

                                                                                                                                                                                                                                                            type GetSnapshotsResponse

                                                                                                                                                                                                                                                            type GetSnapshotsResponse = PagedResponse<
                                                                                                                                                                                                                                                            Snapshot,
                                                                                                                                                                                                                                                            google.pubsub.v1.IListSnapshotsResponse
                                                                                                                                                                                                                                                            >;

                                                                                                                                                                                                                                                              type GetSubscriptionCallback

                                                                                                                                                                                                                                                              type GetSubscriptionCallback = SubscriptionCallback;

                                                                                                                                                                                                                                                                type GetSubscriptionMetadataCallback

                                                                                                                                                                                                                                                                type GetSubscriptionMetadataCallback = MetadataCallback;

                                                                                                                                                                                                                                                                  type GetSubscriptionMetadataResponse

                                                                                                                                                                                                                                                                  type GetSubscriptionMetadataResponse = MetadataResponse;

                                                                                                                                                                                                                                                                    type GetSubscriptionOptions

                                                                                                                                                                                                                                                                    type GetSubscriptionOptions = CallOptions & {
                                                                                                                                                                                                                                                                    autoCreate?: boolean;
                                                                                                                                                                                                                                                                    };

                                                                                                                                                                                                                                                                      type GetSubscriptionResponse

                                                                                                                                                                                                                                                                      type GetSubscriptionResponse = SubscriptionResponse;

                                                                                                                                                                                                                                                                        type GetSubscriptionsCallback

                                                                                                                                                                                                                                                                        type GetSubscriptionsCallback =
                                                                                                                                                                                                                                                                        | GetAllSubscriptionsCallback
                                                                                                                                                                                                                                                                        | GetTopicSubscriptionsCallback;

                                                                                                                                                                                                                                                                          type GetSubscriptionsResponse

                                                                                                                                                                                                                                                                          type GetSubscriptionsResponse =
                                                                                                                                                                                                                                                                          | GetAllSubscriptionsResponse
                                                                                                                                                                                                                                                                          | GetTopicSubscriptionsResponse;

                                                                                                                                                                                                                                                                            type GetTopicCallback

                                                                                                                                                                                                                                                                            type GetTopicCallback = TopicCallback;

                                                                                                                                                                                                                                                                              type GetTopicMetadataCallback

                                                                                                                                                                                                                                                                              type GetTopicMetadataCallback = MetadataCallback;

                                                                                                                                                                                                                                                                                type GetTopicMetadataResponse

                                                                                                                                                                                                                                                                                type GetTopicMetadataResponse = MetadataResponse;

                                                                                                                                                                                                                                                                                  type GetTopicOptions

                                                                                                                                                                                                                                                                                  type GetTopicOptions = CallOptions & {
                                                                                                                                                                                                                                                                                  autoCreate?: boolean;
                                                                                                                                                                                                                                                                                  };

                                                                                                                                                                                                                                                                                    type GetTopicResponse

                                                                                                                                                                                                                                                                                    type GetTopicResponse = TopicResponse;

                                                                                                                                                                                                                                                                                      type GetTopicsCallback

                                                                                                                                                                                                                                                                                      type GetTopicsCallback = RequestCallback<
                                                                                                                                                                                                                                                                                      Topic,
                                                                                                                                                                                                                                                                                      google.pubsub.v1.IListTopicsResponse
                                                                                                                                                                                                                                                                                      >;

                                                                                                                                                                                                                                                                                        type GetTopicsResponse

                                                                                                                                                                                                                                                                                        type GetTopicsResponse = PagedResponse<Topic, google.pubsub.v1.IListTopicsResponse>;

                                                                                                                                                                                                                                                                                          type GetTopicSubscriptionsCallback

                                                                                                                                                                                                                                                                                          type GetTopicSubscriptionsCallback = RequestCallback<
                                                                                                                                                                                                                                                                                          Subscription,
                                                                                                                                                                                                                                                                                          google.pubsub.v1.IListTopicSubscriptionsResponse
                                                                                                                                                                                                                                                                                          >;

                                                                                                                                                                                                                                                                                            type GetTopicSubscriptionsResponse

                                                                                                                                                                                                                                                                                            type GetTopicSubscriptionsResponse = PagedResponse<
                                                                                                                                                                                                                                                                                            Subscription,
                                                                                                                                                                                                                                                                                            google.pubsub.v1.IListTopicSubscriptionsResponse
                                                                                                                                                                                                                                                                                            >;

                                                                                                                                                                                                                                                                                              type ICreateSchemaRequest

                                                                                                                                                                                                                                                                                              type ICreateSchemaRequest = google.pubsub.v1.ICreateSchemaRequest;

                                                                                                                                                                                                                                                                                                type ISchema

                                                                                                                                                                                                                                                                                                type ISchema = google.pubsub.v1.ISchema;

                                                                                                                                                                                                                                                                                                  type Policy

                                                                                                                                                                                                                                                                                                  type Policy = {
                                                                                                                                                                                                                                                                                                  etag?: string | Buffer;
                                                                                                                                                                                                                                                                                                  } & Omit<IamProtos.google.iam.v1.IPolicy, 'etag'>;

                                                                                                                                                                                                                                                                                                    type PublishCallback

                                                                                                                                                                                                                                                                                                    type PublishCallback = RequestCallback<string>;

                                                                                                                                                                                                                                                                                                      type PushConfig

                                                                                                                                                                                                                                                                                                      type PushConfig = google.pubsub.v1.IPushConfig;

                                                                                                                                                                                                                                                                                                        type SchemaEncoding

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

                                                                                                                                                                                                                                                                                                          type SchemaType

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

                                                                                                                                                                                                                                                                                                            type SchemaView

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

                                                                                                                                                                                                                                                                                                              type SeekCallback

                                                                                                                                                                                                                                                                                                              type SeekCallback = RequestCallback<google.pubsub.v1.ISeekResponse>;

                                                                                                                                                                                                                                                                                                                type SeekResponse

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

                                                                                                                                                                                                                                                                                                                  type SetPolicyCallback

                                                                                                                                                                                                                                                                                                                  type SetPolicyCallback = RequestCallback<Policy>;

                                                                                                                                                                                                                                                                                                                    type SetPolicyResponse

                                                                                                                                                                                                                                                                                                                    type SetPolicyResponse = [Policy];

                                                                                                                                                                                                                                                                                                                      type SetSubscriptionMetadataCallback

                                                                                                                                                                                                                                                                                                                      type SetSubscriptionMetadataCallback = MetadataCallback;

                                                                                                                                                                                                                                                                                                                        type SetSubscriptionMetadataResponse

                                                                                                                                                                                                                                                                                                                        type SetSubscriptionMetadataResponse = MetadataResponse;

                                                                                                                                                                                                                                                                                                                          type SetTopicMetadataCallback

                                                                                                                                                                                                                                                                                                                          type SetTopicMetadataCallback = MetadataCallback;

                                                                                                                                                                                                                                                                                                                            type SetTopicMetadataResponse

                                                                                                                                                                                                                                                                                                                            type SetTopicMetadataResponse = MetadataResponse;

                                                                                                                                                                                                                                                                                                                              type SubscriptionCloseCallback

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

                                                                                                                                                                                                                                                                                                                                type SubscriptionCloseOptions

                                                                                                                                                                                                                                                                                                                                type SubscriptionCloseOptions = SubscriberCloseOptions;

                                                                                                                                                                                                                                                                                                                                  type SubscriptionMetadata

                                                                                                                                                                                                                                                                                                                                  type SubscriptionMetadata = {
                                                                                                                                                                                                                                                                                                                                  messageRetentionDuration?: google.protobuf.IDuration | number;
                                                                                                                                                                                                                                                                                                                                  pushEndpoint?: string;
                                                                                                                                                                                                                                                                                                                                  oidcToken?: OidcToken;
                                                                                                                                                                                                                                                                                                                                  } & Omit<google.pubsub.v1.ISubscription, 'messageRetentionDuration'>;

                                                                                                                                                                                                                                                                                                                                    type SubscriptionOptions

                                                                                                                                                                                                                                                                                                                                    type SubscriptionOptions = SubscriberOptions & {
                                                                                                                                                                                                                                                                                                                                    topic?: Topic;
                                                                                                                                                                                                                                                                                                                                    };

                                                                                                                                                                                                                                                                                                                                      type TestIamPermissionsCallback

                                                                                                                                                                                                                                                                                                                                      type TestIamPermissionsCallback = ResourceCallback<
                                                                                                                                                                                                                                                                                                                                      IamPermissionsMap,
                                                                                                                                                                                                                                                                                                                                      IamProtos.google.iam.v1.ITestIamPermissionsResponse
                                                                                                                                                                                                                                                                                                                                      >;

                                                                                                                                                                                                                                                                                                                                        type TestIamPermissionsResponse

                                                                                                                                                                                                                                                                                                                                        type TestIamPermissionsResponse = [
                                                                                                                                                                                                                                                                                                                                        IamPermissionsMap,
                                                                                                                                                                                                                                                                                                                                        IamProtos.google.iam.v1.ITestIamPermissionsResponse
                                                                                                                                                                                                                                                                                                                                        ];

                                                                                                                                                                                                                                                                                                                                          type TopicMetadata

                                                                                                                                                                                                                                                                                                                                          type TopicMetadata = google.pubsub.v1.ITopic;

                                                                                                                                                                                                                                                                                                                                            type TotalOfUnit

                                                                                                                                                                                                                                                                                                                                            type TotalOfUnit =
                                                                                                                                                                                                                                                                                                                                            | 'hour'
                                                                                                                                                                                                                                                                                                                                            | 'minute'
                                                                                                                                                                                                                                                                                                                                            | 'second'
                                                                                                                                                                                                                                                                                                                                            | 'millisecond'
                                                                                                                                                                                                                                                                                                                                            | 'hours'
                                                                                                                                                                                                                                                                                                                                            | 'minutes'
                                                                                                                                                                                                                                                                                                                                            | 'seconds'
                                                                                                                                                                                                                                                                                                                                            | 'milliseconds';
                                                                                                                                                                                                                                                                                                                                            • Simplified list of values to pass to Duration.totalOf(). This list is taken from the tc39 Temporal.Duration proposal, but larger and smaller units have been left off. The latest tc39 spec allows for both singular and plural forms.

                                                                                                                                                                                                                                                                                                                                            Namespaces

                                                                                                                                                                                                                                                                                                                                            namespace protos

                                                                                                                                                                                                                                                                                                                                            module 'build/protos/protos.d.ts' {}

                                                                                                                                                                                                                                                                                                                                              Package Files (17)

                                                                                                                                                                                                                                                                                                                                              Dependencies (18)

                                                                                                                                                                                                                                                                                                                                              Dev Dependencies (39)

                                                                                                                                                                                                                                                                                                                                              Peer Dependencies (0)

                                                                                                                                                                                                                                                                                                                                              No peer dependencies.

                                                                                                                                                                                                                                                                                                                                              Badge

                                                                                                                                                                                                                                                                                                                                              To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                                                                                                                                                                                                                                                              You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@google-cloud/pubsub.

                                                                                                                                                                                                                                                                                                                                              • Markdown
                                                                                                                                                                                                                                                                                                                                                [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@google-cloud/pubsub)
                                                                                                                                                                                                                                                                                                                                              • HTML
                                                                                                                                                                                                                                                                                                                                                <a href="https://www.jsdocs.io/package/@google-cloud/pubsub"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>