1 | /*!
|
2 | * Copyright 2017 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" />
|
17 | import { CallOptions } from 'google-gax';
|
18 | import { google } from '../protos/protos';
|
19 | import { IAM } from './iam';
|
20 | import { Attributes, PublishCallback, Publisher, PublishOptions, PubsubMessage } from './publisher';
|
21 | import { FlowControlledPublisher } from './publisher/flow-publisher';
|
22 | import { EmptyCallback, EmptyResponse, ExistsCallback, ExistsResponse, ObjectStream, PagedResponse, PageOptions, PubSub, RequestCallback, ResourceCallback } from './pubsub';
|
23 | import { CreateSubscriptionCallback, CreateSubscriptionOptions, CreateSubscriptionResponse, Subscription, SubscriptionOptions } from './subscription';
|
24 | export declare type TopicMetadata = google.pubsub.v1.ITopic;
|
25 | declare type TopicCallback = ResourceCallback<Topic, TopicMetadata>;
|
26 | declare type TopicResponse = [Topic, TopicMetadata];
|
27 | export declare type CreateTopicCallback = TopicCallback;
|
28 | export declare type CreateTopicResponse = TopicResponse;
|
29 | export declare type GetTopicCallback = TopicCallback;
|
30 | export declare type GetTopicResponse = TopicResponse;
|
31 | export declare type GetTopicOptions = CallOptions & {
|
32 | autoCreate?: boolean;
|
33 | };
|
34 | declare type MetadataCallback = RequestCallback<TopicMetadata>;
|
35 | declare type MetadataResponse = [TopicMetadata];
|
36 | export declare type GetTopicMetadataCallback = MetadataCallback;
|
37 | export declare type GetTopicMetadataResponse = MetadataResponse;
|
38 | export declare type SetTopicMetadataCallback = MetadataCallback;
|
39 | export declare type SetTopicMetadataResponse = MetadataResponse;
|
40 | export declare type GetTopicSubscriptionsCallback = RequestCallback<Subscription, google.pubsub.v1.IListTopicSubscriptionsResponse>;
|
41 | export declare type GetTopicSubscriptionsResponse = PagedResponse<Subscription, google.pubsub.v1.IListTopicSubscriptionsResponse>;
|
42 | export declare type MessageOptions = PubsubMessage & {
|
43 | json?: any;
|
44 | };
|
45 | /**
|
46 | * A Topic object allows you to interact with a Cloud Pub/Sub topic.
|
47 | *
|
48 | * @class
|
49 | * @param {PubSub} pubsub PubSub object.
|
50 | * @param {string} name Name of the topic.
|
51 | * @param {PublishOptions} [options] Publisher configuration object.
|
52 | *
|
53 | * @example
|
54 | * ```
|
55 | * const {PubSub} = require('@google-cloud/pubsub');
|
56 | * const pubsub = new PubSub();
|
57 | *
|
58 | * const topic = pubsub.topic('my-topic');
|
59 | *
|
60 | * ```
|
61 | * @example To enable message ordering, set `enableMessageOrdering` to true. Please note that this does not persist to an actual topic.
|
62 | * ```
|
63 | * const topic = pubsub.topic('ordered-topic', {enableMessageOrdering: true});
|
64 | * ```
|
65 | */
|
66 | export declare class Topic {
|
67 | name: string;
|
68 | parent: PubSub;
|
69 | pubsub: PubSub;
|
70 | request: typeof PubSub.prototype.request;
|
71 | iam: IAM;
|
72 | metadata?: TopicMetadata;
|
73 | publisher: Publisher;
|
74 | getSubscriptionsStream: () => ObjectStream<Subscription>;
|
75 | constructor(pubsub: PubSub, name: string, options?: PublishOptions);
|
76 | /**
|
77 | * Immediately sends all remaining queued data. This is mostly useful
|
78 | * if you are planning to call close() on the PubSub object that holds
|
79 | * the server connections.
|
80 | *
|
81 | * @param {EmptyCallback} [callback] Callback function.
|
82 | * @returns {Promise<EmptyResponse>}
|
83 | */
|
84 | flush(): Promise<void>;
|
85 | flush(callback: EmptyCallback): void;
|
86 | /**
|
87 | * Create a topic.
|
88 | *
|
89 | * @param {object} [gaxOpts] Request configuration options, outlined
|
90 | * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
|
91 | * @param {CreateTopicCallback} [callback] Callback function.
|
92 | * @returns {Promise<CreateTopicResponse>}
|
93 | *
|
94 | * @example
|
95 | * ```
|
96 | * const {PubSub} = require('@google-cloud/pubsub');
|
97 | * const pubsub = new PubSub();
|
98 | *
|
99 | * const topic = pubsub.topic('my-topic');
|
100 | *
|
101 | * topic.create((err, topic, apiResponse) => {
|
102 | * if (!err) {
|
103 | * // The topic was created successfully.
|
104 | * }
|
105 | * });
|
106 | *
|
107 | * //-
|
108 | * // If the callback is omitted, we'll return a Promise.
|
109 | * //-
|
110 | * topic.create().then((data) => {
|
111 | * const topic = data[0];
|
112 | * const apiResponse = data[1];
|
113 | * });
|
114 | * ```
|
115 | */
|
116 | create(gaxOpts?: CallOptions): Promise<CreateTopicResponse>;
|
117 | create(callback: CreateTopicCallback): void;
|
118 | create(gaxOpts: CallOptions, callback: CreateTopicCallback): void;
|
119 | /**
|
120 | * Create a subscription to this topic.
|
121 | *
|
122 | * @see [Subscriptions: create API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/create}
|
123 | *
|
124 | * @throws {Error} If subscription name is omitted.
|
125 | *
|
126 | * @param {string} name The name of the subscription.
|
127 | * @param {CreateSubscriptionRequest} [options] See a
|
128 | * [Subscription
|
129 | * resource](https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions).
|
130 | * @param {CreateSubscriptionCallback} [callback] Callback function.
|
131 | * @returns {Promise<CreateSubscriptionResponse>}
|
132 | *
|
133 | * @example
|
134 | * ```
|
135 | * const {PubSub} = require('@google-cloud/pubsub');
|
136 | * const pubsub = new PubSub();
|
137 | *
|
138 | * const topic = pubsub.topic('my-topic');
|
139 | * const callback = function(err, subscription, apiResponse) {};
|
140 | *
|
141 | * // Without specifying any options.
|
142 | * topic.createSubscription('newMessages', callback);
|
143 | *
|
144 | * // With options.
|
145 | * topic.createSubscription('newMessages', {
|
146 | * ackDeadlineSeconds: 90
|
147 | * }, callback);
|
148 | *
|
149 | * //-
|
150 | * // If the callback is omitted, we'll return a Promise.
|
151 | * //-
|
152 | * topic.createSubscription('newMessages').then((data) => {
|
153 | * const subscription = data[0];
|
154 | * const apiResponse = data[1];
|
155 | * });
|
156 | * ```
|
157 | */
|
158 | createSubscription(name: string, callback: CreateSubscriptionCallback): void;
|
159 | createSubscription(name: string, options?: CreateSubscriptionOptions): Promise<CreateSubscriptionResponse>;
|
160 | createSubscription(name: string, options: CreateSubscriptionOptions, callback: CreateSubscriptionCallback): void;
|
161 | /**
|
162 | * Delete the topic. This will not delete subscriptions to this topic.
|
163 | *
|
164 | * @see [Topics: delete API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics/delete}
|
165 | *
|
166 | * @param {object} [gaxOpts] Request configuration options, outlined
|
167 | * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
|
168 | * @param {function} [callback] The callback function.
|
169 | * @param {?error} callback.err An error returned while making this
|
170 | * request.
|
171 | * @param {object} callback.apiResponse Raw API response.
|
172 | *
|
173 | * @example
|
174 | * ```
|
175 | * const {PubSub} = require('@google-cloud/pubsub');
|
176 | * const pubsub = new PubSub();
|
177 | *
|
178 | * const topic = pubsub.topic('my-topic');
|
179 | *
|
180 | * topic.delete((err, apiResponse) => {});
|
181 | *
|
182 | * //-
|
183 | * // If the callback is omitted, we'll return a Promise.
|
184 | * //-
|
185 | * topic.delete().then((data) => {
|
186 | * const apiResponse = data[0];
|
187 | * });
|
188 | * ```
|
189 | */
|
190 | delete(callback: EmptyCallback): void;
|
191 | delete(gaxOpts?: CallOptions): Promise<EmptyResponse>;
|
192 | delete(gaxOpts: CallOptions, callback: EmptyCallback): void;
|
193 | /**
|
194 | * @typedef {array} TopicExistsResponse
|
195 | * @property {boolean} 0 Whether the topic exists
|
196 | */
|
197 | /**
|
198 | * @callback TopicExistsCallback
|
199 | * @param {?Error} err Request error, if any.
|
200 | * @param {boolean} exists Whether the topic exists.
|
201 | */
|
202 | /**
|
203 | * Check if a topic exists.
|
204 | *
|
205 | * @param {TopicExistsCallback} [callback] Callback function.
|
206 | * @returns {Promise<TopicExistsResponse>}
|
207 | *
|
208 | * @example
|
209 | * ```
|
210 | * const {PubSub} = require('@google-cloud/pubsub');
|
211 | * const pubsub = new PubSub();
|
212 | *
|
213 | * const topic = pubsub.topic('my-topic');
|
214 | *
|
215 | * topic.exists((err, exists) => {});
|
216 | *
|
217 | * //-
|
218 | * // If the callback is omitted, we'll return a Promise.
|
219 | * //-
|
220 | * topic.exists().then((data) => {
|
221 | * const exists = data[0];
|
222 | * });
|
223 | * ```
|
224 | */
|
225 | exists(): Promise<ExistsResponse>;
|
226 | exists(callback: ExistsCallback): void;
|
227 | /**
|
228 | * @typedef {array} GetTopicResponse
|
229 | * @property {Topic} 0 The {@link Topic}.
|
230 | * @property {object} 1 The full API response.
|
231 | */
|
232 | /**
|
233 | * @callback GetTopicCallback
|
234 | * @param {?Error} err Request error, if any.
|
235 | * @param {Topic} topic The {@link Topic}.
|
236 | * @param {object} apiResponse The full API response.
|
237 | */
|
238 | /**
|
239 | * Get a topic if it exists.
|
240 | *
|
241 | * @param {object} [gaxOpts] Request configuration options, outlined
|
242 | * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
|
243 | * @param {boolean} [gaxOpts.autoCreate=false] Automatically create the topic
|
244 | * does not already exist.
|
245 | * @param {GetTopicCallback} [callback] Callback function.
|
246 | * @returns {Promise<GetTopicResponse>}
|
247 | *
|
248 | * @example
|
249 | * ```
|
250 | * const {PubSub} = require('@google-cloud/pubsub');
|
251 | * const pubsub = new PubSub();
|
252 | *
|
253 | * const topic = pubsub.topic('my-topic');
|
254 | *
|
255 | * topic.get((err, topic, apiResponse) => {
|
256 | * // The `topic` data has been populated.
|
257 | * });
|
258 | *
|
259 | * //-
|
260 | * // If the callback is omitted, we'll return a Promise.
|
261 | * //-
|
262 | * topic.get().then((data) => {
|
263 | * const topic = data[0];
|
264 | * const apiResponse = data[1];
|
265 | * });
|
266 | * ```
|
267 | */
|
268 | get(callback: GetTopicCallback): void;
|
269 | get(gaxOpts?: GetTopicOptions): Promise<GetTopicResponse>;
|
270 | get(gaxOpts: GetTopicOptions, callback: GetTopicCallback): void;
|
271 | /**
|
272 | * @typedef {array} GetTopicMetadataResponse
|
273 | * @property {object} 0 The full API response.
|
274 | */
|
275 | /**
|
276 | * @callback GetTopicMetadataCallback
|
277 | * @param {?Error} err Request error, if any.
|
278 | * @param {object} apiResponse The full API response.
|
279 | */
|
280 | /**
|
281 | * Get the official representation of this topic from the API.
|
282 | *
|
283 | * @see [Topics: get API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics/get}
|
284 | *
|
285 | * @param {object} [gaxOpts] Request configuration options, outlined
|
286 | * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
|
287 | * @param {GetTopicMetadataCallback} [callback] Callback function.
|
288 | * @returns {Promise<GetTopicMetadataResponse>}
|
289 | *
|
290 | * @example
|
291 | * ```
|
292 | * const {PubSub} = require('@google-cloud/pubsub');
|
293 | * const pubsub = new PubSub();
|
294 | *
|
295 | * const topic = pubsub.topic('my-topic');
|
296 | *
|
297 | * topic.getMetadata((err, apiResponse) => {});
|
298 | *
|
299 | * //-
|
300 | * // If the callback is omitted, we'll return a Promise.
|
301 | * //-
|
302 | * topic.getMetadata().then((data) => {
|
303 | * const apiResponse = data[0];
|
304 | * });
|
305 | * ```
|
306 | */
|
307 | getMetadata(callback: GetTopicMetadataCallback): void;
|
308 | getMetadata(gaxOpts: CallOptions, callback: GetTopicMetadataCallback): void;
|
309 | getMetadata(gaxOpts?: CallOptions): Promise<GetTopicMetadataResponse>;
|
310 | /**
|
311 | * Get a list of the subscriptions registered to this topic. You may
|
312 | * optionally provide a query object as the first argument to customize the
|
313 | * response.
|
314 | *
|
315 | * Your provided callback will be invoked with an error object if an API error
|
316 | * occurred or an array of {module:pubsub/subscription} objects.
|
317 | *
|
318 | * @see [Subscriptions: list API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics.subscriptions/list}
|
319 | *
|
320 | * @param {GetSubscriptionsRequest} [query] Query object for listing subscriptions.
|
321 | * @param {GetSubscriptionsCallback} [callback] Callback function.
|
322 | * @returns {Promise<GetSubscriptionsResponse>}
|
323 | *
|
324 | * @example
|
325 | * ```
|
326 | * const {PubSub} = require('@google-cloud/pubsub');
|
327 | * const pubsub = new PubSub();
|
328 | *
|
329 | * const topic = pubsub.topic('my-topic');
|
330 | *
|
331 | * topic.getSubscriptions((err, subscriptions) => {
|
332 | * // subscriptions is an array of `Subscription` objects.
|
333 | * });
|
334 | *
|
335 | * // Customize the query.
|
336 | * topic.getSubscriptions({
|
337 | * pageSize: 3
|
338 | * }, callback);
|
339 | *
|
340 | * //-
|
341 | * // If the callback is omitted, we'll return a Promise.
|
342 | * //-
|
343 | * topic.getSubscriptions().then((data) => {
|
344 | * const subscriptions = data[0];
|
345 | * });
|
346 | * ```
|
347 | */
|
348 | getSubscriptions(callback: GetTopicSubscriptionsCallback): void;
|
349 | getSubscriptions(options: PageOptions, callback: GetTopicSubscriptionsCallback): void;
|
350 | getSubscriptions(options?: PageOptions): Promise<GetTopicSubscriptionsResponse>;
|
351 | /**
|
352 | * Publish the provided message.
|
353 | *
|
354 | * @deprecated Please use {@link Topic#publishMessage}.
|
355 | *
|
356 | * @throws {TypeError} If data is not a Buffer object.
|
357 | * @throws {TypeError} If any value in `attributes` object is not a string.
|
358 | *
|
359 | * @param {buffer} data The message data. This must come in the form of a
|
360 | * Buffer object.
|
361 | * @param {object.<string, string>} [attributes] Attributes for this message.
|
362 | * @param {PublishCallback} [callback] Callback function.
|
363 | * @returns {Promise<PublishResponse>}
|
364 | *
|
365 | * @example
|
366 | * ```
|
367 | * const {PubSub} = require('@google-cloud/pubsub');
|
368 | * const pubsub = new PubSub();
|
369 | *
|
370 | * const topic = pubsub.topic('my-topic');
|
371 | * const data = Buffer.from('Hello, world!');
|
372 | *
|
373 | * const callback = (err, messageId) => {
|
374 | * if (err) {
|
375 | * // Error handling omitted.
|
376 | * }
|
377 | * };
|
378 | *
|
379 | * topic.publish(data, callback);
|
380 | *
|
381 | * ```
|
382 | * @example Optionally you can provide an object containing attributes for the message. Note that all values in the object must be strings.
|
383 | * ```
|
384 | * const attributes = {
|
385 | * key: 'value'
|
386 | * };
|
387 | *
|
388 | * topic.publish(data, attributes, callback);
|
389 | *
|
390 | * ```
|
391 | * @example If the callback is omitted, we'll return a Promise.
|
392 | * ```
|
393 | * topic.publish(data).then((messageId) => {});
|
394 | * ```
|
395 | */
|
396 | publish(data: Buffer, attributes?: Attributes): Promise<string>;
|
397 | publish(data: Buffer, callback: PublishCallback): void;
|
398 | publish(data: Buffer, attributes: Attributes, callback: PublishCallback): void;
|
399 | /**
|
400 | * Publish the provided JSON. It should be noted that all messages published
|
401 | * are done so in the form of a Buffer. This is simply a convenience method
|
402 | * that will transform JSON into a Buffer before publishing.
|
403 | * {@link Subscription} objects will always return message data in the form of
|
404 | * a Buffer, so any JSON published will require manual deserialization.
|
405 | *
|
406 | * @deprecated Please use the `json` option via {@link Topic#publishMessage}.
|
407 | *
|
408 | * @throws {Error} If non-object data is provided.
|
409 | *
|
410 | * @param {object} json The JSON data to publish.
|
411 | * @param {object} [attributes] Attributes for this message.
|
412 | * @param {PublishCallback} [callback] Callback function.
|
413 | * @returns {Promise<PublishResponse>}
|
414 | *
|
415 | * @example
|
416 | * ```
|
417 | * const {PubSub} = require('@google-cloud/pubsub');
|
418 | * const pubsub = new PubSub();
|
419 | * const topic = pubsub.topic('my-topic');
|
420 | *
|
421 | * const data = {
|
422 | * foo: 'bar'
|
423 | * };
|
424 | *
|
425 | * const callback = (err, messageId) => {
|
426 | * if (err) {
|
427 | * // Error handling omitted.
|
428 | * }
|
429 | * };
|
430 | *
|
431 | * topic.publishJSON(data, callback);
|
432 | *
|
433 | * ```
|
434 | * @example Optionally you can provide an object containing attributes for the message. Note that all values in the object must be strings.
|
435 | * ```
|
436 | * const attributes = {
|
437 | * key: 'value'
|
438 | * };
|
439 | *
|
440 | * topic.publishJSON(data, attributes, callback);
|
441 | *
|
442 | * ```
|
443 | * @example If the callback is omitted, we'll return a Promise.
|
444 | * ```
|
445 | * topic.publishJSON(data).then((messageId) => {});
|
446 | * ```
|
447 | */
|
448 | publishJSON(json: object, attributes?: Attributes): Promise<string>;
|
449 | publishJSON(json: object, callback: PublishCallback): void;
|
450 | publishJSON(json: object, attributes: Attributes, callback: PublishCallback): void;
|
451 | /**
|
452 | * @typedef {object} MessageOptions
|
453 | * @property {buffer} [data] The message data.
|
454 | * @property {object} [json] Convenience property to publish JSON data. This
|
455 | * will transform the provided JSON into a Buffer before publishing.
|
456 | * {@link Subscription} objects will always return message data in the
|
457 | * form of a Buffer, so any JSON published will require manual
|
458 | * deserialization.
|
459 | * @property {object.<string, string>} [attributes] Attributes for this
|
460 | * message.
|
461 | * @property {string} [orderingKey] A message ordering key.
|
462 | */
|
463 | /**
|
464 | * Publish the provided message.
|
465 | *
|
466 | * @throws {TypeError} If data is not a Buffer object.
|
467 | * @throws {TypeError} If any value in `attributes` object is not a string.
|
468 | *
|
469 | * @param {MessageOptions} message Message object.
|
470 | * @param {PublishCallback} [callback] Callback function.
|
471 | * @returns {Promise<PublishResponse>}
|
472 | *
|
473 | * @example
|
474 | * ```
|
475 | * const {PubSub} = require('@google-cloud/pubsub');
|
476 | * const pubsub = new PubSub();
|
477 | * const topic = pubsub.topic('my-topic');
|
478 | *
|
479 | * const data = Buffer.from('Hello, world!');
|
480 | *
|
481 | * const callback = (err, messageId) => {
|
482 | * if (err) {
|
483 | * // Error handling omitted.
|
484 | * }
|
485 | * };
|
486 | *
|
487 | * topic.publishMessage({data}, callback);
|
488 | *
|
489 | * ```
|
490 | * @example Publish JSON message data.
|
491 | * ```
|
492 | * const json = {foo: 'bar'};
|
493 | *
|
494 | * topic.publishMessage({json}, callback);
|
495 | *
|
496 | * ```
|
497 | * @example To publish messages in order (this is still experimental), make sure message ordering is enabled and provide an ordering key
|
498 | * ```
|
499 | * const topic = pubsub.topic('ordered-topic', {messageOrdering: true});
|
500 | * const orderingKey = 'my-key';
|
501 | *
|
502 | * topic.publishMessage({data, orderingKey}, callback);
|
503 | *
|
504 | * ```
|
505 | * @example If the callback is omitted, we'll return a Promise.
|
506 | * ```
|
507 | * const [messageId] = await topic.publishMessage({data});
|
508 | * ```
|
509 | */
|
510 | publishMessage(message: MessageOptions): Promise<string>;
|
511 | publishMessage(message: MessageOptions, callback: PublishCallback): void;
|
512 | /**
|
513 | * Creates a FlowControlledPublisher for this Topic.
|
514 | *
|
515 | * FlowControlledPublisher is a helper that lets you control how many messages
|
516 | * are simultaneously queued to send, to avoid ballooning memory usage on
|
517 | * a low bandwidth connection to Pub/Sub.
|
518 | *
|
519 | * Note that it's perfectly fine to create more than one on the same Topic.
|
520 | * The actual flow control settings on the Topic will apply across all
|
521 | * FlowControlledPublisher objects on that Topic.
|
522 | *
|
523 | * @returns {FlowControlledPublisher} The flow control helper.
|
524 | */
|
525 | flowControlled(): FlowControlledPublisher;
|
526 | /**
|
527 | * In the event that the client fails to publish an ordered message, all
|
528 | * subsequent publish calls using the same ordering key will fail. Calling
|
529 | * this method will disregard the publish failure, allowing the supplied
|
530 | * ordering key to be used again in the future.
|
531 | *
|
532 | * @param {string} orderingKey The ordering key in question.
|
533 | *
|
534 | * @example
|
535 | * ```
|
536 | * const {PubSub} = require('@google-cloud/pubsub');
|
537 | * const pubsub = new PubSub();
|
538 | * const topic = pubsub.topic('my-topic', {messageOrdering: true});
|
539 | *
|
540 | * const orderingKey = 'foo';
|
541 | * const data = Buffer.from('Hello, order!');
|
542 | *
|
543 | * topic.publishMessage({data, orderingKey}, err => {
|
544 | * if (err) {
|
545 | * topic.resumePublishing(orderingKey);
|
546 | * }
|
547 | * });
|
548 | * ```
|
549 | */
|
550 | resumePublishing(orderingKey: string): void;
|
551 | /**
|
552 | * @typedef {array} SetTopicMetadataResponse
|
553 | * @property {object} 0 The full API response.
|
554 | */
|
555 | /**
|
556 | * @callback SetTopicMetadataCallback
|
557 | * @param {?Error} err Request error, if any.
|
558 | * @param {object} apiResponse The full API response.
|
559 | */
|
560 | /**
|
561 | * Updates the topic.
|
562 | *
|
563 | * @see [UpdateTopicRequest API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rpc/google.pubsub.v1#google.pubsub.v1.UpdateTopicRequest}
|
564 | *
|
565 | * @param {object} metadata The fields to update. This should be structured
|
566 | * like a {@link
|
567 | * https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics#Topic|Topic
|
568 | * object}.
|
569 | * @param {object} [gaxOpts] Request configuration options, outlined
|
570 | * here: https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html.
|
571 | * @param {SetTopicMetadataCallback} [callback] Callback function.
|
572 | * @returns {Promise<SetTopicMetadataResponse>}
|
573 | *
|
574 | * @example
|
575 | * ```
|
576 | * const {PubSub} = require('@google-cloud/pubsub');
|
577 | * const pubsub = new PubSub();
|
578 | *
|
579 | * const topic = pubsub.topic('my-topic');
|
580 | * const metadata = {
|
581 | * labels: {foo: 'bar'}
|
582 | * };
|
583 | *
|
584 | * topic.setMetadata(metadata, err => {
|
585 | * if (err) {
|
586 | * // Error handling omitted.
|
587 | * }
|
588 | * });
|
589 | *
|
590 | * ```
|
591 | * @example If the callback is omitted, we'll return a Promise.
|
592 | * ```
|
593 | * topic.setMetadata(metadata).then((data) => {
|
594 | * const apiResponse = data[0];
|
595 | * });
|
596 | * ```
|
597 | */
|
598 | setMetadata(options: TopicMetadata, gaxOpts?: CallOptions): Promise<SetTopicMetadataResponse>;
|
599 | setMetadata(options: TopicMetadata, callback: SetTopicMetadataCallback): void;
|
600 | setMetadata(options: TopicMetadata, gaxOpts: CallOptions, callback: SetTopicMetadataCallback): void;
|
601 | /**
|
602 | * Set the publisher options.
|
603 | *
|
604 | * @param {PublishOptions} options The publisher options.
|
605 | *
|
606 | * @example
|
607 | * ```
|
608 | * const {PubSub} = require('@google-cloud/pubsub');
|
609 | * const pubsub = new PubSub();
|
610 | *
|
611 | * const topic = pubsub.topic('my-topic');
|
612 | *
|
613 | * topic.setPublishOptions({
|
614 | * batching: {
|
615 | * maxMilliseconds: 10
|
616 | * }
|
617 | * });
|
618 | * ```
|
619 | */
|
620 | setPublishOptions(options: PublishOptions): void;
|
621 | /**
|
622 | * Get the default publisher options. These may be modified and passed
|
623 | * back into {@link Topic#setPublishOptions}.
|
624 | *
|
625 | * @example
|
626 | * ```
|
627 | * const {PubSub} = require('@google-cloud/pubsub');
|
628 | * const pubsub = new PubSub();
|
629 | *
|
630 | * const topic = pubsub.topic('my-topic');
|
631 | *
|
632 | * const defaults = topic.getPublishOptionDefaults();
|
633 | * defaults.batching.maxMilliseconds = 10;
|
634 | * topic.setPublishOptions(defaults);
|
635 | * ```
|
636 | */
|
637 | getPublishOptionDefaults(): PublishOptions;
|
638 | /**
|
639 | * Create a Subscription object. This command by itself will not run any API
|
640 | * requests. You will receive a {module:pubsub/subscription} object,
|
641 | * which will allow you to interact with a subscription.
|
642 | *
|
643 | * @throws {Error} If subscription name is omitted.
|
644 | *
|
645 | * @param {string} name Name of the subscription.
|
646 | * @param {SubscriberOptions} [options] Configuration object.
|
647 | * @return {Subscription}
|
648 | *
|
649 | * @example
|
650 | * ```
|
651 | * const {PubSub} = require('@google-cloud/pubsub');
|
652 | * const pubsub = new PubSub();
|
653 | *
|
654 | * const topic = pubsub.topic('my-topic');
|
655 | * const subscription = topic.subscription('my-subscription');
|
656 | *
|
657 | * // Register a listener for `message` events.
|
658 | * subscription.on('message', (message) => {
|
659 | * // Called every time a message is received.
|
660 | * // message.id = ID of the message.
|
661 | * // message.ackId = ID used to acknowledge the message receival.
|
662 | * // message.data = Contents of the message.
|
663 | * // message.attributes = Attributes of the message.
|
664 | * // message.publishTime = Timestamp when Pub/Sub received the message.
|
665 | * });
|
666 | * ```
|
667 | */
|
668 | subscription(name: string, options?: SubscriptionOptions): Subscription;
|
669 | /**
|
670 | * Format the name of a topic. A Topic's full name is in the format of
|
671 | * 'projects/{projectId}/topics/{topicName}'.
|
672 | *
|
673 | * @private
|
674 | *
|
675 | * @return {string}
|
676 | */
|
677 | static formatName_(projectId: string, name: string): string;
|
678 | }
|
679 | export { PublishOptions };
|