@google-cloud/pubsub
Advanced tools
Comparing version 1.6.0 to 1.7.0
@@ -21,3 +21,3 @@ /*! | ||
import { Topic } from '../topic'; | ||
import { RequestCallback } from '../pubsub'; | ||
import { RequestCallback, EmptyCallback } from '../pubsub'; | ||
import { google } from '../../proto/pubsub'; | ||
@@ -53,2 +53,4 @@ export declare type PubsubMessage = google.pubsub.v1.IPubsubMessage; | ||
constructor(topic: Topic, options?: PublishOptions); | ||
flush(): Promise<void>; | ||
flush(callback: EmptyCallback): void; | ||
publish(data: Buffer, attributes?: Attributes): Promise<string>; | ||
@@ -55,0 +57,0 @@ publish(data: Buffer, callback: PublishCallback): void; |
@@ -48,2 +48,23 @@ "use strict"; | ||
/** | ||
* Immediately sends all remaining queued data. This is mostly useful | ||
* if you are planning to call close() on the PubSub object that holds | ||
* the server connections. | ||
* | ||
* @private | ||
* | ||
* @param {EmptyCallback} [callback] Callback function. | ||
* @returns {Promise<EmptyResponse>} | ||
*/ | ||
flush(callback) { | ||
const definedCallback = callback ? callback : () => { }; | ||
const publishes = [promisify_1.promisify(this.queue.publish)()]; | ||
Array.from(this.orderedQueues.values()).forEach(q => publishes.push(promisify_1.promisify(q.publish)())); | ||
const allPublishes = Promise.all(publishes); | ||
allPublishes | ||
.then(() => { | ||
definedCallback(null); | ||
}) | ||
.catch(definedCallback); | ||
} | ||
/** | ||
* Publish the provided message. | ||
@@ -50,0 +71,0 @@ * |
@@ -82,3 +82,3 @@ /*! | ||
*/ | ||
publish(): void; | ||
publish(callback?: PublishDone): void; | ||
} | ||
@@ -141,3 +141,3 @@ /** | ||
*/ | ||
publish(): void; | ||
publish(callback?: PublishDone): void; | ||
/** | ||
@@ -144,0 +144,0 @@ * Tells the queue it is ok to continue publishing messages. |
@@ -97,3 +97,3 @@ "use strict"; | ||
*/ | ||
publish() { | ||
publish(callback) { | ||
const { messages, callbacks } = this.batch; | ||
@@ -105,3 +105,3 @@ this.batch = new message_batch_1.MessageBatch(this.batchOptions); | ||
} | ||
this._publish(messages, callbacks); | ||
this._publish(messages, callbacks, callback); | ||
} | ||
@@ -214,3 +214,4 @@ } | ||
*/ | ||
publish() { | ||
publish(callback) { | ||
const definedCallback = callback || (() => { }); | ||
this.inFlight = true; | ||
@@ -226,2 +227,3 @@ if (this.pending) { | ||
this.handlePublishFailure(err); | ||
definedCallback(err); | ||
} | ||
@@ -233,2 +235,3 @@ else if (this.batches.length) { | ||
this.emit('drain'); | ||
definedCallback(null); | ||
} | ||
@@ -235,0 +238,0 @@ }); |
@@ -154,3 +154,6 @@ /*! | ||
getTopicsStream: () => ObjectStream<Topic>; | ||
isOpen: boolean; | ||
constructor(options?: ClientConfig); | ||
close(): Promise<void>; | ||
close(callback: EmptyCallback): void; | ||
createSubscription(topic: Topic | string, name: string, options?: CreateSubscriptionOptions): Promise<CreateSubscriptionResponse>; | ||
@@ -213,2 +216,10 @@ createSubscription(topic: Topic | string, name: string, callback: CreateSubscriptionCallback): void; | ||
/** | ||
* Close all open client objects. | ||
* | ||
* @private | ||
* | ||
* @returns {Promise} | ||
*/ | ||
closeAllClients_(): Promise<void>; | ||
/** | ||
* Funnel all API requests through this method, to be sure we have a project | ||
@@ -215,0 +226,0 @@ * ID. |
@@ -98,2 +98,3 @@ "use strict"; | ||
this.getTopicsStream = paginator_1.paginator.streamify('getTopics'); | ||
this.isOpen = true; | ||
options = options || {}; | ||
@@ -128,2 +129,27 @@ // Determine what scopes are needed. | ||
/** | ||
* Closes out this object, releasing any server connections. Note that once | ||
* you close a PubSub object, it may not be used again. Any pending operations | ||
* (e.g. queued publish messages) will fail. If you have topic or subscription | ||
* objects that may have pending operations, you should call close() on those | ||
* first if you want any pending messages to be delivered correctly. The | ||
* PubSub class doesn't track those. | ||
* | ||
* @callback EmptyCallback | ||
* @returns {Promise<void>} | ||
*/ | ||
close(callback) { | ||
const definedCallback = callback || (() => { }); | ||
if (this.isOpen) { | ||
this.isOpen = false; | ||
this.closeAllClients_() | ||
.then(() => { | ||
definedCallback(null); | ||
}) | ||
.catch(definedCallback); | ||
} | ||
else { | ||
definedCallback(null); | ||
} | ||
} | ||
/** | ||
* @typedef {array} CreateSubscriptionResponse | ||
@@ -647,2 +673,18 @@ * @property {Subscription} 0 The new {@link Subscription}. | ||
/** | ||
* Close all open client objects. | ||
* | ||
* @private | ||
* | ||
* @returns {Promise} | ||
*/ | ||
async closeAllClients_() { | ||
const promises = []; | ||
for (const clientConfig of Object.keys(this.api)) { | ||
const gaxClient = this.api[clientConfig]; | ||
promises.push(gaxClient.close()); | ||
delete this.api[clientConfig]; | ||
} | ||
await Promise.all(promises); | ||
} | ||
/** | ||
* Funnel all API requests through this method, to be sure we have a project | ||
@@ -660,2 +702,14 @@ * ID. | ||
request(config, callback) { | ||
// This prevents further requests, in case any publishers were hanging around. | ||
if (!this.isOpen) { | ||
const statusObject = { | ||
code: 0, | ||
details: 'Cannot use a closed PubSub object.', | ||
metadata: null, | ||
}; | ||
const err = new Error(statusObject.details); | ||
Object.assign(err, statusObject); | ||
callback(err); | ||
return; | ||
} | ||
this.getClient_(config, (err, client) => { | ||
@@ -841,3 +895,3 @@ if (err) { | ||
* | ||
* These methods can be agto-paginated. | ||
* These methods can be auto-paginated. | ||
*/ | ||
@@ -844,0 +898,0 @@ paginator_1.paginator.extend(PubSub, ['getSnapshots', 'getSubscriptions', 'getTopics']); |
@@ -72,2 +72,4 @@ /*! | ||
constructor(pubsub: PubSub, name: string, options?: PublishOptions); | ||
flush(): Promise<void>; | ||
flush(callback: EmptyCallback): void; | ||
create(gaxOpts?: CallOptions): Promise<CreateTopicResponse>; | ||
@@ -74,0 +76,0 @@ create(callback: CreateTopicCallback): void; |
@@ -108,2 +108,15 @@ "use strict"; | ||
/** | ||
* Immediately sends all remaining queued data. This is mostly useful | ||
* if you are planning to call close() on the PubSub object that holds | ||
* the server connections. | ||
* | ||
* @param {EmptyCallback} [callback] Callback function. | ||
* @returns {Promise<EmptyResponse>} | ||
*/ | ||
flush(callback) { | ||
// It doesn't matter here if callback is undefined; the Publisher | ||
// flush() will handle it. | ||
this.publisher.flush(callback); | ||
} | ||
/** | ||
* Create a topic. | ||
@@ -625,3 +638,3 @@ * | ||
* | ||
* @see [UpdateTopicRequest API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/UpdateTopicRequest} | ||
* @see [UpdateTopicRequest API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rpc/google.pubsub.v1#google.pubsub.v1.UpdateTopicRequest} | ||
* | ||
@@ -628,0 +641,0 @@ * @param {object} metadata The fields to update. This should be structured |
@@ -144,4 +144,4 @@ // Copyright 2020 Google LLC | ||
* @property {Object} updateMask | ||
* Required. Indicates which fields in the provided topic to update. Must be specified | ||
* and non-empty. Note that if `update_mask` contains | ||
* Required. Indicates which fields in the provided topic to update. Must be | ||
* specified and non-empty. Note that if `update_mask` contains | ||
* "message_storage_policy" then the new value will be determined based on the | ||
@@ -286,3 +286,3 @@ * policy configured at the project or organization level. The | ||
* @property {string} topic | ||
* The name of the topic that snapshots are attached to. | ||
* Required. The name of the topic that snapshots are attached to. | ||
* Format is `projects/{project}/topics/{topic}`. | ||
@@ -352,6 +352,5 @@ * | ||
* @property {string} topic | ||
* Required. The name of the topic from which this subscription is receiving messages. | ||
* Format is `projects/{project}/topics/{topic}`. | ||
* The value of this field will be `_deleted-topic_` if the topic has been | ||
* deleted. | ||
* Required. The name of the topic from which this subscription is receiving | ||
* messages. Format is `projects/{project}/topics/{topic}`. The value of this | ||
* field will be `_deleted-topic_` if the topic has been deleted. | ||
* | ||
@@ -753,10 +752,13 @@ * @property {Object} pushConfig | ||
* @property {boolean} returnImmediately | ||
* If this field set to true, the system will respond immediately even if | ||
* it there are no messages available to return in the `Pull` response. | ||
* Otherwise, the system may wait (for a bounded amount of time) until at | ||
* least one message is available, rather than returning no messages. | ||
* Optional. If this field set to true, the system will respond immediately | ||
* even if it there are no messages available to return in the `Pull` | ||
* response. Otherwise, the system may wait (for a bounded amount of time) | ||
* until at least one message is available, rather than returning no messages. | ||
* Warning: setting this field to `true` is discouraged because it adversely | ||
* impacts the performance of `Pull` operations. We recommend that users do | ||
* not set this field. | ||
* | ||
* @property {number} maxMessages | ||
* Required. The maximum number of messages to return for this request. Must be a | ||
* positive integer. The Pub/Sub system may return fewer than the number | ||
* Required. The maximum number of messages to return for this request. Must | ||
* be a positive integer. The Pub/Sub system may return fewer than the number | ||
* specified. | ||
@@ -802,6 +804,6 @@ * | ||
* @property {number} ackDeadlineSeconds | ||
* Required. The new ack deadline with respect to the time this request was sent to | ||
* the Pub/Sub system. For example, if the value is 10, the new | ||
* ack deadline will expire 10 seconds after the `ModifyAckDeadline` call | ||
* was made. Specifying zero might immediately make the message available for | ||
* Required. The new ack deadline with respect to the time this request was | ||
* sent to the Pub/Sub system. For example, if the value is 10, the new ack | ||
* deadline will expire 10 seconds after the `ModifyAckDeadline` call was | ||
* made. Specifying zero might immediately make the message available for | ||
* delivery to another subscriber client. This typically results in an | ||
@@ -828,4 +830,5 @@ * increase in the rate of message redeliveries (that is, duplicates). | ||
* @property {string[]} ackIds | ||
* Required. The acknowledgment ID for the messages being acknowledged that was returned | ||
* by the Pub/Sub system in the `Pull` response. Must not be empty. | ||
* Required. The acknowledgment ID for the messages being acknowledged that | ||
* was returned by the Pub/Sub system in the `Pull` response. Must not be | ||
* empty. | ||
* | ||
@@ -846,4 +849,4 @@ * @typedef AcknowledgeRequest | ||
* @property {string} subscription | ||
* Required. The subscription for which to initialize the new stream. This must be | ||
* provided in the first request on the stream, and must not be set in | ||
* Required. The subscription for which to initialize the new stream. This | ||
* must be provided in the first request on the stream, and must not be set in | ||
* subsequent requests from client to server. | ||
@@ -880,4 +883,4 @@ * Format is `projects/{project}/subscriptions/{sub}`. | ||
* @property {number} streamAckDeadlineSeconds | ||
* Required. The ack deadline to use for the stream. This must be provided in the | ||
* first request on the stream, but it can also be updated on subsequent | ||
* Required. The ack deadline to use for the stream. This must be provided in | ||
* the first request on the stream, but it can also be updated on subsequent | ||
* requests from client to server. The minimum deadline you can specify is 10 | ||
@@ -923,6 +926,6 @@ * seconds. The maximum deadline you can specify is 600 seconds (10 minutes). | ||
* @property {string} name | ||
* Required. User-provided name for this snapshot. If the name is not provided in the | ||
* request, the server will assign a random name for this snapshot on the same | ||
* project as the subscription. Note that for REST API requests, you must | ||
* specify a name. See the <a | ||
* Required. User-provided name for this snapshot. If the name is not provided | ||
* in the request, the server will assign a random name for this snapshot on | ||
* the same project as the subscription. Note that for REST API requests, you | ||
* must specify a name. See the <a | ||
* href="https://cloud.google.com/pubsub/docs/admin#resource_names"> resource | ||
@@ -929,0 +932,0 @@ * name rules</a>. Format is `projects/{project}/snapshots/{snap}`. |
@@ -384,4 +384,4 @@ // Copyright 2020 Google LLC | ||
* @param {Object} request.updateMask | ||
* Required. Indicates which fields in the provided topic to update. Must be specified | ||
* and non-empty. Note that if `update_mask` contains | ||
* Required. Indicates which fields in the provided topic to update. Must be | ||
* specified and non-empty. Note that if `update_mask` contains | ||
* "message_storage_policy" then the new value will be determined based on the | ||
@@ -388,0 +388,0 @@ * policy configured at the project or organization level. The |
@@ -7,2 +7,9 @@ # Changelog | ||
## [1.7.0](https://www.github.com/googleapis/nodejs-pubsub/compare/v1.6.0...v1.7.0) (2020-03-29) | ||
### Features | ||
* add a close() method to PubSub, and a flush() method to Topic/Publisher ([#916](https://www.github.com/googleapis/nodejs-pubsub/issues/916)) ([4097995](https://www.github.com/googleapis/nodejs-pubsub/commit/4097995a85a8ca3fb73c2c2a8cb0649cdd4274be)) | ||
## [1.6.0](https://www.github.com/googleapis/nodejs-pubsub/compare/v1.5.0...v1.6.0) (2020-03-04) | ||
@@ -9,0 +16,0 @@ |
{ | ||
"name": "@google-cloud/pubsub", | ||
"description": "Cloud Pub/Sub Client Library for Node.js", | ||
"version": "1.6.0", | ||
"version": "1.7.0", | ||
"license": "Apache-2.0", | ||
@@ -87,3 +87,2 @@ "author": "Google Inc.", | ||
"gts": "^1.0.0", | ||
"intelli-espower-loader": "^1.0.1", | ||
"jsdoc": "^3.6.2", | ||
@@ -97,3 +96,2 @@ "jsdoc-fresh": "^1.0.1", | ||
"ncp": "^2.0.0", | ||
"power-assert": "^1.4.4", | ||
"prettier": "^1.18.2", | ||
@@ -100,0 +98,0 @@ "proxyquire": "^2.0.0", |
@@ -140,2 +140,23 @@ [//]: # "This README.md file is auto-generated, all changes to this file will be lost." | ||
## Supported Node.js Versions | ||
Our client libraries follow the [Node.js release schedule](https://nodejs.org/en/about/releases/). | ||
Libraries are compatible with all current _active_ and _maintenance_ versions of | ||
Node.js. | ||
Client libraries targetting some end-of-life versions of Node.js are available, and | ||
can be installed via npm [dist-tags](https://docs.npmjs.com/cli/dist-tag). | ||
The dist-tags follow the naming convention `legacy-(version)`. | ||
_Legacy Node.js versions are supported as a best effort:_ | ||
* Legacy versions will not be tested in continuous integration. | ||
* Some security patches may not be able to be backported. | ||
* Dependencies will not be kept up-to-date, and features will not be backported. | ||
#### Legacy tags available | ||
* `legacy-8`: install client libraries from this dist-tag for versions | ||
compatible with Node.js 8. | ||
## Versioning | ||
@@ -164,2 +185,8 @@ | ||
Please note that this `README.md`, the `samples/README.md`, | ||
and a variety of configuration files in this repository (including `.nycrc` and `tsconfig.json`) | ||
are generated from a central template. To edit one of these files, make an edit | ||
to its template in this | ||
[directory](https://github.com/googleapis/synthtool/tree/master/synthtool/gcp/templates/node_library). | ||
## License | ||
@@ -166,0 +193,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
3494791
34
57007
203
170
0
0
0
16