@google-cloud/pubsub 2.16.6 → 2.18.2

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.
Files changed (62) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +54 -53
  3. package/build/protos/protos.d.ts +2 -1
  4. package/build/protos/protos.js +7 -0
  5. package/build/protos/protos.json +14 -1
  6. package/build/src/iam.d.ts +180 -0
  7. package/build/src/iam.js +11 -176
  8. package/build/src/iam.js.map +1 -1
  9. package/build/src/index.d.ts +13 -4
  10. package/build/src/index.js +12 -4
  11. package/build/src/index.js.map +1 -1
  12. package/build/src/lease-manager.d.ts +7 -2
  13. package/build/src/lease-manager.js +19 -4
  14. package/build/src/lease-manager.js.map +1 -1
  15. package/build/src/publisher/flow-control.d.ts +90 -0
  16. package/build/src/publisher/flow-control.js +145 -0
  17. package/build/src/publisher/flow-control.js.map +1 -0
  18. package/build/src/publisher/flow-publisher.d.ts +95 -0
  19. package/build/src/publisher/flow-publisher.js +133 -0
  20. package/build/src/publisher/flow-publisher.js.map +1 -0
  21. package/build/src/publisher/index.d.ts +33 -5
  22. package/build/src/publisher/index.js +16 -39
  23. package/build/src/publisher/index.js.map +1 -1
  24. package/build/src/publisher/message-batch.d.ts +1 -1
  25. package/build/src/publisher/message-batch.js +4 -3
  26. package/build/src/publisher/message-batch.js.map +1 -1
  27. package/build/src/publisher/message-queues.js.map +1 -1
  28. package/build/src/publisher/pubsub-message.d.ts +52 -0
  29. package/build/src/publisher/pubsub-message.js +56 -0
  30. package/build/src/publisher/pubsub-message.js.map +1 -0
  31. package/build/src/pubsub.d.ts +354 -4
  32. package/build/src/pubsub.js +28 -322
  33. package/build/src/pubsub.js.map +1 -1
  34. package/build/src/schema.d.ts +9 -4
  35. package/build/src/schema.js +9 -4
  36. package/build/src/schema.js.map +1 -1
  37. package/build/src/snapshot.d.ts +87 -0
  38. package/build/src/snapshot.js +7 -83
  39. package/build/src/snapshot.js.map +1 -1
  40. package/build/src/subscriber.d.ts +6 -0
  41. package/build/src/subscriber.js +6 -0
  42. package/build/src/subscriber.js.map +1 -1
  43. package/build/src/subscription.d.ts +439 -9
  44. package/build/src/subscription.js +38 -404
  45. package/build/src/subscription.js.map +1 -1
  46. package/build/src/topic.d.ts +481 -1
  47. package/build/src/topic.js +51 -430
  48. package/build/src/topic.js.map +1 -1
  49. package/build/src/util.d.ts +2 -1
  50. package/build/src/util.js +2 -2
  51. package/build/src/util.js.map +1 -1
  52. package/build/src/v1/publisher_client.d.ts +262 -0
  53. package/build/src/v1/publisher_client.js +11 -244
  54. package/build/src/v1/publisher_client.js.map +1 -1
  55. package/build/src/v1/publisher_client_config.json +2 -2
  56. package/build/src/v1/schema_service_client.d.ts +165 -0
  57. package/build/src/v1/schema_service_client.js +7 -153
  58. package/build/src/v1/schema_service_client.js.map +1 -1
  59. package/build/src/v1/subscriber_client.d.ts +566 -0
  60. package/build/src/v1/subscriber_client.js +11 -534
  61. package/build/src/v1/subscriber_client.js.map +1 -1
  62. package/package.json +2 -2
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright 2021 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.FlowControl = void 0;
19
+ const defer = require("p-defer");
20
+ /**
21
+ * Manages flow control handling for max bytes and messages.
22
+ *
23
+ * Do not use this class externally, it may change without warning.
24
+ * @private
25
+ *
26
+ */
27
+ class FlowControl {
28
+ constructor(options) {
29
+ this.options = {};
30
+ this.setOptions(options);
31
+ this.bytes = this.messages = 0;
32
+ this.requests = [];
33
+ }
34
+ /**
35
+ * Update our options after the fact.
36
+ *
37
+ * Do not use externally, it may change without warning.
38
+ * @private
39
+ */
40
+ setOptions(options) {
41
+ this.options = options;
42
+ if (this.options.maxOutstandingBytes === 0 ||
43
+ this.options.maxOutstandingMessages === 0) {
44
+ // Undefined is okay, but if either is zero, no publishes ever happen.
45
+ throw new Error('When using publisher flow control, maxOutstandingBytes and maxOutstandingMessages must not be zero');
46
+ }
47
+ }
48
+ /**
49
+ * @returns {number} The number of bytes that are queued up.
50
+ */
51
+ get currentByteCount() {
52
+ return this.bytes;
53
+ }
54
+ /**
55
+ * @returns {number} The number of messages that are queued up.
56
+ */
57
+ get currentMessageCount() {
58
+ return this.messages;
59
+ }
60
+ /**
61
+ * Adds the specified number of bytes or messages to our count. We'll
62
+ * assume that this is end running around our queueing mechanisms.
63
+ *
64
+ * @param {number} bytes The number of bytes to add to the count.
65
+ * @param {number} messages The number of messages to add to the count.
66
+ */
67
+ addToCount(bytes, messages) {
68
+ this.bytes += bytes;
69
+ this.messages += messages;
70
+ }
71
+ /**
72
+ * Attempts to queue the specified number of bytes and messages. If
73
+ * there are too many things in the publisher flow control queue
74
+ * already, we will defer and come back to it.
75
+ *
76
+ * Do not use externally, it may change without warning.
77
+ * @private
78
+ */
79
+ async willSend(bytes, messages) {
80
+ // Add this to our queue size.
81
+ this.bytes += bytes;
82
+ this.messages += messages;
83
+ // If this request won't fit, we have to put it in the queue.
84
+ if (this.exceeded()) {
85
+ const promise = defer();
86
+ this.requests.push({
87
+ promise: promise.promise,
88
+ resolve: promise.resolve,
89
+ reject: promise.reject,
90
+ bytes,
91
+ messageCount: messages,
92
+ });
93
+ // This will pass through when someone else's this.sent() completes.
94
+ await promise.promise;
95
+ }
96
+ }
97
+ /**
98
+ * Removes the specified number of bytes and messages from our queued
99
+ * counts, after a deferred request was released. If there is enough
100
+ * space.
101
+ *
102
+ * Do not use externally, it may change without warning.
103
+ * @private
104
+ */
105
+ sent(bytes, messages) {
106
+ this.bytes -= bytes;
107
+ this.messages -= messages;
108
+ // This shouldn't happen, but just be sure.
109
+ if (this.bytes < 0)
110
+ this.bytes = 0;
111
+ if (this.messages < 0)
112
+ this.messages = 0;
113
+ // Let things waiting on willSend() have a go, if there's space.
114
+ if (this.requests.length > 0 && !this.exceeded()) {
115
+ const next = this.requests.shift();
116
+ next.resolve();
117
+ }
118
+ }
119
+ // Just uses wouldExceed() to see if we've already exceeded the limits.
120
+ exceeded() {
121
+ return this.wouldExceed(0, 0);
122
+ }
123
+ /**
124
+ * Returns true if adding the specified number of bytes or messages
125
+ * would exceed limits imposed by configuration.
126
+ *
127
+ * Do not use externally, it may change without warning.
128
+ * @private
129
+ */
130
+ wouldExceed(bytes, messages) {
131
+ const totalBytes = this.bytes + bytes;
132
+ const totalMessages = this.messages + messages;
133
+ if (this.options.maxOutstandingBytes !== undefined &&
134
+ totalBytes > this.options.maxOutstandingBytes) {
135
+ return true;
136
+ }
137
+ if (this.options.maxOutstandingMessages !== undefined &&
138
+ totalMessages > this.options.maxOutstandingMessages) {
139
+ return true;
140
+ }
141
+ return false;
142
+ }
143
+ }
144
+ exports.FlowControl = FlowControl;
145
+ //# sourceMappingURL=flow-control.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow-control.js","sourceRoot":"","sources":["../../../src/publisher/flow-control.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,iCAAiC;AAyBjC;;;;;;GAMG;AACH,MAAa,WAAW;IAMtB,YAAY,OAA2B;QALvC,YAAO,GAAuB,EAAE,CAAC;QAM/B,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;IACrB,CAAC;IAED;;;;;OAKG;IACH,UAAU,CAAC,OAA2B;QACp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CAAC;QAE1B,2CAA2C;QAC3C,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC;YAAE,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;QACnC,IAAI,IAAI,CAAC,QAAQ,GAAG,CAAC;YAAE,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC;QAEzC,gEAAgE;QAChE,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE;YAChD,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAG,CAAC;YACpC,IAAI,CAAC,OAAO,EAAE,CAAC;SAChB;IACH,CAAC;IAED,uEAAuE;IAC/D,QAAQ;QACd,OAAO,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAChC,CAAC;IAED;;;;;;OAMG;IACH,WAAW,CAAC,KAAa,EAAE,QAAgB;QACzC,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACtC,MAAM,aAAa,GAAG,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAE/C,IACE,IAAI,CAAC,OAAO,CAAC,mBAAmB,KAAK,SAAS;YAC9C,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,mBAAmB,EAC7C;YACA,OAAO,IAAI,CAAC;SACb;QAED,IACE,IAAI,CAAC,OAAO,CAAC,sBAAsB,KAAK,SAAS;YACjD,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,sBAAsB,EACnD;YACA,OAAO,IAAI,CAAC;SACb;QAED,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AA9ID,kCA8IC"}
@@ -0,0 +1,95 @@
1
+ /*!
2
+ * Copyright 2021 Google LLC
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
+ import { Publisher } from '.';
17
+ import { PubsubMessage } from './pubsub-message';
18
+ /**
19
+ * Encapsulates a series of message publishes from a rapid loop (or similar
20
+ * circumstance).
21
+ *
22
+ * This class is not meant to be instantiated outside of the `@google-cloud/pubsub`
23
+ * package. It is returned from {@link Topic#flowControlled}. Messages sent
24
+ * through an instance of this class will obey publisher flow control
25
+ * settings set through {@link PublisherOptions} on {@link Topic}, across
26
+ * all instances returned by {@link Topic#flowControlled} on that {@link Topic}.
27
+ */
28
+ export declare class FlowControlledPublisher {
29
+ private publisher;
30
+ private flowControl;
31
+ private idPromises;
32
+ constructor(publisher: Publisher);
33
+ /**
34
+ * Returns true if sending the specified Buffer would result in exceeding the
35
+ * limits of the flow control settings.
36
+ *
37
+ * @param {PubsubMessage} message The data buffer with the message's contents.
38
+ * @returns {boolean} True if the message would exceed flow control limits.
39
+ */
40
+ wouldExceed(message: PubsubMessage): boolean;
41
+ /**
42
+ * Publishes a message, subject to flow control restrictions.
43
+ *
44
+ * If the message can be sent immediately, this will return `null`. Otherwise,
45
+ * it will return a Promise<void> that resolves after it's okay to resume
46
+ * calling the method.
47
+ *
48
+ * @param {Buffer} [data] The message contents to be sent.
49
+ * @param {Attributes} [attributes] Optional attributes.
50
+ * @returns null, or a Promise that resolves when sending may resume.
51
+ *
52
+ * @example
53
+ * ```
54
+ * const wait = flowControlled.publish({data});
55
+ * if (wait) {
56
+ * await wait;
57
+ * }
58
+ *
59
+ * ```
60
+ * @example
61
+ * ```
62
+ * // It's okay to await unconditionally, it's equivalent to nextTick().
63
+ * await flowControlled.publish(data);
64
+ * ```
65
+ */
66
+ publish(message: PubsubMessage): Promise<void> | null;
67
+ /**
68
+ * Publishes a message unconditionally, updating flow control counters.
69
+ *
70
+ * You'll generally only want to use this if you want to deal with timing the
71
+ * flow control yourself, but you'd like the library to do the bean counting.
72
+ *
73
+ * @param {Buffer} [data] The message contents to be sent.
74
+ * @param {Attributes} [attributes] Optional attributes.
75
+ *
76
+ * @example
77
+ * ```
78
+ * if (!flowControlled.wouldExceed(data)) {
79
+ * flowControlled.publishNow(data);
80
+ * }
81
+ * ```
82
+ */
83
+ publishNow(message: PubsubMessage): void;
84
+ private doPublish;
85
+ /**
86
+ * Returns a Promise that will resolve to all of the currently sent
87
+ * message IDs (or reject if there is an error). This also clears
88
+ * out any currently sent messages, so the next call to `all()` will
89
+ * be a clean slate.
90
+ *
91
+ * @returns {Promise<string[]>} A Promise that resolves when all current
92
+ * messages are sent.
93
+ */
94
+ all(): Promise<string[]>;
95
+ }
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright 2021 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.FlowControlledPublisher = void 0;
19
+ const pubsub_message_1 = require("./pubsub-message");
20
+ /**
21
+ * Encapsulates a series of message publishes from a rapid loop (or similar
22
+ * circumstance).
23
+ *
24
+ * This class is not meant to be instantiated outside of the `@google-cloud/pubsub`
25
+ * package. It is returned from {@link Topic#flowControlled}. Messages sent
26
+ * through an instance of this class will obey publisher flow control
27
+ * settings set through {@link PublisherOptions} on {@link Topic}, across
28
+ * all instances returned by {@link Topic#flowControlled} on that {@link Topic}.
29
+ */
30
+ class FlowControlledPublisher {
31
+ constructor(publisher) {
32
+ this.publisher = publisher;
33
+ this.flowControl = this.publisher.flowControl;
34
+ this.idPromises = [];
35
+ }
36
+ /**
37
+ * Returns true if sending the specified Buffer would result in exceeding the
38
+ * limits of the flow control settings.
39
+ *
40
+ * @param {PubsubMessage} message The data buffer with the message's contents.
41
+ * @returns {boolean} True if the message would exceed flow control limits.
42
+ */
43
+ wouldExceed(message) {
44
+ return this.flowControl.wouldExceed(pubsub_message_1.calculateMessageSize(message), 1);
45
+ }
46
+ /**
47
+ * Publishes a message, subject to flow control restrictions.
48
+ *
49
+ * If the message can be sent immediately, this will return `null`. Otherwise,
50
+ * it will return a Promise<void> that resolves after it's okay to resume
51
+ * calling the method.
52
+ *
53
+ * @param {Buffer} [data] The message contents to be sent.
54
+ * @param {Attributes} [attributes] Optional attributes.
55
+ * @returns null, or a Promise that resolves when sending may resume.
56
+ *
57
+ * @example
58
+ * ```
59
+ * const wait = flowControlled.publish({data});
60
+ * if (wait) {
61
+ * await wait;
62
+ * }
63
+ *
64
+ * ```
65
+ * @example
66
+ * ```
67
+ * // It's okay to await unconditionally, it's equivalent to nextTick().
68
+ * await flowControlled.publish(data);
69
+ * ```
70
+ */
71
+ publish(message) {
72
+ const doPublish = () => {
73
+ this.doPublish(message);
74
+ };
75
+ const size = pubsub_message_1.calculateMessageSize(message);
76
+ if (this.flowControl.wouldExceed(size, 1)) {
77
+ const waitPromise = this.flowControl.willSend(size, 1);
78
+ return waitPromise.then(doPublish);
79
+ }
80
+ else {
81
+ this.flowControl.willSend(size, 1).then(() => { });
82
+ doPublish();
83
+ return null;
84
+ }
85
+ }
86
+ /**
87
+ * Publishes a message unconditionally, updating flow control counters.
88
+ *
89
+ * You'll generally only want to use this if you want to deal with timing the
90
+ * flow control yourself, but you'd like the library to do the bean counting.
91
+ *
92
+ * @param {Buffer} [data] The message contents to be sent.
93
+ * @param {Attributes} [attributes] Optional attributes.
94
+ *
95
+ * @example
96
+ * ```
97
+ * if (!flowControlled.wouldExceed(data)) {
98
+ * flowControlled.publishNow(data);
99
+ * }
100
+ * ```
101
+ */
102
+ publishNow(message) {
103
+ this.flowControl.addToCount(pubsub_message_1.calculateMessageSize(message), 1);
104
+ this.doPublish(message);
105
+ }
106
+ doPublish(message) {
107
+ let idPromise = this.publisher.publishMessage(message);
108
+ // This will defer but not eat any errors.
109
+ const publishDone = (id) => {
110
+ this.flowControl.sent(pubsub_message_1.calculateMessageSize(message), 1);
111
+ return id;
112
+ };
113
+ idPromise.catch(publishDone);
114
+ idPromise = idPromise.then(publishDone);
115
+ this.idPromises.push(idPromise);
116
+ }
117
+ /**
118
+ * Returns a Promise that will resolve to all of the currently sent
119
+ * message IDs (or reject if there is an error). This also clears
120
+ * out any currently sent messages, so the next call to `all()` will
121
+ * be a clean slate.
122
+ *
123
+ * @returns {Promise<string[]>} A Promise that resolves when all current
124
+ * messages are sent.
125
+ */
126
+ all() {
127
+ const allPromise = Promise.all(this.idPromises);
128
+ this.idPromises = [];
129
+ return allPromise;
130
+ }
131
+ }
132
+ exports.FlowControlledPublisher = FlowControlledPublisher;
133
+ //# sourceMappingURL=flow-publisher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow-publisher.js","sourceRoot":"","sources":["../../../src/publisher/flow-publisher.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAIH,qDAAqE;AAErE;;;;;;;;;GASG;AACH,MAAa,uBAAuB;IAKlC,YAAY,SAAoB;QAC9B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC;QAC9C,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;IACvB,CAAC;IAED;;;;;;OAMG;IACH,WAAW,CAAC,OAAsB;QAChC,OAAO,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,qCAAoB,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;IACxE,CAAC;IAED;;;;;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CAAC,WAAW,CAAC,CAAC;QAExC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAClC,CAAC;IAED;;;;;;;;OAQG;IACH,GAAG;QACD,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAChD,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,OAAO,UAAU,CAAC;IACpB,CAAC;CACF;AAhHD,0DAgHC"}
@@ -20,14 +20,13 @@ import { BatchPublishOptions } from './message-batch';
20
20
  import { Queue, OrderedQueue } from './message-queues';
21
21
  import { Topic } from '../topic';
22
22
  import { RequestCallback, EmptyCallback } from '../pubsub';
23
- import { google } from '../../protos/protos';
24
- export declare type PubsubMessage = google.pubsub.v1.IPubsubMessage;
25
- export interface Attributes {
26
- [key: string]: string;
27
- }
23
+ import { FlowControl, FlowControlOptions } from './flow-control';
24
+ import { PubsubMessage, Attributes } from './pubsub-message';
25
+ export { PubsubMessage, Attributes } from './pubsub-message';
28
26
  export declare type PublishCallback = RequestCallback<string>;
29
27
  export interface PublishOptions {
30
28
  batching?: BatchPublishOptions;
29
+ flowControlOptions?: FlowControlOptions;
31
30
  gaxOpts?: CallOptions;
32
31
  messageOrdering?: boolean;
33
32
  enableOpenTelemetryTracing?: boolean;
@@ -36,6 +35,8 @@ export interface PublishOptions {
36
35
  * @typedef PublishOptions
37
36
  * @property {BatchPublishOptions} [batching] The maximum number of bytes to
38
37
  * buffer before sending a payload.
38
+ * @property {FlowControlOptions} [publisherFlowControl] Publisher-side flow
39
+ * control settings. If this is undefined, Ignore will be the assumed action.
39
40
  * @property {object} [gaxOpts] Request configuration options, outlined
40
41
  * {@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html|here.}
41
42
  * @property {boolean} [messageOrdering] If true, messages published with the
@@ -44,6 +45,7 @@ export interface PublishOptions {
44
45
  * any order.
45
46
  */
46
47
  export declare const BATCH_LIMITS: BatchPublishOptions;
48
+ export declare const flowControlDefaults: FlowControlOptions;
47
49
  /**
48
50
  * A Publisher object allows you to publish messages to a specific topic.
49
51
  *
@@ -60,9 +62,34 @@ export declare class Publisher {
60
62
  settings: PublishOptions;
61
63
  queue: Queue;
62
64
  orderedQueues: Map<string, OrderedQueue>;
65
+ flowControl: FlowControl;
63
66
  constructor(topic: Topic, options?: PublishOptions);
67
+ /**
68
+ * Immediately sends all remaining queued data. This is mostly useful
69
+ * if you are planning to call close() on the PubSub object that holds
70
+ * the server connections.
71
+ *
72
+ * @private
73
+ *
74
+ * @param {EmptyCallback} [callback] Callback function.
75
+ * @returns {Promise<EmptyResponse>}
76
+ */
64
77
  flush(): Promise<void>;
65
78
  flush(callback: EmptyCallback): void;
79
+ /**
80
+ * Publish the provided message.
81
+ *
82
+ * @deprecated use {@link Publisher#publishMessage} instead.
83
+ *
84
+ * @private
85
+ * @see Publisher#publishMessage
86
+ *
87
+ * @param {buffer} data The message data. This must come in the form of a
88
+ * Buffer object.
89
+ * @param {object.<string, string>} [attributes] Attributes for this message.
90
+ * @param {PublishCallback} [callback] Callback function.
91
+ * @returns {Promise<PublishResponse>}
92
+ */
66
93
  publish(data: Buffer, attributes?: Attributes): Promise<string>;
67
94
  publish(data: Buffer, callback: PublishCallback): void;
68
95
  publish(data: Buffer, attributes: Attributes, callback: PublishCallback): void;
@@ -77,6 +104,7 @@ export declare class Publisher {
77
104
  * @param {PubsubMessage} [message] Options for this message.
78
105
  * @param {PublishCallback} [callback] Callback function.
79
106
  */
107
+ publishMessage(message: PubsubMessage): Promise<string>;
80
108
  publishMessage(message: PubsubMessage, callback: PublishCallback): void;
81
109
  /**
82
110
  * Indicates to the publisher that it is safe to continue publishing for the
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.Publisher = exports.BATCH_LIMITS = void 0;
18
+ exports.Publisher = exports.flowControlDefaults = exports.BATCH_LIMITS = void 0;
19
19
  const promisify_1 = require("@google-cloud/promisify");
20
20
  const extend = require("extend");
21
21
  const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
@@ -23,10 +23,14 @@ const api_1 = require("@opentelemetry/api");
23
23
  const message_queues_1 = require("./message-queues");
24
24
  const default_options_1 = require("../default-options");
25
25
  const opentelemetry_tracing_1 = require("../opentelemetry-tracing");
26
+ const flow_control_1 = require("./flow-control");
27
+ const util_1 = require("../util");
26
28
  /**
27
29
  * @typedef PublishOptions
28
30
  * @property {BatchPublishOptions} [batching] The maximum number of bytes to
29
31
  * buffer before sending a payload.
32
+ * @property {FlowControlOptions} [publisherFlowControl] Publisher-side flow
33
+ * control settings. If this is undefined, Ignore will be the assumed action.
30
34
  * @property {object} [gaxOpts] Request configuration options, outlined
31
35
  * {@link https://googleapis.github.io/gax-nodejs/interfaces/CallOptions.html|here.}
32
36
  * @property {boolean} [messageOrdering] If true, messages published with the
@@ -38,6 +42,10 @@ exports.BATCH_LIMITS = {
38
42
  maxBytes: Math.pow(1024, 2) * 9,
39
43
  maxMessages: 1000,
40
44
  };
45
+ exports.flowControlDefaults = {
46
+ maxOutstandingBytes: undefined,
47
+ maxOutstandingMessages: undefined,
48
+ };
41
49
  /**
42
50
  * A Publisher object allows you to publish messages to a specific topic.
43
51
  *
@@ -51,21 +59,12 @@ exports.BATCH_LIMITS = {
51
59
  */
52
60
  class Publisher {
53
61
  constructor(topic, options) {
62
+ this.flowControl = new flow_control_1.FlowControl((options === null || options === void 0 ? void 0 : options.flowControlOptions) || exports.flowControlDefaults);
54
63
  this.setOptions(options);
55
64
  this.topic = topic;
56
65
  this.queue = new message_queues_1.Queue(this);
57
66
  this.orderedQueues = new Map();
58
67
  }
59
- /**
60
- * Immediately sends all remaining queued data. This is mostly useful
61
- * if you are planning to call close() on the PubSub object that holds
62
- * the server connections.
63
- *
64
- * @private
65
- *
66
- * @param {EmptyCallback} [callback] Callback function.
67
- * @returns {Promise<EmptyResponse>}
68
- */
69
68
  flush(callback) {
70
69
  const definedCallback = callback ? callback : () => { };
71
70
  const publishes = [promisify_1.promisify(this.queue.publish).bind(this.queue)()];
@@ -77,36 +76,11 @@ class Publisher {
77
76
  })
78
77
  .catch(definedCallback);
79
78
  }
80
- /**
81
- * Publish the provided message.
82
- *
83
- * @deprecated use {@link Publisher#publishMessage} instead.
84
- *
85
- * @private
86
- * @see Publisher#publishMessage
87
- *
88
- * @param {buffer} data The message data. This must come in the form of a
89
- * Buffer object.
90
- * @param {object.<string, string>} [attributes] Attributes for this message.
91
- * @param {PublishCallback} [callback] Callback function.
92
- * @returns {Promise<PublishResponse>}
93
- */
94
79
  publish(data, attrsOrCb, callback) {
95
80
  const attributes = typeof attrsOrCb === 'object' ? attrsOrCb : {};
96
81
  callback = typeof attrsOrCb === 'function' ? attrsOrCb : callback;
97
82
  return this.publishMessage({ data, attributes }, callback);
98
83
  }
99
- /**
100
- * Publish the provided message.
101
- *
102
- * @private
103
- *
104
- * @throws {TypeError} If data is not a Buffer object.
105
- * @throws {TypeError} If any value in `attributes` object is not a string.
106
- *
107
- * @param {PubsubMessage} [message] Options for this message.
108
- * @param {PublishCallback} [callback] Callback function.
109
- */
110
84
  publishMessage(message, callback) {
111
85
  const { data, attributes = {} } = message;
112
86
  // We must have at least one of:
@@ -183,6 +157,7 @@ class Publisher {
183
157
  isBundling: false,
184
158
  },
185
159
  enableOpenTelemetryTracing: false,
160
+ flowControlOptions: Object.assign({}, exports.flowControlDefaults),
186
161
  };
187
162
  return defaults;
188
163
  }
@@ -195,7 +170,7 @@ class Publisher {
195
170
  */
196
171
  setOptions(options = {}) {
197
172
  const defaults = this.getOptionDefaults();
198
- const { batching, gaxOpts, messageOrdering, enableOpenTelemetryTracing } = extend(true, defaults, options);
173
+ const { batching, gaxOpts, messageOrdering, enableOpenTelemetryTracing, flowControlOptions, } = extend(true, defaults, options);
199
174
  this.settings = {
200
175
  batching: {
201
176
  maxBytes: Math.min(batching.maxBytes, exports.BATCH_LIMITS.maxBytes),
@@ -205,6 +180,7 @@ class Publisher {
205
180
  gaxOpts,
206
181
  messageOrdering,
207
182
  enableOpenTelemetryTracing,
183
+ flowControlOptions,
208
184
  };
209
185
  // We also need to let all of our queues know that they need to update their options.
210
186
  // Note that these might be undefined, because setOptions() is called in the constructor.
@@ -216,6 +192,8 @@ class Publisher {
216
192
  q.updateOptions();
217
193
  }
218
194
  }
195
+ // This will always be filled in by our defaults if nothing else.
196
+ this.flowControl.setOptions(this.settings.flowControlOptions);
219
197
  }
220
198
  /**
221
199
  * Constructs an OpenTelemetry span
@@ -259,8 +237,7 @@ class Publisher {
259
237
  }
260
238
  }
261
239
  exports.Publisher = Publisher;
262
- promisify_1.promisifyAll(Publisher, {
240
+ util_1.promisifySome(Publisher, Publisher.prototype, ['flush', 'publishMessage'], {
263
241
  singular: true,
264
- exclude: ['publish', 'setOptions', 'constructSpan', 'getOptionDefaults'],
265
242
  });
266
243
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/publisher/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,uDAAgE;AAChE,iCAAiC;AAEjC,8EAAuE;AACvE,4CAAsE;AAGtE,qDAAqD;AAIrD,wDAAkD;AAClD,oEAAoD;AAiBpD;;;;;;;;;;GAUG;AAEU,QAAA,YAAY,GAAwB;IAC/C,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC;IAC/B,WAAW,EAAE,IAAI;CAClB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAa,SAAS;IAKpB,YAAY,KAAY,EAAE,OAAwB;QAChD,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,KAAK,GAAG,IAAI,sBAAK,CAAC,IAAI,CAAC,CAAC;QAC7B,IAAI,CAAC,aAAa,GAAG,IAAI,GAA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E,QAAQ,EAAE,IAAI;CACf,CAAC,CAAC"}
@@ -61,7 +61,7 @@ export declare class MessageBatch {
61
61
  * @param {object} message The message in question.
62
62
  * @returns {boolean}
63
63
  */
64
- canFit({ data }: PubsubMessage): boolean;
64
+ canFit(message: PubsubMessage): boolean;
65
65
  /**
66
66
  * Checks to see if this batch is at the maximum allowed payload size.
67
67
  * When publishing ordered messages, it is ok to exceed the user configured
@@ -17,6 +17,7 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.MessageBatch = void 0;
19
19
  const _1 = require("./");
20
+ const pubsub_message_1 = require("./pubsub-message");
20
21
  /**
21
22
  * @typedef BatchPublishOptions
22
23
  * @property {number} [maxBytes=1 * 1024 * 1024] The maximum number of bytes to
@@ -58,7 +59,7 @@ class MessageBatch {
58
59
  add(message, callback) {
59
60
  this.messages.push(message);
60
61
  this.callbacks.push(callback);
61
- this.bytes += message.data.length;
62
+ this.bytes += pubsub_message_1.calculateMessageSize(message);
62
63
  }
63
64
  /**
64
65
  * Indicates if a given message can fit in the batch.
@@ -66,10 +67,10 @@ class MessageBatch {
66
67
  * @param {object} message The message in question.
67
68
  * @returns {boolean}
68
69
  */
69
- canFit({ data }) {
70
+ canFit(message) {
70
71
  const { maxMessages, maxBytes } = this.options;
71
72
  return (this.messages.length < maxMessages &&
72
- this.bytes + data.length <= maxBytes);
73
+ this.bytes + pubsub_message_1.calculateMessageSize(message) <= maxBytes);
73
74
  }
74
75
  /**
75
76
  * Checks to see if this batch is at the maximum allowed payload size.