@google-cloud/pubsub 2.17.0 → 2.18.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/README.md +1 -0
- package/build/protos/protos.d.ts +2 -1
- package/build/protos/protos.js +7 -0
- package/build/protos/protos.json +14 -1
- package/build/src/iam.d.ts +180 -0
- package/build/src/iam.js +11 -176
- package/build/src/iam.js.map +1 -1
- package/build/src/index.d.ts +13 -4
- package/build/src/index.js +12 -4
- package/build/src/index.js.map +1 -1
- package/build/src/lease-manager.d.ts +7 -2
- package/build/src/lease-manager.js +19 -4
- package/build/src/lease-manager.js.map +1 -1
- package/build/src/publisher/flow-control.d.ts +90 -0
- package/build/src/publisher/flow-control.js +145 -0
- package/build/src/publisher/flow-control.js.map +1 -0
- package/build/src/publisher/flow-publisher.d.ts +95 -0
- package/build/src/publisher/flow-publisher.js +133 -0
- package/build/src/publisher/flow-publisher.js.map +1 -0
- package/build/src/publisher/index.d.ts +33 -5
- package/build/src/publisher/index.js +16 -39
- package/build/src/publisher/index.js.map +1 -1
- package/build/src/publisher/message-batch.d.ts +1 -1
- package/build/src/publisher/message-batch.js +4 -3
- package/build/src/publisher/message-batch.js.map +1 -1
- package/build/src/publisher/message-queues.js.map +1 -1
- package/build/src/publisher/pubsub-message.d.ts +52 -0
- package/build/src/publisher/pubsub-message.js +56 -0
- package/build/src/publisher/pubsub-message.js.map +1 -0
- package/build/src/pubsub.d.ts +354 -4
- package/build/src/pubsub.js +28 -322
- package/build/src/pubsub.js.map +1 -1
- package/build/src/schema.d.ts +9 -4
- package/build/src/schema.js +9 -4
- package/build/src/schema.js.map +1 -1
- package/build/src/snapshot.d.ts +87 -0
- package/build/src/snapshot.js +7 -83
- package/build/src/snapshot.js.map +1 -1
- package/build/src/subscriber.d.ts +6 -0
- package/build/src/subscriber.js +6 -0
- package/build/src/subscriber.js.map +1 -1
- package/build/src/subscription.d.ts +439 -9
- package/build/src/subscription.js +38 -404
- package/build/src/subscription.js.map +1 -1
- package/build/src/topic.d.ts +481 -1
- package/build/src/topic.js +51 -430
- package/build/src/topic.js.map +1 -1
- package/build/src/util.d.ts +2 -1
- package/build/src/util.js +2 -2
- package/build/src/util.js.map +1 -1
- package/build/src/v1/publisher_client.d.ts +246 -15
- package/build/src/v1/publisher_client.js +18 -264
- package/build/src/v1/publisher_client.js.map +1 -1
- package/build/src/v1/publisher_client_config.json +1 -1
- package/build/src/v1/schema_service_client.d.ts +151 -5
- package/build/src/v1/schema_service_client.js +6 -157
- package/build/src/v1/schema_service_client.js.map +1 -1
- package/build/src/v1/subscriber_client.d.ts +536 -16
- package/build/src/v1/subscriber_client.js +14 -552
- package/build/src/v1/subscriber_client.js.map +1 -1
- package/package.json +3 -3
package/build/src/topic.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ import { CallOptions } from 'google-gax';
|
|
|
18
18
|
import { google } from '../protos/protos';
|
|
19
19
|
import { IAM } from './iam';
|
|
20
20
|
import { Attributes, PublishCallback, Publisher, PublishOptions, PubsubMessage } from './publisher';
|
|
21
|
+
import { FlowControlledPublisher } from './publisher/flow-publisher';
|
|
21
22
|
import { EmptyCallback, EmptyResponse, ExistsCallback, ExistsResponse, ObjectStream, PagedResponse, PageOptions, PubSub, RequestCallback, ResourceCallback } from './pubsub';
|
|
22
23
|
import { CreateSubscriptionCallback, CreateSubscriptionOptions, CreateSubscriptionResponse, Subscription, SubscriptionOptions } from './subscription';
|
|
23
24
|
export declare type TopicMetadata = google.pubsub.v1.ITopic;
|
|
@@ -50,13 +51,17 @@ export declare type MessageOptions = PubsubMessage & {
|
|
|
50
51
|
* @param {PublishOptions} [options] Publisher configuration object.
|
|
51
52
|
*
|
|
52
53
|
* @example
|
|
54
|
+
* ```
|
|
53
55
|
* const {PubSub} = require('@google-cloud/pubsub');
|
|
54
56
|
* const pubsub = new PubSub();
|
|
55
57
|
*
|
|
56
58
|
* const topic = pubsub.topic('my-topic');
|
|
57
59
|
*
|
|
58
|
-
*
|
|
60
|
+
* ```
|
|
61
|
+
* @example To enable message ordering, set `enableMessageOrdering` to true. Please note that this does not persist to an actual topic.
|
|
62
|
+
* ```
|
|
59
63
|
* const topic = pubsub.topic('ordered-topic', {enableMessageOrdering: true});
|
|
64
|
+
* ```
|
|
60
65
|
*/
|
|
61
66
|
export declare class Topic {
|
|
62
67
|
name: string;
|
|
@@ -68,36 +73,456 @@ export declare class Topic {
|
|
|
68
73
|
publisher: Publisher;
|
|
69
74
|
getSubscriptionsStream: () => ObjectStream<Subscription>;
|
|
70
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
|
+
*/
|
|
71
84
|
flush(): Promise<void>;
|
|
72
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
|
+
*/
|
|
73
116
|
create(gaxOpts?: CallOptions): Promise<CreateTopicResponse>;
|
|
74
117
|
create(callback: CreateTopicCallback): void;
|
|
75
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
|
+
*/
|
|
76
158
|
createSubscription(name: string, callback: CreateSubscriptionCallback): void;
|
|
77
159
|
createSubscription(name: string, options?: CreateSubscriptionOptions): Promise<CreateSubscriptionResponse>;
|
|
78
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
|
+
*/
|
|
79
190
|
delete(callback: EmptyCallback): void;
|
|
80
191
|
delete(gaxOpts?: CallOptions): Promise<EmptyResponse>;
|
|
81
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
|
+
*/
|
|
82
225
|
exists(): Promise<ExistsResponse>;
|
|
83
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
|
+
*/
|
|
84
268
|
get(callback: GetTopicCallback): void;
|
|
85
269
|
get(gaxOpts?: GetTopicOptions): Promise<GetTopicResponse>;
|
|
86
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
|
+
*/
|
|
87
307
|
getMetadata(callback: GetTopicMetadataCallback): void;
|
|
88
308
|
getMetadata(gaxOpts: CallOptions, callback: GetTopicMetadataCallback): void;
|
|
89
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
|
+
*/
|
|
90
348
|
getSubscriptions(callback: GetTopicSubscriptionsCallback): void;
|
|
91
349
|
getSubscriptions(options: PageOptions, callback: GetTopicSubscriptionsCallback): void;
|
|
92
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
|
+
*/
|
|
93
396
|
publish(data: Buffer, attributes?: Attributes): Promise<string>;
|
|
94
397
|
publish(data: Buffer, callback: PublishCallback): void;
|
|
95
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
|
+
*/
|
|
96
448
|
publishJSON(json: object, attributes?: Attributes): Promise<string>;
|
|
97
449
|
publishJSON(json: object, callback: PublishCallback): void;
|
|
98
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
|
+
*/
|
|
99
510
|
publishMessage(message: MessageOptions): Promise<[string]>;
|
|
100
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;
|
|
101
526
|
/**
|
|
102
527
|
* In the event that the client fails to publish an ordered message, all
|
|
103
528
|
* subsequent publish calls using the same ordering key will fail. Calling
|
|
@@ -107,6 +532,7 @@ export declare class Topic {
|
|
|
107
532
|
* @param {string} orderingKey The ordering key in question.
|
|
108
533
|
*
|
|
109
534
|
* @example
|
|
535
|
+
* ```
|
|
110
536
|
* const {PubSub} = require('@google-cloud/pubsub');
|
|
111
537
|
* const pubsub = new PubSub();
|
|
112
538
|
* const topic = pubsub.topic('my-topic', {messageOrdering: true});
|
|
@@ -119,8 +545,56 @@ export declare class Topic {
|
|
|
119
545
|
* topic.resumePublishing(orderingKey);
|
|
120
546
|
* }
|
|
121
547
|
* });
|
|
548
|
+
* ```
|
|
122
549
|
*/
|
|
123
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
|
+
*/
|
|
124
598
|
setMetadata(options: TopicMetadata, gaxOpts?: CallOptions): Promise<SetTopicMetadataResponse>;
|
|
125
599
|
setMetadata(options: TopicMetadata, callback: SetTopicMetadataCallback): void;
|
|
126
600
|
setMetadata(options: TopicMetadata, gaxOpts: CallOptions, callback: SetTopicMetadataCallback): void;
|
|
@@ -130,6 +604,7 @@ export declare class Topic {
|
|
|
130
604
|
* @param {PublishOptions} options The publisher options.
|
|
131
605
|
*
|
|
132
606
|
* @example
|
|
607
|
+
* ```
|
|
133
608
|
* const {PubSub} = require('@google-cloud/pubsub');
|
|
134
609
|
* const pubsub = new PubSub();
|
|
135
610
|
*
|
|
@@ -140,6 +615,7 @@ export declare class Topic {
|
|
|
140
615
|
* maxMilliseconds: 10
|
|
141
616
|
* }
|
|
142
617
|
* });
|
|
618
|
+
* ```
|
|
143
619
|
*/
|
|
144
620
|
setPublishOptions(options: PublishOptions): void;
|
|
145
621
|
/**
|
|
@@ -147,6 +623,7 @@ export declare class Topic {
|
|
|
147
623
|
* back into {@link Topic#setPublishOptions}.
|
|
148
624
|
*
|
|
149
625
|
* @example
|
|
626
|
+
* ```
|
|
150
627
|
* const {PubSub} = require('@google-cloud/pubsub');
|
|
151
628
|
* const pubsub = new PubSub();
|
|
152
629
|
*
|
|
@@ -155,6 +632,7 @@ export declare class Topic {
|
|
|
155
632
|
* const defaults = topic.getPublishOptionDefaults();
|
|
156
633
|
* defaults.batching.maxMilliseconds = 10;
|
|
157
634
|
* topic.setPublishOptions(defaults);
|
|
635
|
+
* ```
|
|
158
636
|
*/
|
|
159
637
|
getPublishOptionDefaults(): PublishOptions;
|
|
160
638
|
/**
|
|
@@ -169,6 +647,7 @@ export declare class Topic {
|
|
|
169
647
|
* @return {Subscription}
|
|
170
648
|
*
|
|
171
649
|
* @example
|
|
650
|
+
* ```
|
|
172
651
|
* const {PubSub} = require('@google-cloud/pubsub');
|
|
173
652
|
* const pubsub = new PubSub();
|
|
174
653
|
*
|
|
@@ -184,6 +663,7 @@ export declare class Topic {
|
|
|
184
663
|
* // message.attributes = Attributes of the message.
|
|
185
664
|
* // message.publishTime = Timestamp when Pub/Sub received the message.
|
|
186
665
|
* });
|
|
666
|
+
* ```
|
|
187
667
|
*/
|
|
188
668
|
subscription(name: string, options?: SubscriptionOptions): Subscription;
|
|
189
669
|
/**
|