Package @google-cloud/pubsub (6.4.1)

Classes

AckError

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.

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.

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

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.*

Message

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

PublishError

Exception to be thrown during failed ordered publish.

Error

PubSub

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

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

Snapshot

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

Snapshots are sometimes retrieved when using various methods:


Snapshots may be created with:

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

-

StatusError

Error wrapper for gRPC status objects.

Subscription

A Subscription object will give you access to your Cloud Pub/Sub subscription.

Subscriptions are sometimes retrieved when using various methods:

Subscription objects may be created directly with:

All Subscription objects are instances of an [EventEmitter](http://nodejs.org/api/events.html). The subscription will pull for messages automatically as long as there is at least one listener assigned for the message event. Available events:

Upon receipt of a message: on(event: 'message', listener: (message: Message) => void): this;

Upon receipt of an error: on(event: 'error', listener: (error: Error) => void): this;

Upon 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.

Topic

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

Interfaces

BatchPublishOptions

ClientConfig

DurationLike

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

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.

HedgingOptions

Settings for configuring publish hedging.

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.

PageOptions

PublishOptions

SchemaMessageMetadata

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

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

Subscription

Variables

AckResponses

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

Encodings

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

SchemaTypes

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

SchemaViews

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

SubscriptionCloseBehaviors

SubscriptionCloseBehaviors: {
    NackImmediately: "NACK";
    WaitForProcessing: "WAIT";
}

Type Aliases

AckResponse

export type AckResponse = ValueOf

Attributes

export type Attributes = Record

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

CreateSchemaResponse

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

CreateSnapshotCallback

export type CreateSnapshotCallback = ResourceCallback

CreateSnapshotResponse

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

CreateSubscriptionCallback

export type CreateSubscriptionCallback = SubscriptionCallback;

CreateSubscriptionOptions

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

CreateSubscriptionResponse

export type CreateSubscriptionResponse = SubscriptionResponse;

CreateTopicCallback

export type CreateTopicCallback = TopicCallback;

CreateTopicResponse

export type CreateTopicResponse = TopicResponse;

EmptyCallback

export type EmptyCallback = RequestCallback

EmptyResponse

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

ExistsCallback

export type ExistsCallback = RequestCallback

ExistsResponse

export type ExistsResponse = [boolean];

GetPolicyCallback

export type GetPolicyCallback = RequestCallback

GetPolicyResponse

export type GetPolicyResponse = [Policy];

GetSnapshotsCallback

export type GetSnapshotsCallback = RequestCallback

GetSnapshotsResponse

export type GetSnapshotsResponse = PagedResponse

GetSubscriptionCallback

export type GetSubscriptionCallback = SubscriptionCallback;

GetSubscriptionMetadataCallback

export type GetSubscriptionMetadataCallback = MetadataCallback;

GetSubscriptionMetadataResponse

export type GetSubscriptionMetadataResponse = MetadataResponse;

GetSubscriptionOptions

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

GetSubscriptionResponse

export type GetSubscriptionResponse = SubscriptionResponse;

GetSubscriptionsCallback

export type GetSubscriptionsCallback = GetAllSubscriptionsCallback | GetTopicSubscriptionsCallback;

GetSubscriptionsResponse

export type GetSubscriptionsResponse = GetAllSubscriptionsResponse | GetTopicSubscriptionsResponse;

GetTopicCallback

export type GetTopicCallback = TopicCallback;

GetTopicMetadataCallback

export type GetTopicMetadataCallback = MetadataCallback;

GetTopicMetadataResponse

export type GetTopicMetadataResponse = MetadataResponse;

GetTopicOptions

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

GetTopicResponse

export type GetTopicResponse = TopicResponse;

GetTopicsCallback

export type GetTopicsCallback = RequestCallback

GetTopicsResponse

export type GetTopicsResponse = PagedResponse

GetTopicSubscriptionsCallback

export type GetTopicSubscriptionsCallback = RequestCallback

GetTopicSubscriptionsResponse

export type GetTopicSubscriptionsResponse = PagedResponse

ICreateSchemaRequest

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

ISchema

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

Policy

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

PublishCallback

export type PublishCallback = RequestCallback

PushConfig

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

SchemaEncoding

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

SchemaType

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

SchemaView

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

SeekCallback

export type SeekCallback = RequestCallback

SeekResponse

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

SetPolicyCallback

export type SetPolicyCallback = RequestCallback

SetPolicyResponse

export type SetPolicyResponse = [Policy];

SetSubscriptionMetadataCallback

export type SetSubscriptionMetadataCallback = MetadataCallback;

SetSubscriptionMetadataResponse

export type SetSubscriptionMetadataResponse = MetadataResponse;

SetTopicMetadataCallback

export type SetTopicMetadataCallback = MetadataCallback;

SetTopicMetadataResponse

export type SetTopicMetadataResponse = MetadataResponse;

SubscriptionCloseCallback

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

SubscriptionCloseOptions

export type SubscriptionCloseOptions = SubscriberCloseOptions;

SubscriptionMetadata

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

SubscriptionOptions

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

TestIamPermissionsCallback

export type TestIamPermissionsCallback = ResourceCallback

TestIamPermissionsResponse

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

TopicMetadata

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

TotalOfUnit

export 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.