UNPKG

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