UNPKG

27.1 kBTypeScriptView Raw
1/*!
2 * Copyright 2014 Google Inc. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16/// <reference types="node" />
17import { EventEmitter } from 'events';
18import { CallOptions } from 'google-gax';
19import { google } from '../protos/protos';
20import { IAM } from './iam';
21import { FlowControlOptions } from './lease-manager';
22import { DetachedCallback, DetachedResponse, EmptyCallback, EmptyResponse, ExistsCallback, ExistsResponse, Omit, PubSub, RequestCallback, ResourceCallback } from './pubsub';
23import { CreateSnapshotCallback, CreateSnapshotResponse, SeekCallback, SeekResponse, Snapshot } from './snapshot';
24import { SubscriberOptions } from './subscriber';
25import { Topic } from './topic';
26export declare type PushConfig = google.pubsub.v1.IPushConfig;
27export declare type OidcToken = google.pubsub.v1.PushConfig.IOidcToken;
28export declare type SubscriptionMetadata = {
29 messageRetentionDuration?: google.protobuf.IDuration | number;
30 pushEndpoint?: string;
31 oidcToken?: OidcToken;
32} & Omit<google.pubsub.v1.ISubscription, 'messageRetentionDuration'>;
33export declare type SubscriptionOptions = SubscriberOptions & {
34 topic?: Topic;
35};
36export declare type SubscriptionCloseCallback = (err?: Error) => void;
37declare type SubscriptionCallback = ResourceCallback<Subscription, google.pubsub.v1.ISubscription>;
38declare type SubscriptionResponse = [Subscription, google.pubsub.v1.ISubscription];
39export declare type CreateSubscriptionOptions = SubscriptionMetadata & {
40 gaxOpts?: CallOptions;
41 flowControl?: FlowControlOptions;
42};
43export declare type CreateSubscriptionCallback = SubscriptionCallback;
44export declare type CreateSubscriptionResponse = SubscriptionResponse;
45export declare type GetSubscriptionOptions = CallOptions & {
46 autoCreate?: boolean;
47};
48export declare type GetSubscriptionCallback = SubscriptionCallback;
49export declare type GetSubscriptionResponse = SubscriptionResponse;
50declare type MetadataCallback = RequestCallback<google.pubsub.v1.ISubscription>;
51declare type MetadataResponse = [google.pubsub.v1.ISubscription];
52export declare type GetSubscriptionMetadataCallback = MetadataCallback;
53export declare type GetSubscriptionMetadataResponse = MetadataResponse;
54export declare type SetSubscriptionMetadataCallback = MetadataCallback;
55export declare type SetSubscriptionMetadataResponse = MetadataResponse;
56export declare type DetachSubscriptionCallback = EmptyCallback;
57export declare type DetachSubscriptionResponse = EmptyResponse;
58/**
59 * @typedef {object} ExpirationPolicy
60 * A policy that specifies the conditions for this subscription's expiration. A
61 * subscription is considered active as long as any connected subscriber is
62 * successfully consuming messages from the subscription or is issuing
63 * operations on the subscription. If expirationPolicy is not set, a default
64 * policy with ttl of 31 days will be used. The minimum allowed value for
65 * expirationPolicy.ttl is 1 day.
66 * @property {google.protobuf.Duration} ttl Specifies the "time-to-live"
67 * duration for an associated resource. The resource expires if it is not
68 * active for a period of `ttl`. The definition of "activity" depends on the
69 * type of the associated resource. The minimum and maximum allowed values
70 * for `ttl` depend on the type of the associated resource, as well. If
71 * `ttl` is not set, the associated resource never expires.
72 */
73/**
74 * A Subscription object will give you access to your Cloud Pub/Sub
75 * subscription.
76 *
77 * Subscriptions are sometimes retrieved when using various methods:
78 *
79 * - {@link PubSub#getSubscriptions}
80 * - {@link Topic#getSubscriptions}
81 *
82 * Subscription objects may be created directly with:
83 *
84 * - {@link PubSub#createSubscription}
85 * - {@link Topic#createSubscription}
86 *
87 * All Subscription objects are instances of an
88 * [EventEmitter](http://nodejs.org/api/events.html). The subscription will pull
89 * for messages automatically as long as there is at least one listener assigned
90 * for the `message` event. Available events:
91 *
92 * Upon receipt of a message:
93 * on(event: 'message', listener: (message: {@link Message}) => void): this;
94 *
95 * Upon receipt of an error:
96 * on(event: 'error', listener: (error: Error) => void): this;
97 *
98 * Upon the closing of the subscriber:
99 * on(event: 'close', listener: Function): this;
100 *
101 * By default Subscription objects allow you to process 100 messages at the same
102 * time. You can fine tune this value by adjusting the
103 * `options.flowControl.maxMessages` option.
104 *
105 * If your subscription is seeing more re-deliveries than preferable, you might
106 * try increasing your `options.ackDeadline` value or decreasing the
107 * `options.streamingOptions.maxStreams` value.
108 *
109 * Subscription objects handle ack management, by automatically extending the
110 * ack deadline while the message is being processed, to then issue the ack or
111 * nack of such message when the processing is done. **Note:** message
112 * redelivery is still possible.
113 *
114 * By default each {@link PubSub} instance can handle 100 open streams, with
115 * default options this translates to less than 20 Subscriptions per PubSub
116 * instance. If you wish to create more Subscriptions than that, you can either
117 * create multiple PubSub instances or lower the
118 * `options.streamingOptions.maxStreams` value on each Subscription object.
119 *
120 * @class
121 *
122 * @param {PubSub} pubsub PubSub object.
123 * @param {string} name The name of the subscription.
124 * @param {SubscriberOptions} [options] Options for handling messages.
125 *
126 * @example From {@link PubSub#getSubscriptions}
127 * ```
128 * const {PubSub} = require('@google-cloud/pubsub');
129 * const pubsub = new PubSub();
130 *
131 * pubsub.getSubscriptions((err, subscriptions) => {
132 * // `subscriptions` is an array of Subscription objects.
133 * });
134 *
135 * ```
136 * @example From {@link Topic#getSubscriptions}
137 * ```
138 * const topic = pubsub.topic('my-topic');
139 * topic.getSubscriptions((err, subscriptions) => {
140 * // `subscriptions` is an array of Subscription objects.
141 * });
142 *
143 * ```
144 * @example {@link Topic#createSubscription}
145 * ```
146 * const topic = pubsub.topic('my-topic');
147 * topic.createSubscription('new-subscription', (err, subscription) => {
148 * // `subscription` is a Subscription object.
149 * });
150 *
151 * ```
152 * @example {@link Topic#subscription}
153 * ```
154 * const topic = pubsub.topic('my-topic');
155 * const subscription = topic.subscription('my-subscription');
156 * // `subscription` is a Subscription object.
157 *
158 * ```
159 * @example Once you have obtained a subscription object, you may begin to register listeners. This will automatically trigger pulling for messages.
160 * ```
161 * // Register an error handler.
162 * subscription.on('error', (err) => {});
163 *
164 * // Register a close handler in case the subscriber closes unexpectedly
165 * subscription.on('close', () => {});
166 *
167 * // Register a listener for `message` events.
168 * function onMessage(message) {
169 * // Called every time a message is received.
170 *
171 * // message.id = ID of the message.
172 * // message.ackId = ID used to acknowledge the message receival.
173 * // message.data = Contents of the message.
174 * // message.attributes = Attributes of the message.
175 * // message.publishTime = Date when Pub/Sub received the message.
176 *
177 * // Ack the message:
178 * // message.ack();
179 *
180 * // This doesn't ack the message, but allows more messages to be retrieved
181 * // if your limit was hit or if you don't want to ack the message.
182 * // message.nack();
183 * }
184 * subscription.on('message', onMessage);
185 *
186 * // Remove the listener from receiving `message` events.
187 * subscription.removeListener('message', onMessage);
188 *
189 * ```
190 * @example To apply a fine level of flow control, consider the following configuration
191 * ```
192 * const subscription = topic.subscription('my-sub', {
193 * flowControl: {
194 * maxMessages: 1,
195 * // this tells the client to manage and lock any excess messages
196 * allowExcessMessages: false
197 * }
198 * });
199 * ```
200 */
201export declare class Subscription extends EventEmitter {
202 pubsub: PubSub;
203 iam: IAM;
204 name: string;
205 topic?: Topic | string;
206 metadata?: google.pubsub.v1.ISubscription;
207 request: typeof PubSub.prototype.request;
208 private _subscriber;
209 constructor(pubsub: PubSub, name: string, options?: SubscriptionOptions);
210 /**
211 * Indicates if the Subscription is open and receiving messages.
212 *
213 * @type {boolean}
214 */
215 get isOpen(): boolean;
216 /**
217 * @type {string}
218 */
219 get projectId(): string;
220 /**
221 * Closes the Subscription, once this is called you will no longer receive
222 * message events unless you call {Subscription#open} or add new message
223 * listeners.
224 *
225 * @param {function} [callback] The callback function.
226 * @param {?error} callback.err An error returned while closing the
227 * Subscription.
228 *
229 * @example
230 * ```
231 * subscription.close(err => {
232 * if (err) {
233 * // Error handling omitted.
234 * }
235 * });
236 *
237 * // If the callback is omitted a Promise will be returned.
238 * subscription.close().then(() => {});
239 * ```
240 */
241 close(): Promise<void>;
242 close(callback: SubscriptionCloseCallback): void;
243 /**
244 * Create a subscription.
245 *
246 * @see [Subscriptions: create API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/create}
247 *
248 * @throws {Error} If subscription name is omitted.
249 *
250 * @param {string} name The name of the subscription.
251 * @param {CreateSubscriptionRequest} [options] See a
252 * [Subscription
253 * resource](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions).
254 * @param {CreateSubscriptionCallback} [callback] Callback function.
255 * @returns {Promise<CreateSubscriptionResponse>}
256 *
257 * @example
258 * ```
259 * const {PubSub} = require('@google-cloud/pubsub');
260 * const pubsub = new PubSub();
261 *
262 * const topic = pubsub.topic('my-topic');
263 * const subscription = topic.subscription('newMessages');
264 * const callback = function(err, subscription, apiResponse) {};
265 *
266 * subscription.create(callback);
267 *
268 * ```
269 * @example With options
270 * ```
271 * subscription.create({
272 * ackDeadlineSeconds: 90
273 * }, callback);
274 *
275 * ```
276 * @example If the callback is omitted, we'll return a Promise.
277 * ```
278 * const [sub, apiResponse] = await subscription.create();
279 * ```
280 */
281 create(options?: CreateSubscriptionOptions): Promise<CreateSubscriptionResponse>;
282 create(callback: CreateSubscriptionCallback): void;
283 create(options: CreateSubscriptionOptions, callback: CreateSubscriptionCallback): void;
284 /**
285 * @typedef {array} CreateSnapshotResponse
286 * @property {Snapshot} 0 The new {@link Snapshot}.
287 * @property {object} 1 The full API response.
288 */
289 /**
290 * @callback CreateSnapshotCallback
291 * @param {?Error} err Request error, if any.
292 * @param {Snapshot} snapshot The new {@link Snapshot}.
293 * @param {object} apiResponse The full API response.
294 */
295 /**
296 * Create a snapshot with the given name.
297 *
298 * @param {string} name Name of the snapshot.
299 * @param {object} [gaxOpts] Request configuration options, outlined
300 * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
301 * @param {CreateSnapshotCallback} [callback] Callback function.
302 * @returns {Promise<CreateSnapshotResponse>}
303 *
304 * @example
305 * ```
306 * const {PubSub} = require('@google-cloud/pubsub');
307 * const pubsub = new PubSub();
308 *
309 * const topic = pubsub.topic('my-topic');
310 * const subscription = topic.subscription('my-subscription');
311 *
312 * const callback = (err, snapshot, apiResponse) => {
313 * if (!err) {
314 * // The snapshot was created successfully.
315 * }
316 * };
317 *
318 * subscription.createSnapshot('my-snapshot', callback);
319 *
320 * //-
321 * // If the callback is omitted, we'll return a Promise.
322 * //-
323 * subscription.createSnapshot('my-snapshot').then((data) => {
324 * const snapshot = data[0];
325 * const apiResponse = data[1];
326 * });
327 * ```
328 */
329 createSnapshot(name: string, gaxOpts?: CallOptions): Promise<CreateSnapshotResponse>;
330 createSnapshot(name: string, callback: CreateSnapshotCallback): void;
331 createSnapshot(name: string, gaxOpts: CallOptions, callback: CreateSnapshotCallback): void;
332 /**
333 * Delete the subscription. Pull requests from the current subscription will
334 * be errored once unsubscription is complete.
335 *
336 * @see [Subscriptions: delete API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/delete}
337 *
338 * @param {object} [gaxOpts] Request configuration options, outlined
339 * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
340 * @param {function} [callback] The callback function.
341 * @param {?error} callback.err An error returned while making this
342 * request.
343 * @param {object} callback.apiResponse Raw API response.
344 *
345 * @example
346 * ```
347 * const {PubSub} = require('@google-cloud/pubsub');
348 * const pubsub = new PubSub();
349 *
350 * const topic = pubsub.topic('my-topic');
351 * const subscription = topic.subscription('my-subscription');
352 *
353 * subscription.delete((err, apiResponse) => {});
354 *
355 * //-
356 * // If the callback is omitted, we'll return a Promise.
357 * //-
358 * subscription.delete().then((data) => {
359 * const apiResponse = data[0];
360 * });
361 * ```
362 */
363 delete(gaxOpts?: CallOptions): Promise<EmptyResponse>;
364 delete(callback: EmptyCallback): void;
365 delete(gaxOpts: CallOptions, callback: EmptyCallback): void;
366 /**
367 * @typedef {array} SubscriptionDetachedResponse
368 * @property {boolean} 0 Whether the subscription is detached.
369 */
370 /**
371 * @callback SubscriptionDetachedCallback
372 * @param {?Error} err Request error, if any.
373 * @param {boolean} exists Whether the subscription is detached.
374 */
375 /**
376 * Check if a subscription is detached.
377 *
378 * @param {SubscriptionDetachedCallback} [callback] Callback function.
379 * @returns {Promise<SubscriptionDetachedResponse>}
380 *
381 * @example
382 * ```
383 * const {PubSub} = require('@google-cloud/pubsub');
384 * const pubsub = new PubSub();
385 *
386 * const topic = pubsub.topic('my-topic');
387 * const subscription = topic.subscription('my-subscription');
388 *
389 * subscription.detached((err, exists) => {});
390 *
391 * //-
392 * // If the callback is omitted, we'll return a Promise.
393 * //-
394 * subscription.detached().then((data) => {
395 * const detached = data[0];
396 * });
397 * ```
398 */
399 detached(): Promise<DetachedResponse>;
400 detached(callback: DetachedCallback): void;
401 /**
402 * @typedef {array} SubscriptionExistsResponse
403 * @property {boolean} 0 Whether the subscription exists
404 */
405 /**
406 * @callback SubscriptionExistsCallback
407 * @param {?Error} err Request error, if any.
408 * @param {boolean} exists Whether the subscription exists.
409 */
410 /**
411 * Check if a subscription exists.
412 *
413 * @param {SubscriptionExistsCallback} [callback] Callback function.
414 * @returns {Promise<SubscriptionExistsResponse>}
415 *
416 * @example
417 * ```
418 * const {PubSub} = require('@google-cloud/pubsub');
419 * const pubsub = new PubSub();
420 *
421 * const topic = pubsub.topic('my-topic');
422 * const subscription = topic.subscription('my-subscription');
423 *
424 * subscription.exists((err, exists) => {});
425 *
426 * //-
427 * // If the callback is omitted, we'll return a Promise.
428 * //-
429 * subscription.exists().then((data) => {
430 * const exists = data[0];
431 * });
432 * ```
433 */
434 exists(): Promise<ExistsResponse>;
435 exists(callback: ExistsCallback): void;
436 /**
437 * @typedef {array} GetSubscriptionResponse
438 * @property {Subscription} 0 The {@link Subscription}.
439 * @property {object} 1 The full API response.
440 */
441 /**
442 * @callback GetSubscriptionCallback
443 * @param {?Error} err Request error, if any.
444 * @param {Subscription} subscription The {@link Subscription}.
445 * @param {object} apiResponse The full API response.
446 */
447 /**
448 * Get a subscription if it exists.
449 *
450 * @param {object} [gaxOpts] Request configuration options, outlined
451 * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
452 * @param {boolean} [gaxOpts.autoCreate=false] Automatically create the
453 * subscription if it does not already exist.
454 * @param {GetSubscriptionCallback} [callback] Callback function.
455 * @returns {Promise<GetSubscriptionResponse>}
456 *
457 * @example
458 * ```
459 * const {PubSub} = require('@google-cloud/pubsub');
460 * const pubsub = new PubSub();
461 *
462 * const topic = pubsub.topic('my-topic');
463 * const subscription = topic.subscription('my-subscription');
464 *
465 * subscription.get((err, subscription, apiResponse) => {
466 * // The `subscription` data has been populated.
467 * });
468 *
469 * //-
470 * // If the callback is omitted, we'll return a Promise.
471 * //-
472 * subscription.get().then((data) => {
473 * const subscription = data[0];
474 * const apiResponse = data[1];
475 * });
476 * ```
477 */
478 get(gaxOpts?: GetSubscriptionOptions): Promise<GetSubscriptionResponse>;
479 get(callback: GetSubscriptionCallback): void;
480 get(gaxOpts: GetSubscriptionOptions, callback: GetSubscriptionCallback): void;
481 /**
482 * @typedef {array} GetSubscriptionMetadataResponse
483 * @property {object} 0 The full API response.
484 */
485 /**
486 * @callback GetSubscriptionMetadataCallback
487 * @param {?Error} err Request error, if any.
488 * @param {object} apiResponse The full API response.
489 */
490 /**
491 * Fetches the subscriptions metadata.
492 *
493 * @param {object} [gaxOpts] Request configuration options, outlined
494 * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
495 * @param {GetSubscriptionMetadataCallback} [callback] Callback function.
496 * @returns {Promise<GetSubscriptionMetadataResponse>}
497 *
498 * @example
499 * ```
500 * const {PubSub} = require('@google-cloud/pubsub');
501 * const pubsub = new PubSub();
502 *
503 * const topic = pubsub.topic('my-topic');
504 * const subscription = topic.subscription('my-subscription');
505 *
506 * subscription.getMetadata((err, apiResponse) => {
507 * if (err) {
508 * // Error handling omitted.
509 * }
510 * });
511 *
512 * //-
513 * // If the callback is omitted, we'll return a Promise.
514 * //-
515 * subscription.getMetadata().then((data) => {
516 * const apiResponse = data[0];
517 * });
518 * ```
519 */
520 getMetadata(gaxOpts?: CallOptions): Promise<GetSubscriptionMetadataResponse>;
521 getMetadata(callback: GetSubscriptionMetadataCallback): void;
522 getMetadata(gaxOpts: CallOptions, callback: GetSubscriptionMetadataCallback): void;
523 /**
524 * @typedef {array} ModifyPushConfigResponse
525 * @property {object} 0 The full API response.
526 */
527 /**
528 * @callback ModifyPushConfigCallback
529 * @param {?Error} err Request error, if any.
530 * @param {object} apiResponse The full API response.
531 */
532 /**
533 * Modify the push config for the subscription.
534 *
535 * @param {object} config The push config.
536 * @param {string} config.pushEndpoint A URL locating the endpoint to which
537 * messages should be published.
538 * @param {object} config.attributes [PushConfig attributes](https://cloud.google.com/pubsub/docs/reference/rpc/google.pubsub.v1#google.pubsub.v1.PushConfig).
539 * @param {object} config.oidcToken If specified, Pub/Sub will generate and
540 * attach an OIDC JWT token as an `Authorization` header in the HTTP
541 * request for every pushed message. This object should have the same
542 * structure as [OidcToken]{@link google.pubsub.v1.OidcToken}
543 * @param {object} [gaxOpts] Request configuration options, outlined
544 * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
545 * @param {ModifyPushConfigCallback} [callback] Callback function.
546 * @returns {Promise<ModifyPushConfigResponse>}
547 *
548 * @example
549 * ```
550 * const {PubSub} = require('@google-cloud/pubsub');
551 * const pubsub = new PubSub();
552 *
553 * const topic = pubsub.topic('my-topic');
554 * const subscription = topic.subscription('my-subscription');
555 *
556 * const pushConfig = {
557 * pushEndpoint: 'https://mydomain.com/push',
558 * attributes: {
559 * key: 'value'
560 * },
561 * oidcToken: {
562 * serviceAccountEmail: 'myproject@appspot.gserviceaccount.com',
563 * audience: 'myaudience'
564 * }
565 * };
566 *
567 * subscription.modifyPushConfig(pushConfig, (err, apiResponse) => {
568 * if (err) {
569 * // Error handling omitted.
570 * }
571 * });
572 *
573 * //-
574 * // If the callback is omitted, we'll return a Promise.
575 * //-
576 * subscription.modifyPushConfig(pushConfig).then((data) => {
577 * const apiResponse = data[0];
578 * });
579 * ```
580 */
581 modifyPushConfig(config: PushConfig, gaxOpts?: CallOptions): Promise<EmptyResponse>;
582 modifyPushConfig(config: PushConfig, callback: EmptyCallback): void;
583 modifyPushConfig(config: PushConfig, gaxOpts: CallOptions, callback: EmptyCallback): void;
584 /**
585 * Opens the Subscription to receive messages. In general this method
586 * shouldn't need to be called, unless you wish to receive messages after
587 * calling {@link Subscription#close}. Alternatively one could just assign a
588 * new `message` event listener which will also re-open the Subscription.
589 *
590 * @example
591 * ```
592 * subscription.on('message', message => message.ack());
593 *
594 * // Close the subscription.
595 * subscription.close(err => {
596 * if (err) {
597 * // Error handling omitted.
598 * }
599 *
600 * The subscription has been closed and messages will no longer be received.
601 * });
602 *
603 * // Resume receiving messages.
604 * subscription.open();
605 * ```
606 */
607 open(): void;
608 /**
609 * @typedef {array} SeekResponse
610 * @property {object} 0 The full API response.
611 */
612 /**
613 * @callback SeekCallback
614 * @param {?Error} err Request error, if any.
615 * @param {object} apiResponse The full API response.
616 */
617 /**
618 * Seeks an existing subscription to a point in time or a given snapshot.
619 *
620 * @param {string|date} snapshot The point to seek to. This will accept the
621 * name of the snapshot or a Date object.
622 * @param {object} [gaxOpts] Request configuration options, outlined
623 * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
624 * @param {SeekCallback} [callback] Callback function.
625 * @returns {Promise<SeekResponse>}
626 *
627 * @example
628 * ```
629 * const callback = (err, resp) => {
630 * if (!err) {
631 * // Seek was successful.
632 * }
633 * };
634 *
635 * subscription.seek('my-snapshot', callback);
636 *
637 * //-
638 * // Alternatively, to specify a certain point in time, you can provide a
639 * Date
640 * // object.
641 * //-
642 * const date = new Date('October 21 2015');
643 *
644 * subscription.seek(date, callback);
645 * ```
646 */
647 seek(snapshot: string | Date, gaxOpts?: CallOptions): Promise<SeekResponse>;
648 seek(snapshot: string | Date, callback: SeekCallback): void;
649 seek(snapshot: string | Date, gaxOpts: CallOptions, callback: SeekCallback): void;
650 /**
651 * @typedef {array} SetSubscriptionMetadataResponse
652 * @property {object} 0 The full API response.
653 */
654 /**
655 * @callback SetSubscriptionMetadataCallback
656 * @param {?Error} err Request error, if any.
657 * @param {object} apiResponse The full API response.
658 */
659 /**
660 * Update the subscription object.
661 *
662 * @param {object} metadata The subscription metadata.
663 * @param {object} [gaxOpts] Request configuration options, outlined
664 * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
665 * @param {SetSubscriptionMetadataCallback} [callback] Callback function.
666 * @returns {Promise<SetSubscriptionMetadataResponse>}
667 *
668 * @example
669 * ```
670 * const metadata = {
671 * key: 'value'
672 * };
673 *
674 * subscription.setMetadata(metadata, (err, apiResponse) => {
675 * if (err) {
676 * // Error handling omitted.
677 * }
678 * });
679 *
680 * //-
681 * // If the callback is omitted, we'll return a Promise.
682 * //-
683 * subscription.setMetadata(metadata).then((data) => {
684 * const apiResponse = data[0];
685 * });
686 * ```
687 */
688 setMetadata(metadata: SubscriptionMetadata, gaxOpts?: CallOptions): Promise<SetSubscriptionMetadataResponse>;
689 setMetadata(metadata: SubscriptionMetadata, callback: SetSubscriptionMetadataCallback): void;
690 setMetadata(metadata: SubscriptionMetadata, gaxOpts: CallOptions, callback: SetSubscriptionMetadataCallback): void;
691 /**
692 * Sets the Subscription options.
693 *
694 * @param {SubscriberOptions} options The options.
695 */
696 setOptions(options: SubscriberOptions): void;
697 /**
698 * Create a Snapshot object. See {@link Subscription#createSnapshot} to
699 * create a snapshot.
700 *
701 * @throws {Error} If a name is not provided.
702 *
703 * @param {string} name The name of the snapshot.
704 * @returns {Snapshot}
705 *
706 * @example
707 * ```
708 * const snapshot = subscription.snapshot('my-snapshot');
709 * ```
710 */
711 snapshot(name: string): Snapshot;
712 /**
713 * Watches for incoming message event handlers and open/closes the
714 * subscriber as needed.
715 *
716 * @private
717 */
718 private _listen;
719 /*!
720 * Formats Subscription metadata.
721 *
722 * @private
723 */
724 static formatMetadata_(metadata: SubscriptionMetadata): google.pubsub.v1.ISubscription;
725 /*!
726 * Format the name of a subscription. A subscription's full name is in the
727 * format of projects/{projectId}/subscriptions/{subName}.
728 *
729 * @private
730 */
731 static formatName_(projectId: string, name: string): string;
732}
733export {};