From 858b565077494072522b0147ae54c113e5c2610b Mon Sep 17 00:00:00 2001 From: Megan Potter <57276408+feywind@users.noreply.github.com> Date: Fri, 18 Oct 2024 15:07:44 -0400 Subject: [PATCH 1/9] samples: various sample and doc improvements we had queued up (#1987) * samples: update publishing samples to clarify that topic objects should be cached; also fix a usage of publish() * samples: convert publishWithRetrySettings to use veneer * samples: update publishWithRetrySettings with new defaults; add comment about including all items * docs: clarify what subscriber batching means * samples: update EOD sample with endpoint * samples: add comments about ordered publishing as well --- ...istenForMessagesWithExactlyOnceDelivery.js | 9 ++- samples/publishAvroRecords.js | 6 +- samples/publishBatchedMessages.js | 3 +- samples/publishMessage.js | 9 +-- samples/publishMessageWithCustomAttributes.js | 12 ++-- samples/publishOrderedMessage.js | 12 ++-- samples/publishProtobufMessages.js | 8 ++- samples/publishWithFlowControl.js | 4 +- samples/publishWithOpenTelemetryTracing.js | 3 + samples/publishWithRetrySettings.js | 56 ++++++++--------- samples/resumePublish.js | 10 ++- ...istenForMessagesWithExactlyOnceDelivery.ts | 9 ++- samples/typescript/publishAvroRecords.ts | 6 +- samples/typescript/publishBatchedMessages.ts | 3 +- samples/typescript/publishMessage.ts | 9 +-- .../publishMessageWithCustomAttributes.ts | 12 ++-- samples/typescript/publishOrderedMessage.ts | 12 ++-- samples/typescript/publishProtobufMessages.ts | 8 ++- samples/typescript/publishWithFlowControl.ts | 4 +- .../publishWithOpenTelemetryTracing.ts | 3 + .../typescript/publishWithRetrySettings.ts | 61 ++++++++----------- samples/typescript/resumePublish.ts | 10 ++- src/message-queues.ts | 3 + src/subscriber.ts | 3 +- 24 files changed, 155 insertions(+), 120 deletions(-) diff --git a/samples/listenForMessagesWithExactlyOnceDelivery.js b/samples/listenForMessagesWithExactlyOnceDelivery.js index 1027761a0..a5d549f84 100644 --- a/samples/listenForMessagesWithExactlyOnceDelivery.js +++ b/samples/listenForMessagesWithExactlyOnceDelivery.js @@ -1,4 +1,4 @@ -// Copyright 2022 Google LLC +// Copyright 2022-2024 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -38,8 +38,11 @@ // Imports the Google Cloud client library const {PubSub} = require('@google-cloud/pubsub'); -// Creates a client; cache this for further use -const pubSubClient = new PubSub(); +// Pub/Sub's exactly once delivery guarantee only applies when subscribers connect to the service in the same region. +// For list of locational endpoints for Pub/Sub, see https://cloud.google.com/pubsub/docs/reference/service_apis_overview#list_of_locational_endpoints +const pubSubClient = new PubSub({ + apiEndpoint: 'us-west1-pubsub.googleapis.com:443', +}); async function listenForMessagesWithExactlyOnceDelivery( subscriptionNameOrId, diff --git a/samples/publishAvroRecords.js b/samples/publishAvroRecords.js index f40f3e418..053b9a06b 100644 --- a/samples/publishAvroRecords.js +++ b/samples/publishAvroRecords.js @@ -1,4 +1,4 @@ -// Copyright 2019-2021 Google LLC +// Copyright 2019-2024 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -46,8 +46,10 @@ const fs = require('fs'); const pubSubClient = new PubSub(); async function publishAvroRecords(topicNameOrId) { - // Get the topic metadata to learn about its schema encoding. + // Cache topic objects (publishers) and reuse them. const topic = pubSubClient.topic(topicNameOrId); + + // Get the topic metadata to learn about its schema encoding. const [topicMetadata] = await topic.getMetadata(); const topicSchemaMetadata = topicMetadata.schemaSettings; diff --git a/samples/publishBatchedMessages.js b/samples/publishBatchedMessages.js index 0a45a0880..a5f99b242 100644 --- a/samples/publishBatchedMessages.js +++ b/samples/publishBatchedMessages.js @@ -1,4 +1,4 @@ -// Copyright 2019-2023 Google LLC +// Copyright 2019-2024 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -53,6 +53,7 @@ async function publishBatchedMessages( // Publishes the message as a string, e.g. "Hello, world!" or JSON.stringify(someObject) const dataBuffer = Buffer.from(data); + // Cache topic objects (publishers) and reuse them. const publishOptions = { batching: { maxMessages: maxMessages, diff --git a/samples/publishMessage.js b/samples/publishMessage.js index 2436b07fb..6b0581d08 100644 --- a/samples/publishMessage.js +++ b/samples/publishMessage.js @@ -1,4 +1,4 @@ -// Copyright 2019-2023 Google LLC +// Copyright 2019-2024 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -47,10 +47,11 @@ async function publishMessage(topicNameOrId, data) { // Publishes the message as a string, e.g. "Hello, world!" or JSON.stringify(someObject) const dataBuffer = Buffer.from(data); + // Cache topic objects (publishers) and reuse them. + const topic = pubSubClient.topic(topicNameOrId); + try { - const messageId = await pubSubClient - .topic(topicNameOrId) - .publishMessage({data: dataBuffer}); + const messageId = topic.publishMessage({data: dataBuffer}); console.log(`Message ${messageId} published.`); } catch (error) { console.error(`Received error while publishing: ${error.message}`); diff --git a/samples/publishMessageWithCustomAttributes.js b/samples/publishMessageWithCustomAttributes.js index 3c2e6b43a..224a9ce0d 100644 --- a/samples/publishMessageWithCustomAttributes.js +++ b/samples/publishMessageWithCustomAttributes.js @@ -1,4 +1,4 @@ -// Copyright 2019-2023 Google LLC +// Copyright 2019-2024 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -52,9 +52,13 @@ async function publishMessageWithCustomAttributes(topicNameOrId, data) { username: 'gcp', }; - const messageId = await pubSubClient - .topic(topicNameOrId) - .publishMessage({data: dataBuffer, attributes: customAttributes}); + // Cache topic objects (publishers) and reuse them. + const topic = pubSubClient.topic(topicNameOrId); + + const messageId = topic.publishMessage({ + data: dataBuffer, + attributes: customAttributes, + }); console.log(`Message ${messageId} published.`); } // [END pubsub_publish_custom_attributes] diff --git a/samples/publishOrderedMessage.js b/samples/publishOrderedMessage.js index bb4e0cc4d..19761b6ad 100644 --- a/samples/publishOrderedMessage.js +++ b/samples/publishOrderedMessage.js @@ -1,4 +1,4 @@ -// Copyright 2019-2023 Google LLC +// Copyright 2019-2024 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -61,14 +61,18 @@ async function publishOrderedMessage(topicNameOrId, data, orderingKey) { orderingKey: orderingKey, }; + // Cache topic objects (publishers) and reuse them. + // + // Pub/Sub's ordered delivery guarantee only applies when publishes for an ordering + // key are in the same region. For list of locational endpoints for Pub/Sub, see: + // https://cloud.google.com/pubsub/docs/reference/service_apis_overview#list_of_locational_endpoints const publishOptions = { messageOrdering: true, }; + const topic = pubSubClient.topic(topicNameOrId, publishOptions); // Publishes the message - const messageId = await pubSubClient - .topic(topicNameOrId, publishOptions) - .publishMessage(message); + const messageId = topic.publishMessage(message); console.log(`Message ${messageId} published.`); diff --git a/samples/publishProtobufMessages.js b/samples/publishProtobufMessages.js index bab100563..f486f586f 100644 --- a/samples/publishProtobufMessages.js +++ b/samples/publishProtobufMessages.js @@ -1,4 +1,4 @@ -// Copyright 2019-2021 Google LLC +// Copyright 2019-2024 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -45,8 +45,10 @@ const protobuf = require('protobufjs'); const pubSubClient = new PubSub(); async function publishProtobufMessages(topicNameOrId) { - // Get the topic metadata to learn about its schema. + // Cache topic objects (publishers) and reuse them. const topic = pubSubClient.topic(topicNameOrId); + + // Get the topic metadata to learn about its schema. const [topicMetadata] = await topic.getMetadata(); const topicSchemaMetadata = topicMetadata.schemaSettings; @@ -87,7 +89,7 @@ async function publishProtobufMessages(topicNameOrId) { return; } - const messageId = await topic.publish(dataBuffer); + const messageId = await topic.publishMessage({data: dataBuffer}); console.log(`Protobuf message ${messageId} published.`); } // [END pubsub_publish_proto_messages] diff --git a/samples/publishWithFlowControl.js b/samples/publishWithFlowControl.js index 7e1193f79..9c914e2d2 100644 --- a/samples/publishWithFlowControl.js +++ b/samples/publishWithFlowControl.js @@ -1,4 +1,4 @@ -// Copyright 2021 Google LLC +// Copyright 2021-2024 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -50,7 +50,7 @@ async function publishWithFlowControl(topicNameOrId) { }, }; - // Get a publisher. + // Get a publisher. Cache topic objects (publishers) and reuse them. const topic = pubSubClient.topic(topicNameOrId, options); // For flow controlled publishing, we'll use a publisher flow controller diff --git a/samples/publishWithOpenTelemetryTracing.js b/samples/publishWithOpenTelemetryTracing.js index 42b529739..71d030c96 100644 --- a/samples/publishWithOpenTelemetryTracing.js +++ b/samples/publishWithOpenTelemetryTracing.js @@ -86,7 +86,10 @@ async function publishMessage(topicNameOrId, data) { // Publishes the message as a string, e.g. "Hello, world!" // or JSON.stringify(someObject) const dataBuffer = Buffer.from(data); + + // Cache topic objects (publishers) and reuse them. const publisher = pubSubClient.topic(topicNameOrId); + const messageId = await publisher.publishMessage({data: dataBuffer}); console.log(`Message ${messageId} published.`); diff --git a/samples/publishWithRetrySettings.js b/samples/publishWithRetrySettings.js index 3c50b5a99..24738b7e0 100644 --- a/samples/publishWithRetrySettings.js +++ b/samples/publishWithRetrySettings.js @@ -1,4 +1,4 @@ -// Copyright 2019-2023 Google LLC +// Copyright 2019-2024 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -39,34 +39,20 @@ // Imports the Google Cloud client library. v1 is for the lower level // proto access. -const {v1} = require('@google-cloud/pubsub'); +const {PubSub} = require('@google-cloud/pubsub'); -// Creates a publisher client. -const publisherClient = new v1.PublisherClient({ - // optional auth parameters -}); -async function publishWithRetrySettings(projectId, topicNameOrId, data) { - const formattedTopic = publisherClient.projectTopicPath( - projectId, - topicNameOrId - ); - - // Publishes the message as a string, e.g. "Hello, world!" or JSON.stringify(someObject) - const dataBuffer = Buffer.from(data); - const messagesElement = { - data: dataBuffer, - }; - const messages = [messagesElement]; - - // Build the request - const request = { - topic: formattedTopic, - messages: messages, - }; +async function publishWithRetrySettings(topicNameOrId, data) { + const pubsubClient = new PubSub(); // Retry settings control how the publisher handles retryable failures. Default values are shown. // The `retryCodes` array determines which grpc errors will trigger an automatic retry. // The `backoffSettings` object lets you specify the behaviour of retries over time. + // + // Reference this document to see the current defaults for publishing: + // https://github.com/googleapis/nodejs-pubsub/blob/6e2c28a9298a49dc1b194ce747ff5258c8df6deb/src/v1/publisher_client_config.json#L59 + // + // Please note that _all_ items must be included when passing these settings to topic(). + // Otherwise, unpredictable (incorrect) defaults may be assumed. const retrySettings = { retryCodes: [ 10, // 'ABORTED' @@ -83,36 +69,42 @@ async function publishWithRetrySettings(projectId, topicNameOrId, data) { initialRetryDelayMillis: 100, // The multiplier by which to increase the delay time between the completion // of failed requests, and the initiation of the subsequent retrying request. - retryDelayMultiplier: 1.3, + retryDelayMultiplier: 4, // The maximum delay time, in milliseconds, between requests. // When this value is reached, retryDelayMultiplier will no longer be used to increase delay time. maxRetryDelayMillis: 60000, // The initial timeout parameter to the request. - initialRpcTimeoutMillis: 5000, + initialRpcTimeoutMillis: 60000, // The multiplier by which to increase the timeout parameter between failed requests. rpcTimeoutMultiplier: 1.0, // The maximum timeout parameter, in milliseconds, for a request. When this value is reached, // rpcTimeoutMultiplier will no longer be used to increase the timeout. - maxRpcTimeoutMillis: 600000, + maxRpcTimeoutMillis: 60000, // The total time, in milliseconds, starting from when the initial request is sent, // after which an error will be returned, regardless of the retrying attempts made meanwhile. totalTimeoutMillis: 600000, }, }; - const [response] = await publisherClient.publish(request, { - retry: retrySettings, + // Cache topic objects (publishers) and reuse them. + const topic = pubsubClient.topic(topicNameOrId, { + gaxOpts: { + retry: retrySettings, + }, }); - console.log(`Message ${response.messageIds} published.`); + + // Publishes the message as a string, e.g. "Hello, world!" or JSON.stringify(someObject) + const dataBuffer = Buffer.from(data); + const messageId = await topic.publishMessage({data: dataBuffer}); + console.log(`Message ${messageId} published.`); } // [END pubsub_publisher_retry_settings] function main( - projectId = 'YOUR_PROJECT_ID', topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID', data = JSON.stringify({foo: 'bar'}) ) { - publishWithRetrySettings(projectId, topicNameOrId, data).catch(err => { + publishWithRetrySettings(topicNameOrId, data).catch(err => { console.error(err.message); process.exitCode = 1; }); diff --git a/samples/resumePublish.js b/samples/resumePublish.js index 3dbe4b242..5d66e712f 100644 --- a/samples/resumePublish.js +++ b/samples/resumePublish.js @@ -1,4 +1,4 @@ -// Copyright 2019-2023 Google LLC +// Copyright 2019-2024 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -52,8 +52,14 @@ async function resumePublish(topicNameOrId, data, orderingKey) { messageOrdering: true, }; - // Publishes the message + // Cache topic objects (publishers) and reuse them. + // + // Pub/Sub's ordered delivery guarantee only applies when publishes for an ordering + // key are in the same region. For list of locational endpoints for Pub/Sub, see: + // https://cloud.google.com/pubsub/docs/reference/service_apis_overview#list_of_locational_endpoints const publisher = pubSubClient.topic(topicNameOrId, publishOptions); + + // Publishes the message try { const message = { data: dataBuffer, diff --git a/samples/typescript/listenForMessagesWithExactlyOnceDelivery.ts b/samples/typescript/listenForMessagesWithExactlyOnceDelivery.ts index 618ba9a30..9194c0b6f 100644 --- a/samples/typescript/listenForMessagesWithExactlyOnceDelivery.ts +++ b/samples/typescript/listenForMessagesWithExactlyOnceDelivery.ts @@ -1,4 +1,4 @@ -// Copyright 2022 Google LLC +// Copyright 2022-2024 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -34,8 +34,11 @@ // Imports the Google Cloud client library import {Message, PubSub, AckError} from '@google-cloud/pubsub'; -// Creates a client; cache this for further use -const pubSubClient = new PubSub(); +// Pub/Sub's exactly once delivery guarantee only applies when subscribers connect to the service in the same region. +// For list of locational endpoints for Pub/Sub, see https://cloud.google.com/pubsub/docs/reference/service_apis_overview#list_of_locational_endpoints +const pubSubClient = new PubSub({ + apiEndpoint: 'us-west1-pubsub.googleapis.com:443', +}); async function listenForMessagesWithExactlyOnceDelivery( subscriptionNameOrId: string, diff --git a/samples/typescript/publishAvroRecords.ts b/samples/typescript/publishAvroRecords.ts index d269f5479..9725f9af3 100644 --- a/samples/typescript/publishAvroRecords.ts +++ b/samples/typescript/publishAvroRecords.ts @@ -1,4 +1,4 @@ -// Copyright 2019-2021 Google LLC +// Copyright 2019-2024 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -47,8 +47,10 @@ interface ProvinceObject { } async function publishAvroRecords(topicNameOrId: string) { - // Get the topic metadata to learn about its schema encoding. + // Cache topic objects (publishers) and reuse them. const topic = pubSubClient.topic(topicNameOrId); + + // Get the topic metadata to learn about its schema encoding. const [topicMetadata] = await topic.getMetadata(); const topicSchemaMetadata = topicMetadata.schemaSettings; diff --git a/samples/typescript/publishBatchedMessages.ts b/samples/typescript/publishBatchedMessages.ts index 5f7f76cbc..4d5157beb 100644 --- a/samples/typescript/publishBatchedMessages.ts +++ b/samples/typescript/publishBatchedMessages.ts @@ -1,4 +1,4 @@ -// Copyright 2019-2023 Google LLC +// Copyright 2019-2024 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -49,6 +49,7 @@ async function publishBatchedMessages( // Publishes the message as a string, e.g. "Hello, world!" or JSON.stringify(someObject) const dataBuffer = Buffer.from(data); + // Cache topic objects (publishers) and reuse them. const publishOptions: PublishOptions = { batching: { maxMessages: maxMessages, diff --git a/samples/typescript/publishMessage.ts b/samples/typescript/publishMessage.ts index 86b9e7562..eb7526143 100644 --- a/samples/typescript/publishMessage.ts +++ b/samples/typescript/publishMessage.ts @@ -1,4 +1,4 @@ -// Copyright 2019-2023 Google LLC +// Copyright 2019-2024 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -43,10 +43,11 @@ async function publishMessage(topicNameOrId: string, data: string) { // Publishes the message as a string, e.g. "Hello, world!" or JSON.stringify(someObject) const dataBuffer = Buffer.from(data); + // Cache topic objects (publishers) and reuse them. + const topic = pubSubClient.topic(topicNameOrId); + try { - const messageId = await pubSubClient - .topic(topicNameOrId) - .publishMessage({data: dataBuffer}); + const messageId = topic.publishMessage({data: dataBuffer}); console.log(`Message ${messageId} published.`); } catch (error) { console.error( diff --git a/samples/typescript/publishMessageWithCustomAttributes.ts b/samples/typescript/publishMessageWithCustomAttributes.ts index 9b6619377..df285cb29 100644 --- a/samples/typescript/publishMessageWithCustomAttributes.ts +++ b/samples/typescript/publishMessageWithCustomAttributes.ts @@ -1,4 +1,4 @@ -// Copyright 2019-2023 Google LLC +// Copyright 2019-2024 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -55,9 +55,13 @@ async function publishMessageWithCustomAttributes( username: 'gcp', }; - const messageId = await pubSubClient - .topic(topicNameOrId) - .publishMessage({data: dataBuffer, attributes: customAttributes}); + // Cache topic objects (publishers) and reuse them. + const topic = pubSubClient.topic(topicNameOrId); + + const messageId = topic.publishMessage({ + data: dataBuffer, + attributes: customAttributes, + }); console.log(`Message ${messageId} published.`); } // [END pubsub_publish_custom_attributes] diff --git a/samples/typescript/publishOrderedMessage.ts b/samples/typescript/publishOrderedMessage.ts index 30187a0c2..0fb083208 100644 --- a/samples/typescript/publishOrderedMessage.ts +++ b/samples/typescript/publishOrderedMessage.ts @@ -1,4 +1,4 @@ -// Copyright 2019-2023 Google LLC +// Copyright 2019-2024 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -61,14 +61,18 @@ async function publishOrderedMessage( orderingKey: orderingKey, }; + // Cache topic objects (publishers) and reuse them. + // + // Pub/Sub's ordered delivery guarantee only applies when publishes for an ordering + // key are in the same region. For list of locational endpoints for Pub/Sub, see: + // https://cloud.google.com/pubsub/docs/reference/service_apis_overview#list_of_locational_endpoints const publishOptions: PublishOptions = { messageOrdering: true, }; + const topic = pubSubClient.topic(topicNameOrId, publishOptions); // Publishes the message - const messageId = await pubSubClient - .topic(topicNameOrId, publishOptions) - .publishMessage(message); + const messageId = topic.publishMessage(message); console.log(`Message ${messageId} published.`); diff --git a/samples/typescript/publishProtobufMessages.ts b/samples/typescript/publishProtobufMessages.ts index 0ff9ba64b..4947352bd 100644 --- a/samples/typescript/publishProtobufMessages.ts +++ b/samples/typescript/publishProtobufMessages.ts @@ -1,4 +1,4 @@ -// Copyright 2019-2021 Google LLC +// Copyright 2019-2024 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -46,8 +46,10 @@ interface ProvinceObject { } async function publishProtobufMessages(topicNameOrId: string) { - // Get the topic metadata to learn about its schema. + // Cache topic objects (publishers) and reuse them. const topic = pubSubClient.topic(topicNameOrId); + + // Get the topic metadata to learn about its schema. const [topicMetadata] = await topic.getMetadata(); const topicSchemaMetadata = topicMetadata.schemaSettings; @@ -88,7 +90,7 @@ async function publishProtobufMessages(topicNameOrId: string) { return; } - const messageId = await topic.publish(dataBuffer); + const messageId = await topic.publishMessage({data: dataBuffer}); console.log(`Protobuf message ${messageId} published.`); } // [END pubsub_publish_proto_messages] diff --git a/samples/typescript/publishWithFlowControl.ts b/samples/typescript/publishWithFlowControl.ts index 2d08a0831..c8c991a60 100644 --- a/samples/typescript/publishWithFlowControl.ts +++ b/samples/typescript/publishWithFlowControl.ts @@ -1,4 +1,4 @@ -// Copyright 2021 Google LLC +// Copyright 2021-2024 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -46,7 +46,7 @@ async function publishWithFlowControl(topicNameOrId: string) { }, }; - // Get a publisher. + // Get a publisher. Cache topic objects (publishers) and reuse them. const topic = pubSubClient.topic(topicNameOrId, options); // For flow controlled publishing, we'll use a publisher flow controller diff --git a/samples/typescript/publishWithOpenTelemetryTracing.ts b/samples/typescript/publishWithOpenTelemetryTracing.ts index cd7a82b3a..a92982976 100644 --- a/samples/typescript/publishWithOpenTelemetryTracing.ts +++ b/samples/typescript/publishWithOpenTelemetryTracing.ts @@ -78,7 +78,10 @@ async function publishMessage(topicNameOrId: string, data: string) { // Publishes the message as a string, e.g. "Hello, world!" // or JSON.stringify(someObject) const dataBuffer = Buffer.from(data); + + // Cache topic objects (publishers) and reuse them. const publisher = pubSubClient.topic(topicNameOrId); + const messageId = await publisher.publishMessage({data: dataBuffer}); console.log(`Message ${messageId} published.`); diff --git a/samples/typescript/publishWithRetrySettings.ts b/samples/typescript/publishWithRetrySettings.ts index 1add95d3d..b47498275 100644 --- a/samples/typescript/publishWithRetrySettings.ts +++ b/samples/typescript/publishWithRetrySettings.ts @@ -1,4 +1,4 @@ -// Copyright 2019-2023 Google LLC +// Copyright 2019-2024 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -35,39 +35,20 @@ // Imports the Google Cloud client library. v1 is for the lower level // proto access. -import {v1} from '@google-cloud/pubsub'; +import {PubSub} from '@google-cloud/pubsub'; -// Creates a publisher client. -const publisherClient = new v1.PublisherClient({ - // optional auth parameters -}); - -async function publishWithRetrySettings( - projectId: string, - topicNameOrId: string, - data: string -) { - const formattedTopic = publisherClient.projectTopicPath( - projectId, - topicNameOrId - ); - - // Publishes the message as a string, e.g. "Hello, world!" or JSON.stringify(someObject) - const dataBuffer = Buffer.from(data); - const messagesElement = { - data: dataBuffer, - }; - const messages = [messagesElement]; - - // Build the request - const request = { - topic: formattedTopic, - messages: messages, - }; +async function publishWithRetrySettings(topicNameOrId: string, data: string) { + const pubsubClient = new PubSub(); // Retry settings control how the publisher handles retryable failures. Default values are shown. // The `retryCodes` array determines which grpc errors will trigger an automatic retry. // The `backoffSettings` object lets you specify the behaviour of retries over time. + // + // Reference this document to see the current defaults for publishing: + // https://github.com/googleapis/nodejs-pubsub/blob/6e2c28a9298a49dc1b194ce747ff5258c8df6deb/src/v1/publisher_client_config.json#L59 + // + // Please note that _all_ items must be included when passing these settings to topic(). + // Otherwise, unpredictable (incorrect) defaults may be assumed. const retrySettings = { retryCodes: [ 10, // 'ABORTED' @@ -84,36 +65,42 @@ async function publishWithRetrySettings( initialRetryDelayMillis: 100, // The multiplier by which to increase the delay time between the completion // of failed requests, and the initiation of the subsequent retrying request. - retryDelayMultiplier: 1.3, + retryDelayMultiplier: 4, // The maximum delay time, in milliseconds, between requests. // When this value is reached, retryDelayMultiplier will no longer be used to increase delay time. maxRetryDelayMillis: 60000, // The initial timeout parameter to the request. - initialRpcTimeoutMillis: 5000, + initialRpcTimeoutMillis: 60000, // The multiplier by which to increase the timeout parameter between failed requests. rpcTimeoutMultiplier: 1.0, // The maximum timeout parameter, in milliseconds, for a request. When this value is reached, // rpcTimeoutMultiplier will no longer be used to increase the timeout. - maxRpcTimeoutMillis: 600000, + maxRpcTimeoutMillis: 60000, // The total time, in milliseconds, starting from when the initial request is sent, // after which an error will be returned, regardless of the retrying attempts made meanwhile. totalTimeoutMillis: 600000, }, }; - const [response] = await publisherClient.publish(request, { - retry: retrySettings, + // Cache topic objects (publishers) and reuse them. + const topic = pubsubClient.topic(topicNameOrId, { + gaxOpts: { + retry: retrySettings, + }, }); - console.log(`Message ${response.messageIds} published.`); + + // Publishes the message as a string, e.g. "Hello, world!" or JSON.stringify(someObject) + const dataBuffer = Buffer.from(data); + const messageId = await topic.publishMessage({data: dataBuffer}); + console.log(`Message ${messageId} published.`); } // [END pubsub_publisher_retry_settings] function main( - projectId = 'YOUR_PROJECT_ID', topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID', data = JSON.stringify({foo: 'bar'}) ) { - publishWithRetrySettings(projectId, topicNameOrId, data).catch(err => { + publishWithRetrySettings(topicNameOrId, data).catch(err => { console.error(err.message); process.exitCode = 1; }); diff --git a/samples/typescript/resumePublish.ts b/samples/typescript/resumePublish.ts index ca1e929b3..2a7f9680f 100644 --- a/samples/typescript/resumePublish.ts +++ b/samples/typescript/resumePublish.ts @@ -1,4 +1,4 @@ -// Copyright 2019-2023 Google LLC +// Copyright 2019-2024 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -52,8 +52,14 @@ async function resumePublish( messageOrdering: true, }; - // Publishes the message + // Cache topic objects (publishers) and reuse them. + // + // Pub/Sub's ordered delivery guarantee only applies when publishes for an ordering + // key are in the same region. For list of locational endpoints for Pub/Sub, see: + // https://cloud.google.com/pubsub/docs/reference/service_apis_overview#list_of_locational_endpoints const publisher = pubSubClient.topic(topicNameOrId, publishOptions); + + // Publishes the message try { const message = { data: dataBuffer, diff --git a/src/message-queues.ts b/src/message-queues.ts index a08330a36..b5d1275d2 100644 --- a/src/message-queues.ts +++ b/src/message-queues.ts @@ -55,6 +55,9 @@ export interface QueuedMessage { */ export type QueuedMessages = Array; +/** + * Batching options for sending acks and modacks back to the server. + */ export interface BatchOptions { callOptions?: CallOptions; maxMessages?: number; diff --git a/src/subscriber.ts b/src/subscriber.ts index c20b63be6..834165c7d 100644 --- a/src/subscriber.ts +++ b/src/subscriber.ts @@ -560,7 +560,8 @@ export class Message implements tracing.MessageWithAttributes { * ever have, while it's under library control. * @property {Duration} [maxAckDeadline] The maximum time that ackDeadline should * ever have, while it's under library control. - * @property {BatchOptions} [batching] Request batching options. + * @property {BatchOptions} [batching] Request batching options; this is for + * batching acks and modacks being sent back to the server. * @property {FlowControlOptions} [flowControl] Flow control options. * @property {boolean} [useLegacyFlowControl] Disables enforcing flow control * settings at the Cloud PubSub server and uses the less accurate method From 5ee05ccb1661b22feab614c833a0f05b3ace69aa Mon Sep 17 00:00:00 2001 From: sofisl <55454395+sofisl@users.noreply.github.com> Date: Wed, 23 Oct 2024 12:52:17 -0400 Subject: [PATCH 2/9] chore: delete unused templates (#1989) * Delete .github/ISSUE_TEMPLATE/bug_report.md * Delete .github/ISSUE_TEMPLATE/feature_request.md * Delete .github/ISSUE_TEMPLATE/question.md --- .github/ISSUE_TEMPLATE/bug_report.md | 38 ----------------------- .github/ISSUE_TEMPLATE/feature_request.md | 18 ----------- .github/ISSUE_TEMPLATE/question.md | 12 ------- 3 files changed, 68 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/bug_report.md delete mode 100644 .github/ISSUE_TEMPLATE/feature_request.md delete mode 100644 .github/ISSUE_TEMPLATE/question.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index 490cdb0aa..000000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,38 +0,0 @@ ---- -name: Bug report -about: Create a report to help us improve -labels: 'type: bug, priority: p2' ---- - -Thanks for stopping by to let us know something could be better! - -**PLEASE READ**: If you have a support contract with Google, please create an issue in the [support console](https://cloud.google.com/support/) instead of filing on GitHub. This will ensure a timely response. - -1) Is this a client library issue or a product issue? -This is the client library for . We will only be able to assist with issues that pertain to the behaviors of this library. If the issue you're experiencing is due to the behavior of the product itself, please visit the [ Support page]() to reach the most relevant engineers. - -2) Did someone already solve this? - - Search the issues already opened: https://github.com/googleapis/nodejs-pubsub/issues - - Search the issues on our "catch-all" repository: https://github.com/googleapis/google-cloud-node - - Search or ask on StackOverflow (engineers monitor these tags): http://stackoverflow.com/questions/tagged/google-cloud-platform+node.js - -3) Do you have a support contract? -Please create an issue in the [support console](https://cloud.google.com/support/) to ensure a timely response. - -If the support paths suggested above still do not result in a resolution, please provide the following details. - -#### Environment details - - - OS: - - Node.js version: - - npm version: - - `@google-cloud/pubsub` version: - -#### Steps to reproduce - - 1. ? - 2. ? - -Making sure to follow these steps will guarantee the quickest resolution possible. - -Thanks! diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index b0327dfa0..000000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -name: Feature request -about: Suggest an idea for this library -labels: 'type: feature request, priority: p3' ---- - -Thanks for stopping by to let us know something could be better! - -**PLEASE READ**: If you have a support contract with Google, please create an issue in the [support console](https://cloud.google.com/support/) instead of filing on GitHub. This will ensure a timely response. - - **Is your feature request related to a problem? Please describe.** -A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] - **Describe the solution you'd like** -A clear and concise description of what you want to happen. - **Describe alternatives you've considered** -A clear and concise description of any alternative solutions or features you've considered. - **Additional context** -Add any other context or screenshots about the feature request here. diff --git a/.github/ISSUE_TEMPLATE/question.md b/.github/ISSUE_TEMPLATE/question.md deleted file mode 100644 index 973231139..000000000 --- a/.github/ISSUE_TEMPLATE/question.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -name: Question -about: Ask a question -labels: 'type: question, priority: p3' ---- - -Thanks for stopping by to ask us a question! Please make sure to include: -- What you're trying to do -- What code you've already tried -- Any error messages you're getting - -**PLEASE READ**: If you have a support contract with Google, please create an issue in the [support console](https://cloud.google.com/support/) instead of filing on GitHub. This will ensure a timely response. From 586f5c1f671e6b37ef80e932d32fb8de3807fb59 Mon Sep 17 00:00:00 2001 From: Mend Renovate Date: Thu, 24 Oct 2024 19:52:09 +0200 Subject: [PATCH 3/9] chore(deps): update dependency gts to v6 (#1986) --- system-test/fixtures/sample/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system-test/fixtures/sample/package.json b/system-test/fixtures/sample/package.json index f4596200d..179237129 100644 --- a/system-test/fixtures/sample/package.json +++ b/system-test/fixtures/sample/package.json @@ -18,6 +18,6 @@ "devDependencies": { "@types/node": "^20.0.0", "typescript": "^4.6.4", - "gts": "^3.1.0" + "gts": "^6.0.0" } } From aaf537cca44f827d02cfb06af433f6425f40c387 Mon Sep 17 00:00:00 2001 From: Megan Potter <57276408+feywind@users.noreply.github.com> Date: Thu, 7 Nov 2024 16:31:02 -0500 Subject: [PATCH 4/9] build: revert gts version for system test fixtures, update TS version to match main package (#1995) --- system-test/fixtures/sample/package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system-test/fixtures/sample/package.json b/system-test/fixtures/sample/package.json index 179237129..0fd53d369 100644 --- a/system-test/fixtures/sample/package.json +++ b/system-test/fixtures/sample/package.json @@ -17,7 +17,7 @@ }, "devDependencies": { "@types/node": "^20.0.0", - "typescript": "^4.6.4", - "gts": "^6.0.0" + "typescript": "^5.1.6", + "gts": "^5.0.0" } } From 154714df56b1da09382708bd39551f5d0b581e31 Mon Sep 17 00:00:00 2001 From: Mend Renovate Date: Thu, 7 Nov 2024 22:56:52 +0100 Subject: [PATCH 5/9] chore(deps): update dependency @types/uuid to v10 (#1991) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d9bbaa757..8beb2b3e2 100644 --- a/package.json +++ b/package.json @@ -80,7 +80,7 @@ "@types/proxyquire": "^1.3.28", "@types/sinon": "^17.0.0", "@types/tmp": "^0.2.0", - "@types/uuid": "^9.0.0", + "@types/uuid": "^10.0.0", "c8": "^9.0.0", "codecov": "^3.0.0", "execa": "^5.0.0", From 48b5b7c6fa95c5ad07c620fce2591d8fb44f9e1c Mon Sep 17 00:00:00 2001 From: Mend Renovate Date: Thu, 7 Nov 2024 23:06:16 +0100 Subject: [PATCH 6/9] chore(deps): update dependency @types/node to v22 (#1993) --- package.json | 2 +- system-test/fixtures/sample/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 8beb2b3e2..279df9e5c 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "@types/mocha": "^9.0.0", "@types/mv": "^2.1.0", "@types/ncp": "^2.0.1", - "@types/node": "^20.0.0", + "@types/node": "^22.0.0", "@types/proxyquire": "^1.3.28", "@types/sinon": "^17.0.0", "@types/tmp": "^0.2.0", diff --git a/system-test/fixtures/sample/package.json b/system-test/fixtures/sample/package.json index 0fd53d369..1a2e039ef 100644 --- a/system-test/fixtures/sample/package.json +++ b/system-test/fixtures/sample/package.json @@ -16,7 +16,7 @@ "@google-cloud/pubsub": "file:./pubsub.tgz" }, "devDependencies": { - "@types/node": "^20.0.0", + "@types/node": "^22.0.0", "typescript": "^5.1.6", "gts": "^5.0.0" } From 70754309fb600c54d0a573f2d49ad4c419577550 Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 7 Nov 2024 17:26:20 -0500 Subject: [PATCH 7/9] feat: Add IngestionFailureEvent to the external proto (#1984) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Add IngestionFailureEvent to the external proto PiperOrigin-RevId: 684152766 Source-Link: https://github.com/googleapis/googleapis/commit/d992b0619ee79a2d32f6954cc29351ed8f15f560 Source-Link: https://github.com/googleapis/googleapis-gen/commit/f7405e1dc75cddd10a6aca96211318586fb61fc0 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZjc0MDVlMWRjNzVjZGRkMTBhNmFjYTk2MjExMzE4NTg2ZmI2MWZjMCJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot Co-authored-by: Megan Potter <57276408+feywind@users.noreply.github.com> --- protos/google/pubsub/v1/pubsub.proto | 57 ++ protos/protos.d.ts | 421 ++++++++++++ protos/protos.js | 972 +++++++++++++++++++++++++++ protos/protos.json | 87 +++ 4 files changed, 1537 insertions(+) diff --git a/protos/google/pubsub/v1/pubsub.proto b/protos/google/pubsub/v1/pubsub.proto index 54b44b822..0f269f525 100644 --- a/protos/google/pubsub/v1/pubsub.proto +++ b/protos/google/pubsub/v1/pubsub.proto @@ -365,6 +365,63 @@ message PlatformLogsSettings { Severity severity = 1 [(google.api.field_behavior) = OPTIONAL]; } +// Payload of the Platform Log entry sent when a failure is encountered while +// ingesting. +message IngestionFailureEvent { + // Specifies the reason why some data may have been left out of + // the desired Pub/Sub message due to the API message limits + // (https://cloud.google.com/pubsub/quotas#resource_limits). For example, + // when the number of attributes is larger than 100, the number of + // attributes is truncated to 100 to respect the limit on the attribute count. + // Other attribute limits are treated similarly. When the size of the desired + // message would've been larger than 10MB, the message won't be published at + // all, and ingestion of the subsequent messages will proceed as normal. + message ApiViolationReason {} + + // Set when an Avro file is unsupported or its format is not valid. When this + // occurs, one or more Avro objects won't be ingested. + message AvroFailureReason {} + + // Failure when ingesting from a Cloud Storage source. + message CloudStorageFailure { + // Optional. Name of the Cloud Storage bucket used for ingestion. + string bucket = 1 [(google.api.field_behavior) = OPTIONAL]; + + // Optional. Name of the Cloud Storage object which contained the section + // that couldn't be ingested. + string object_name = 2 [(google.api.field_behavior) = OPTIONAL]; + + // Optional. Generation of the Cloud Storage object which contained the + // section that couldn't be ingested. + int64 object_generation = 3 [(google.api.field_behavior) = OPTIONAL]; + + // Reason why ingestion failed for the specified object. + oneof reason { + // Optional. Failure encountered when parsing an Avro file. + AvroFailureReason avro_failure_reason = 5 + [(google.api.field_behavior) = OPTIONAL]; + + // Optional. The Pub/Sub API limits prevented the desired message from + // being published. + ApiViolationReason api_violation_reason = 6 + [(google.api.field_behavior) = OPTIONAL]; + } + } + + // Required. Name of the import topic. Format is: + // projects/{project_name}/topics/{topic_name}. + string topic = 1 [(google.api.field_behavior) = REQUIRED]; + + // Required. Error details explaining why ingestion to Pub/Sub has failed. + string error_message = 2 [(google.api.field_behavior) = REQUIRED]; + + oneof failure { + // Optional. Failure when ingesting from Cloud Storage. + CloudStorageFailure cloud_storage_failure = 3 + [(google.api.field_behavior) = OPTIONAL]; + } +} + // A topic resource. message Topic { option (google.api.resource) = { diff --git a/protos/protos.d.ts b/protos/protos.d.ts index eed0f3d03..1c673e0fe 100644 --- a/protos/protos.d.ts +++ b/protos/protos.d.ts @@ -1241,6 +1241,427 @@ export namespace google { } } + /** Properties of an IngestionFailureEvent. */ + interface IIngestionFailureEvent { + + /** IngestionFailureEvent topic */ + topic?: (string|null); + + /** IngestionFailureEvent errorMessage */ + errorMessage?: (string|null); + + /** IngestionFailureEvent cloudStorageFailure */ + cloudStorageFailure?: (google.pubsub.v1.IngestionFailureEvent.ICloudStorageFailure|null); + } + + /** Represents an IngestionFailureEvent. */ + class IngestionFailureEvent implements IIngestionFailureEvent { + + /** + * Constructs a new IngestionFailureEvent. + * @param [properties] Properties to set + */ + constructor(properties?: google.pubsub.v1.IIngestionFailureEvent); + + /** IngestionFailureEvent topic. */ + public topic: string; + + /** IngestionFailureEvent errorMessage. */ + public errorMessage: string; + + /** IngestionFailureEvent cloudStorageFailure. */ + public cloudStorageFailure?: (google.pubsub.v1.IngestionFailureEvent.ICloudStorageFailure|null); + + /** IngestionFailureEvent failure. */ + public failure?: "cloudStorageFailure"; + + /** + * Creates a new IngestionFailureEvent instance using the specified properties. + * @param [properties] Properties to set + * @returns IngestionFailureEvent instance + */ + public static create(properties?: google.pubsub.v1.IIngestionFailureEvent): google.pubsub.v1.IngestionFailureEvent; + + /** + * Encodes the specified IngestionFailureEvent message. Does not implicitly {@link google.pubsub.v1.IngestionFailureEvent.verify|verify} messages. + * @param message IngestionFailureEvent message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: google.pubsub.v1.IIngestionFailureEvent, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified IngestionFailureEvent message, length delimited. Does not implicitly {@link google.pubsub.v1.IngestionFailureEvent.verify|verify} messages. + * @param message IngestionFailureEvent message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: google.pubsub.v1.IIngestionFailureEvent, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes an IngestionFailureEvent message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns IngestionFailureEvent + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): google.pubsub.v1.IngestionFailureEvent; + + /** + * Decodes an IngestionFailureEvent message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns IngestionFailureEvent + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): google.pubsub.v1.IngestionFailureEvent; + + /** + * Verifies an IngestionFailureEvent message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates an IngestionFailureEvent message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns IngestionFailureEvent + */ + public static fromObject(object: { [k: string]: any }): google.pubsub.v1.IngestionFailureEvent; + + /** + * Creates a plain object from an IngestionFailureEvent message. Also converts values to other types if specified. + * @param message IngestionFailureEvent + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: google.pubsub.v1.IngestionFailureEvent, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this IngestionFailureEvent to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + + /** + * Gets the default type url for IngestionFailureEvent + * @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns The default type url + */ + public static getTypeUrl(typeUrlPrefix?: string): string; + } + + namespace IngestionFailureEvent { + + /** Properties of an ApiViolationReason. */ + interface IApiViolationReason { + } + + /** Represents an ApiViolationReason. */ + class ApiViolationReason implements IApiViolationReason { + + /** + * Constructs a new ApiViolationReason. + * @param [properties] Properties to set + */ + constructor(properties?: google.pubsub.v1.IngestionFailureEvent.IApiViolationReason); + + /** + * Creates a new ApiViolationReason instance using the specified properties. + * @param [properties] Properties to set + * @returns ApiViolationReason instance + */ + public static create(properties?: google.pubsub.v1.IngestionFailureEvent.IApiViolationReason): google.pubsub.v1.IngestionFailureEvent.ApiViolationReason; + + /** + * Encodes the specified ApiViolationReason message. Does not implicitly {@link google.pubsub.v1.IngestionFailureEvent.ApiViolationReason.verify|verify} messages. + * @param message ApiViolationReason message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: google.pubsub.v1.IngestionFailureEvent.IApiViolationReason, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified ApiViolationReason message, length delimited. Does not implicitly {@link google.pubsub.v1.IngestionFailureEvent.ApiViolationReason.verify|verify} messages. + * @param message ApiViolationReason message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: google.pubsub.v1.IngestionFailureEvent.IApiViolationReason, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes an ApiViolationReason message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns ApiViolationReason + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): google.pubsub.v1.IngestionFailureEvent.ApiViolationReason; + + /** + * Decodes an ApiViolationReason message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns ApiViolationReason + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): google.pubsub.v1.IngestionFailureEvent.ApiViolationReason; + + /** + * Verifies an ApiViolationReason message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates an ApiViolationReason message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns ApiViolationReason + */ + public static fromObject(object: { [k: string]: any }): google.pubsub.v1.IngestionFailureEvent.ApiViolationReason; + + /** + * Creates a plain object from an ApiViolationReason message. Also converts values to other types if specified. + * @param message ApiViolationReason + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: google.pubsub.v1.IngestionFailureEvent.ApiViolationReason, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this ApiViolationReason to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + + /** + * Gets the default type url for ApiViolationReason + * @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns The default type url + */ + public static getTypeUrl(typeUrlPrefix?: string): string; + } + + /** Properties of an AvroFailureReason. */ + interface IAvroFailureReason { + } + + /** Represents an AvroFailureReason. */ + class AvroFailureReason implements IAvroFailureReason { + + /** + * Constructs a new AvroFailureReason. + * @param [properties] Properties to set + */ + constructor(properties?: google.pubsub.v1.IngestionFailureEvent.IAvroFailureReason); + + /** + * Creates a new AvroFailureReason instance using the specified properties. + * @param [properties] Properties to set + * @returns AvroFailureReason instance + */ + public static create(properties?: google.pubsub.v1.IngestionFailureEvent.IAvroFailureReason): google.pubsub.v1.IngestionFailureEvent.AvroFailureReason; + + /** + * Encodes the specified AvroFailureReason message. Does not implicitly {@link google.pubsub.v1.IngestionFailureEvent.AvroFailureReason.verify|verify} messages. + * @param message AvroFailureReason message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: google.pubsub.v1.IngestionFailureEvent.IAvroFailureReason, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified AvroFailureReason message, length delimited. Does not implicitly {@link google.pubsub.v1.IngestionFailureEvent.AvroFailureReason.verify|verify} messages. + * @param message AvroFailureReason message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: google.pubsub.v1.IngestionFailureEvent.IAvroFailureReason, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes an AvroFailureReason message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns AvroFailureReason + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): google.pubsub.v1.IngestionFailureEvent.AvroFailureReason; + + /** + * Decodes an AvroFailureReason message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns AvroFailureReason + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): google.pubsub.v1.IngestionFailureEvent.AvroFailureReason; + + /** + * Verifies an AvroFailureReason message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates an AvroFailureReason message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns AvroFailureReason + */ + public static fromObject(object: { [k: string]: any }): google.pubsub.v1.IngestionFailureEvent.AvroFailureReason; + + /** + * Creates a plain object from an AvroFailureReason message. Also converts values to other types if specified. + * @param message AvroFailureReason + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: google.pubsub.v1.IngestionFailureEvent.AvroFailureReason, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this AvroFailureReason to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + + /** + * Gets the default type url for AvroFailureReason + * @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns The default type url + */ + public static getTypeUrl(typeUrlPrefix?: string): string; + } + + /** Properties of a CloudStorageFailure. */ + interface ICloudStorageFailure { + + /** CloudStorageFailure bucket */ + bucket?: (string|null); + + /** CloudStorageFailure objectName */ + objectName?: (string|null); + + /** CloudStorageFailure objectGeneration */ + objectGeneration?: (number|Long|string|null); + + /** CloudStorageFailure avroFailureReason */ + avroFailureReason?: (google.pubsub.v1.IngestionFailureEvent.IAvroFailureReason|null); + + /** CloudStorageFailure apiViolationReason */ + apiViolationReason?: (google.pubsub.v1.IngestionFailureEvent.IApiViolationReason|null); + } + + /** Represents a CloudStorageFailure. */ + class CloudStorageFailure implements ICloudStorageFailure { + + /** + * Constructs a new CloudStorageFailure. + * @param [properties] Properties to set + */ + constructor(properties?: google.pubsub.v1.IngestionFailureEvent.ICloudStorageFailure); + + /** CloudStorageFailure bucket. */ + public bucket: string; + + /** CloudStorageFailure objectName. */ + public objectName: string; + + /** CloudStorageFailure objectGeneration. */ + public objectGeneration: (number|Long|string); + + /** CloudStorageFailure avroFailureReason. */ + public avroFailureReason?: (google.pubsub.v1.IngestionFailureEvent.IAvroFailureReason|null); + + /** CloudStorageFailure apiViolationReason. */ + public apiViolationReason?: (google.pubsub.v1.IngestionFailureEvent.IApiViolationReason|null); + + /** CloudStorageFailure reason. */ + public reason?: ("avroFailureReason"|"apiViolationReason"); + + /** + * Creates a new CloudStorageFailure instance using the specified properties. + * @param [properties] Properties to set + * @returns CloudStorageFailure instance + */ + public static create(properties?: google.pubsub.v1.IngestionFailureEvent.ICloudStorageFailure): google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure; + + /** + * Encodes the specified CloudStorageFailure message. Does not implicitly {@link google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure.verify|verify} messages. + * @param message CloudStorageFailure message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: google.pubsub.v1.IngestionFailureEvent.ICloudStorageFailure, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Encodes the specified CloudStorageFailure message, length delimited. Does not implicitly {@link google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure.verify|verify} messages. + * @param message CloudStorageFailure message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: google.pubsub.v1.IngestionFailureEvent.ICloudStorageFailure, writer?: $protobuf.Writer): $protobuf.Writer; + + /** + * Decodes a CloudStorageFailure message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns CloudStorageFailure + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: ($protobuf.Reader|Uint8Array), length?: number): google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure; + + /** + * Decodes a CloudStorageFailure message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns CloudStorageFailure + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: ($protobuf.Reader|Uint8Array)): google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure; + + /** + * Verifies a CloudStorageFailure message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): (string|null); + + /** + * Creates a CloudStorageFailure message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns CloudStorageFailure + */ + public static fromObject(object: { [k: string]: any }): google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure; + + /** + * Creates a plain object from a CloudStorageFailure message. Also converts values to other types if specified. + * @param message CloudStorageFailure + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure, options?: $protobuf.IConversionOptions): { [k: string]: any }; + + /** + * Converts this CloudStorageFailure to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any }; + + /** + * Gets the default type url for CloudStorageFailure + * @param [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns The default type url + */ + public static getTypeUrl(typeUrlPrefix?: string): string; + } + } + /** Properties of a Topic. */ interface ITopic { diff --git a/protos/protos.js b/protos/protos.js index b54729ed3..590cfac5b 100644 --- a/protos/protos.js +++ b/protos/protos.js @@ -2864,6 +2864,978 @@ return PlatformLogsSettings; })(); + v1.IngestionFailureEvent = (function() { + + /** + * Properties of an IngestionFailureEvent. + * @memberof google.pubsub.v1 + * @interface IIngestionFailureEvent + * @property {string|null} [topic] IngestionFailureEvent topic + * @property {string|null} [errorMessage] IngestionFailureEvent errorMessage + * @property {google.pubsub.v1.IngestionFailureEvent.ICloudStorageFailure|null} [cloudStorageFailure] IngestionFailureEvent cloudStorageFailure + */ + + /** + * Constructs a new IngestionFailureEvent. + * @memberof google.pubsub.v1 + * @classdesc Represents an IngestionFailureEvent. + * @implements IIngestionFailureEvent + * @constructor + * @param {google.pubsub.v1.IIngestionFailureEvent=} [properties] Properties to set + */ + function IngestionFailureEvent(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * IngestionFailureEvent topic. + * @member {string} topic + * @memberof google.pubsub.v1.IngestionFailureEvent + * @instance + */ + IngestionFailureEvent.prototype.topic = ""; + + /** + * IngestionFailureEvent errorMessage. + * @member {string} errorMessage + * @memberof google.pubsub.v1.IngestionFailureEvent + * @instance + */ + IngestionFailureEvent.prototype.errorMessage = ""; + + /** + * IngestionFailureEvent cloudStorageFailure. + * @member {google.pubsub.v1.IngestionFailureEvent.ICloudStorageFailure|null|undefined} cloudStorageFailure + * @memberof google.pubsub.v1.IngestionFailureEvent + * @instance + */ + IngestionFailureEvent.prototype.cloudStorageFailure = null; + + // OneOf field names bound to virtual getters and setters + var $oneOfFields; + + /** + * IngestionFailureEvent failure. + * @member {"cloudStorageFailure"|undefined} failure + * @memberof google.pubsub.v1.IngestionFailureEvent + * @instance + */ + Object.defineProperty(IngestionFailureEvent.prototype, "failure", { + get: $util.oneOfGetter($oneOfFields = ["cloudStorageFailure"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Creates a new IngestionFailureEvent instance using the specified properties. + * @function create + * @memberof google.pubsub.v1.IngestionFailureEvent + * @static + * @param {google.pubsub.v1.IIngestionFailureEvent=} [properties] Properties to set + * @returns {google.pubsub.v1.IngestionFailureEvent} IngestionFailureEvent instance + */ + IngestionFailureEvent.create = function create(properties) { + return new IngestionFailureEvent(properties); + }; + + /** + * Encodes the specified IngestionFailureEvent message. Does not implicitly {@link google.pubsub.v1.IngestionFailureEvent.verify|verify} messages. + * @function encode + * @memberof google.pubsub.v1.IngestionFailureEvent + * @static + * @param {google.pubsub.v1.IIngestionFailureEvent} message IngestionFailureEvent message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + IngestionFailureEvent.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.topic != null && Object.hasOwnProperty.call(message, "topic")) + writer.uint32(/* id 1, wireType 2 =*/10).string(message.topic); + if (message.errorMessage != null && Object.hasOwnProperty.call(message, "errorMessage")) + writer.uint32(/* id 2, wireType 2 =*/18).string(message.errorMessage); + if (message.cloudStorageFailure != null && Object.hasOwnProperty.call(message, "cloudStorageFailure")) + $root.google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure.encode(message.cloudStorageFailure, writer.uint32(/* id 3, wireType 2 =*/26).fork()).ldelim(); + return writer; + }; + + /** + * Encodes the specified IngestionFailureEvent message, length delimited. Does not implicitly {@link google.pubsub.v1.IngestionFailureEvent.verify|verify} messages. + * @function encodeDelimited + * @memberof google.pubsub.v1.IngestionFailureEvent + * @static + * @param {google.pubsub.v1.IIngestionFailureEvent} message IngestionFailureEvent message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + IngestionFailureEvent.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes an IngestionFailureEvent message from the specified reader or buffer. + * @function decode + * @memberof google.pubsub.v1.IngestionFailureEvent + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {google.pubsub.v1.IngestionFailureEvent} IngestionFailureEvent + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + IngestionFailureEvent.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.pubsub.v1.IngestionFailureEvent(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: { + message.topic = reader.string(); + break; + } + case 2: { + message.errorMessage = reader.string(); + break; + } + case 3: { + message.cloudStorageFailure = $root.google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure.decode(reader, reader.uint32()); + break; + } + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes an IngestionFailureEvent message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof google.pubsub.v1.IngestionFailureEvent + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {google.pubsub.v1.IngestionFailureEvent} IngestionFailureEvent + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + IngestionFailureEvent.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies an IngestionFailureEvent message. + * @function verify + * @memberof google.pubsub.v1.IngestionFailureEvent + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + IngestionFailureEvent.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + var properties = {}; + if (message.topic != null && message.hasOwnProperty("topic")) + if (!$util.isString(message.topic)) + return "topic: string expected"; + if (message.errorMessage != null && message.hasOwnProperty("errorMessage")) + if (!$util.isString(message.errorMessage)) + return "errorMessage: string expected"; + if (message.cloudStorageFailure != null && message.hasOwnProperty("cloudStorageFailure")) { + properties.failure = 1; + { + var error = $root.google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure.verify(message.cloudStorageFailure); + if (error) + return "cloudStorageFailure." + error; + } + } + return null; + }; + + /** + * Creates an IngestionFailureEvent message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof google.pubsub.v1.IngestionFailureEvent + * @static + * @param {Object.} object Plain object + * @returns {google.pubsub.v1.IngestionFailureEvent} IngestionFailureEvent + */ + IngestionFailureEvent.fromObject = function fromObject(object) { + if (object instanceof $root.google.pubsub.v1.IngestionFailureEvent) + return object; + var message = new $root.google.pubsub.v1.IngestionFailureEvent(); + if (object.topic != null) + message.topic = String(object.topic); + if (object.errorMessage != null) + message.errorMessage = String(object.errorMessage); + if (object.cloudStorageFailure != null) { + if (typeof object.cloudStorageFailure !== "object") + throw TypeError(".google.pubsub.v1.IngestionFailureEvent.cloudStorageFailure: object expected"); + message.cloudStorageFailure = $root.google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure.fromObject(object.cloudStorageFailure); + } + return message; + }; + + /** + * Creates a plain object from an IngestionFailureEvent message. Also converts values to other types if specified. + * @function toObject + * @memberof google.pubsub.v1.IngestionFailureEvent + * @static + * @param {google.pubsub.v1.IngestionFailureEvent} message IngestionFailureEvent + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + IngestionFailureEvent.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) { + object.topic = ""; + object.errorMessage = ""; + } + if (message.topic != null && message.hasOwnProperty("topic")) + object.topic = message.topic; + if (message.errorMessage != null && message.hasOwnProperty("errorMessage")) + object.errorMessage = message.errorMessage; + if (message.cloudStorageFailure != null && message.hasOwnProperty("cloudStorageFailure")) { + object.cloudStorageFailure = $root.google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure.toObject(message.cloudStorageFailure, options); + if (options.oneofs) + object.failure = "cloudStorageFailure"; + } + return object; + }; + + /** + * Converts this IngestionFailureEvent to JSON. + * @function toJSON + * @memberof google.pubsub.v1.IngestionFailureEvent + * @instance + * @returns {Object.} JSON object + */ + IngestionFailureEvent.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for IngestionFailureEvent + * @function getTypeUrl + * @memberof google.pubsub.v1.IngestionFailureEvent + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + IngestionFailureEvent.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/google.pubsub.v1.IngestionFailureEvent"; + }; + + IngestionFailureEvent.ApiViolationReason = (function() { + + /** + * Properties of an ApiViolationReason. + * @memberof google.pubsub.v1.IngestionFailureEvent + * @interface IApiViolationReason + */ + + /** + * Constructs a new ApiViolationReason. + * @memberof google.pubsub.v1.IngestionFailureEvent + * @classdesc Represents an ApiViolationReason. + * @implements IApiViolationReason + * @constructor + * @param {google.pubsub.v1.IngestionFailureEvent.IApiViolationReason=} [properties] Properties to set + */ + function ApiViolationReason(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * Creates a new ApiViolationReason instance using the specified properties. + * @function create + * @memberof google.pubsub.v1.IngestionFailureEvent.ApiViolationReason + * @static + * @param {google.pubsub.v1.IngestionFailureEvent.IApiViolationReason=} [properties] Properties to set + * @returns {google.pubsub.v1.IngestionFailureEvent.ApiViolationReason} ApiViolationReason instance + */ + ApiViolationReason.create = function create(properties) { + return new ApiViolationReason(properties); + }; + + /** + * Encodes the specified ApiViolationReason message. Does not implicitly {@link google.pubsub.v1.IngestionFailureEvent.ApiViolationReason.verify|verify} messages. + * @function encode + * @memberof google.pubsub.v1.IngestionFailureEvent.ApiViolationReason + * @static + * @param {google.pubsub.v1.IngestionFailureEvent.IApiViolationReason} message ApiViolationReason message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ApiViolationReason.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + return writer; + }; + + /** + * Encodes the specified ApiViolationReason message, length delimited. Does not implicitly {@link google.pubsub.v1.IngestionFailureEvent.ApiViolationReason.verify|verify} messages. + * @function encodeDelimited + * @memberof google.pubsub.v1.IngestionFailureEvent.ApiViolationReason + * @static + * @param {google.pubsub.v1.IngestionFailureEvent.IApiViolationReason} message ApiViolationReason message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + ApiViolationReason.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes an ApiViolationReason message from the specified reader or buffer. + * @function decode + * @memberof google.pubsub.v1.IngestionFailureEvent.ApiViolationReason + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {google.pubsub.v1.IngestionFailureEvent.ApiViolationReason} ApiViolationReason + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ApiViolationReason.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.pubsub.v1.IngestionFailureEvent.ApiViolationReason(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes an ApiViolationReason message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof google.pubsub.v1.IngestionFailureEvent.ApiViolationReason + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {google.pubsub.v1.IngestionFailureEvent.ApiViolationReason} ApiViolationReason + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + ApiViolationReason.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies an ApiViolationReason message. + * @function verify + * @memberof google.pubsub.v1.IngestionFailureEvent.ApiViolationReason + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + ApiViolationReason.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + return null; + }; + + /** + * Creates an ApiViolationReason message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof google.pubsub.v1.IngestionFailureEvent.ApiViolationReason + * @static + * @param {Object.} object Plain object + * @returns {google.pubsub.v1.IngestionFailureEvent.ApiViolationReason} ApiViolationReason + */ + ApiViolationReason.fromObject = function fromObject(object) { + if (object instanceof $root.google.pubsub.v1.IngestionFailureEvent.ApiViolationReason) + return object; + return new $root.google.pubsub.v1.IngestionFailureEvent.ApiViolationReason(); + }; + + /** + * Creates a plain object from an ApiViolationReason message. Also converts values to other types if specified. + * @function toObject + * @memberof google.pubsub.v1.IngestionFailureEvent.ApiViolationReason + * @static + * @param {google.pubsub.v1.IngestionFailureEvent.ApiViolationReason} message ApiViolationReason + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + ApiViolationReason.toObject = function toObject() { + return {}; + }; + + /** + * Converts this ApiViolationReason to JSON. + * @function toJSON + * @memberof google.pubsub.v1.IngestionFailureEvent.ApiViolationReason + * @instance + * @returns {Object.} JSON object + */ + ApiViolationReason.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for ApiViolationReason + * @function getTypeUrl + * @memberof google.pubsub.v1.IngestionFailureEvent.ApiViolationReason + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + ApiViolationReason.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/google.pubsub.v1.IngestionFailureEvent.ApiViolationReason"; + }; + + return ApiViolationReason; + })(); + + IngestionFailureEvent.AvroFailureReason = (function() { + + /** + * Properties of an AvroFailureReason. + * @memberof google.pubsub.v1.IngestionFailureEvent + * @interface IAvroFailureReason + */ + + /** + * Constructs a new AvroFailureReason. + * @memberof google.pubsub.v1.IngestionFailureEvent + * @classdesc Represents an AvroFailureReason. + * @implements IAvroFailureReason + * @constructor + * @param {google.pubsub.v1.IngestionFailureEvent.IAvroFailureReason=} [properties] Properties to set + */ + function AvroFailureReason(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * Creates a new AvroFailureReason instance using the specified properties. + * @function create + * @memberof google.pubsub.v1.IngestionFailureEvent.AvroFailureReason + * @static + * @param {google.pubsub.v1.IngestionFailureEvent.IAvroFailureReason=} [properties] Properties to set + * @returns {google.pubsub.v1.IngestionFailureEvent.AvroFailureReason} AvroFailureReason instance + */ + AvroFailureReason.create = function create(properties) { + return new AvroFailureReason(properties); + }; + + /** + * Encodes the specified AvroFailureReason message. Does not implicitly {@link google.pubsub.v1.IngestionFailureEvent.AvroFailureReason.verify|verify} messages. + * @function encode + * @memberof google.pubsub.v1.IngestionFailureEvent.AvroFailureReason + * @static + * @param {google.pubsub.v1.IngestionFailureEvent.IAvroFailureReason} message AvroFailureReason message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + AvroFailureReason.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + return writer; + }; + + /** + * Encodes the specified AvroFailureReason message, length delimited. Does not implicitly {@link google.pubsub.v1.IngestionFailureEvent.AvroFailureReason.verify|verify} messages. + * @function encodeDelimited + * @memberof google.pubsub.v1.IngestionFailureEvent.AvroFailureReason + * @static + * @param {google.pubsub.v1.IngestionFailureEvent.IAvroFailureReason} message AvroFailureReason message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + AvroFailureReason.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes an AvroFailureReason message from the specified reader or buffer. + * @function decode + * @memberof google.pubsub.v1.IngestionFailureEvent.AvroFailureReason + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {google.pubsub.v1.IngestionFailureEvent.AvroFailureReason} AvroFailureReason + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + AvroFailureReason.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.pubsub.v1.IngestionFailureEvent.AvroFailureReason(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes an AvroFailureReason message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof google.pubsub.v1.IngestionFailureEvent.AvroFailureReason + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {google.pubsub.v1.IngestionFailureEvent.AvroFailureReason} AvroFailureReason + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + AvroFailureReason.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies an AvroFailureReason message. + * @function verify + * @memberof google.pubsub.v1.IngestionFailureEvent.AvroFailureReason + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + AvroFailureReason.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + return null; + }; + + /** + * Creates an AvroFailureReason message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof google.pubsub.v1.IngestionFailureEvent.AvroFailureReason + * @static + * @param {Object.} object Plain object + * @returns {google.pubsub.v1.IngestionFailureEvent.AvroFailureReason} AvroFailureReason + */ + AvroFailureReason.fromObject = function fromObject(object) { + if (object instanceof $root.google.pubsub.v1.IngestionFailureEvent.AvroFailureReason) + return object; + return new $root.google.pubsub.v1.IngestionFailureEvent.AvroFailureReason(); + }; + + /** + * Creates a plain object from an AvroFailureReason message. Also converts values to other types if specified. + * @function toObject + * @memberof google.pubsub.v1.IngestionFailureEvent.AvroFailureReason + * @static + * @param {google.pubsub.v1.IngestionFailureEvent.AvroFailureReason} message AvroFailureReason + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + AvroFailureReason.toObject = function toObject() { + return {}; + }; + + /** + * Converts this AvroFailureReason to JSON. + * @function toJSON + * @memberof google.pubsub.v1.IngestionFailureEvent.AvroFailureReason + * @instance + * @returns {Object.} JSON object + */ + AvroFailureReason.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for AvroFailureReason + * @function getTypeUrl + * @memberof google.pubsub.v1.IngestionFailureEvent.AvroFailureReason + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + AvroFailureReason.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/google.pubsub.v1.IngestionFailureEvent.AvroFailureReason"; + }; + + return AvroFailureReason; + })(); + + IngestionFailureEvent.CloudStorageFailure = (function() { + + /** + * Properties of a CloudStorageFailure. + * @memberof google.pubsub.v1.IngestionFailureEvent + * @interface ICloudStorageFailure + * @property {string|null} [bucket] CloudStorageFailure bucket + * @property {string|null} [objectName] CloudStorageFailure objectName + * @property {number|Long|null} [objectGeneration] CloudStorageFailure objectGeneration + * @property {google.pubsub.v1.IngestionFailureEvent.IAvroFailureReason|null} [avroFailureReason] CloudStorageFailure avroFailureReason + * @property {google.pubsub.v1.IngestionFailureEvent.IApiViolationReason|null} [apiViolationReason] CloudStorageFailure apiViolationReason + */ + + /** + * Constructs a new CloudStorageFailure. + * @memberof google.pubsub.v1.IngestionFailureEvent + * @classdesc Represents a CloudStorageFailure. + * @implements ICloudStorageFailure + * @constructor + * @param {google.pubsub.v1.IngestionFailureEvent.ICloudStorageFailure=} [properties] Properties to set + */ + function CloudStorageFailure(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * CloudStorageFailure bucket. + * @member {string} bucket + * @memberof google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure + * @instance + */ + CloudStorageFailure.prototype.bucket = ""; + + /** + * CloudStorageFailure objectName. + * @member {string} objectName + * @memberof google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure + * @instance + */ + CloudStorageFailure.prototype.objectName = ""; + + /** + * CloudStorageFailure objectGeneration. + * @member {number|Long} objectGeneration + * @memberof google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure + * @instance + */ + CloudStorageFailure.prototype.objectGeneration = $util.Long ? $util.Long.fromBits(0,0,false) : 0; + + /** + * CloudStorageFailure avroFailureReason. + * @member {google.pubsub.v1.IngestionFailureEvent.IAvroFailureReason|null|undefined} avroFailureReason + * @memberof google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure + * @instance + */ + CloudStorageFailure.prototype.avroFailureReason = null; + + /** + * CloudStorageFailure apiViolationReason. + * @member {google.pubsub.v1.IngestionFailureEvent.IApiViolationReason|null|undefined} apiViolationReason + * @memberof google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure + * @instance + */ + CloudStorageFailure.prototype.apiViolationReason = null; + + // OneOf field names bound to virtual getters and setters + var $oneOfFields; + + /** + * CloudStorageFailure reason. + * @member {"avroFailureReason"|"apiViolationReason"|undefined} reason + * @memberof google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure + * @instance + */ + Object.defineProperty(CloudStorageFailure.prototype, "reason", { + get: $util.oneOfGetter($oneOfFields = ["avroFailureReason", "apiViolationReason"]), + set: $util.oneOfSetter($oneOfFields) + }); + + /** + * Creates a new CloudStorageFailure instance using the specified properties. + * @function create + * @memberof google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure + * @static + * @param {google.pubsub.v1.IngestionFailureEvent.ICloudStorageFailure=} [properties] Properties to set + * @returns {google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure} CloudStorageFailure instance + */ + CloudStorageFailure.create = function create(properties) { + return new CloudStorageFailure(properties); + }; + + /** + * Encodes the specified CloudStorageFailure message. Does not implicitly {@link google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure.verify|verify} messages. + * @function encode + * @memberof google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure + * @static + * @param {google.pubsub.v1.IngestionFailureEvent.ICloudStorageFailure} message CloudStorageFailure message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + CloudStorageFailure.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.bucket != null && Object.hasOwnProperty.call(message, "bucket")) + writer.uint32(/* id 1, wireType 2 =*/10).string(message.bucket); + if (message.objectName != null && Object.hasOwnProperty.call(message, "objectName")) + writer.uint32(/* id 2, wireType 2 =*/18).string(message.objectName); + if (message.objectGeneration != null && Object.hasOwnProperty.call(message, "objectGeneration")) + writer.uint32(/* id 3, wireType 0 =*/24).int64(message.objectGeneration); + if (message.avroFailureReason != null && Object.hasOwnProperty.call(message, "avroFailureReason")) + $root.google.pubsub.v1.IngestionFailureEvent.AvroFailureReason.encode(message.avroFailureReason, writer.uint32(/* id 5, wireType 2 =*/42).fork()).ldelim(); + if (message.apiViolationReason != null && Object.hasOwnProperty.call(message, "apiViolationReason")) + $root.google.pubsub.v1.IngestionFailureEvent.ApiViolationReason.encode(message.apiViolationReason, writer.uint32(/* id 6, wireType 2 =*/50).fork()).ldelim(); + return writer; + }; + + /** + * Encodes the specified CloudStorageFailure message, length delimited. Does not implicitly {@link google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure.verify|verify} messages. + * @function encodeDelimited + * @memberof google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure + * @static + * @param {google.pubsub.v1.IngestionFailureEvent.ICloudStorageFailure} message CloudStorageFailure message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + CloudStorageFailure.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a CloudStorageFailure message from the specified reader or buffer. + * @function decode + * @memberof google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure} CloudStorageFailure + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + CloudStorageFailure.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: { + message.bucket = reader.string(); + break; + } + case 2: { + message.objectName = reader.string(); + break; + } + case 3: { + message.objectGeneration = reader.int64(); + break; + } + case 5: { + message.avroFailureReason = $root.google.pubsub.v1.IngestionFailureEvent.AvroFailureReason.decode(reader, reader.uint32()); + break; + } + case 6: { + message.apiViolationReason = $root.google.pubsub.v1.IngestionFailureEvent.ApiViolationReason.decode(reader, reader.uint32()); + break; + } + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a CloudStorageFailure message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure} CloudStorageFailure + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + CloudStorageFailure.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a CloudStorageFailure message. + * @function verify + * @memberof google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + CloudStorageFailure.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + var properties = {}; + if (message.bucket != null && message.hasOwnProperty("bucket")) + if (!$util.isString(message.bucket)) + return "bucket: string expected"; + if (message.objectName != null && message.hasOwnProperty("objectName")) + if (!$util.isString(message.objectName)) + return "objectName: string expected"; + if (message.objectGeneration != null && message.hasOwnProperty("objectGeneration")) + if (!$util.isInteger(message.objectGeneration) && !(message.objectGeneration && $util.isInteger(message.objectGeneration.low) && $util.isInteger(message.objectGeneration.high))) + return "objectGeneration: integer|Long expected"; + if (message.avroFailureReason != null && message.hasOwnProperty("avroFailureReason")) { + properties.reason = 1; + { + var error = $root.google.pubsub.v1.IngestionFailureEvent.AvroFailureReason.verify(message.avroFailureReason); + if (error) + return "avroFailureReason." + error; + } + } + if (message.apiViolationReason != null && message.hasOwnProperty("apiViolationReason")) { + if (properties.reason === 1) + return "reason: multiple values"; + properties.reason = 1; + { + var error = $root.google.pubsub.v1.IngestionFailureEvent.ApiViolationReason.verify(message.apiViolationReason); + if (error) + return "apiViolationReason." + error; + } + } + return null; + }; + + /** + * Creates a CloudStorageFailure message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure + * @static + * @param {Object.} object Plain object + * @returns {google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure} CloudStorageFailure + */ + CloudStorageFailure.fromObject = function fromObject(object) { + if (object instanceof $root.google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure) + return object; + var message = new $root.google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure(); + if (object.bucket != null) + message.bucket = String(object.bucket); + if (object.objectName != null) + message.objectName = String(object.objectName); + if (object.objectGeneration != null) + if ($util.Long) + (message.objectGeneration = $util.Long.fromValue(object.objectGeneration)).unsigned = false; + else if (typeof object.objectGeneration === "string") + message.objectGeneration = parseInt(object.objectGeneration, 10); + else if (typeof object.objectGeneration === "number") + message.objectGeneration = object.objectGeneration; + else if (typeof object.objectGeneration === "object") + message.objectGeneration = new $util.LongBits(object.objectGeneration.low >>> 0, object.objectGeneration.high >>> 0).toNumber(); + if (object.avroFailureReason != null) { + if (typeof object.avroFailureReason !== "object") + throw TypeError(".google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure.avroFailureReason: object expected"); + message.avroFailureReason = $root.google.pubsub.v1.IngestionFailureEvent.AvroFailureReason.fromObject(object.avroFailureReason); + } + if (object.apiViolationReason != null) { + if (typeof object.apiViolationReason !== "object") + throw TypeError(".google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure.apiViolationReason: object expected"); + message.apiViolationReason = $root.google.pubsub.v1.IngestionFailureEvent.ApiViolationReason.fromObject(object.apiViolationReason); + } + return message; + }; + + /** + * Creates a plain object from a CloudStorageFailure message. Also converts values to other types if specified. + * @function toObject + * @memberof google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure + * @static + * @param {google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure} message CloudStorageFailure + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + CloudStorageFailure.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) { + object.bucket = ""; + object.objectName = ""; + if ($util.Long) { + var long = new $util.Long(0, 0, false); + object.objectGeneration = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long; + } else + object.objectGeneration = options.longs === String ? "0" : 0; + } + if (message.bucket != null && message.hasOwnProperty("bucket")) + object.bucket = message.bucket; + if (message.objectName != null && message.hasOwnProperty("objectName")) + object.objectName = message.objectName; + if (message.objectGeneration != null && message.hasOwnProperty("objectGeneration")) + if (typeof message.objectGeneration === "number") + object.objectGeneration = options.longs === String ? String(message.objectGeneration) : message.objectGeneration; + else + object.objectGeneration = options.longs === String ? $util.Long.prototype.toString.call(message.objectGeneration) : options.longs === Number ? new $util.LongBits(message.objectGeneration.low >>> 0, message.objectGeneration.high >>> 0).toNumber() : message.objectGeneration; + if (message.avroFailureReason != null && message.hasOwnProperty("avroFailureReason")) { + object.avroFailureReason = $root.google.pubsub.v1.IngestionFailureEvent.AvroFailureReason.toObject(message.avroFailureReason, options); + if (options.oneofs) + object.reason = "avroFailureReason"; + } + if (message.apiViolationReason != null && message.hasOwnProperty("apiViolationReason")) { + object.apiViolationReason = $root.google.pubsub.v1.IngestionFailureEvent.ApiViolationReason.toObject(message.apiViolationReason, options); + if (options.oneofs) + object.reason = "apiViolationReason"; + } + return object; + }; + + /** + * Converts this CloudStorageFailure to JSON. + * @function toJSON + * @memberof google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure + * @instance + * @returns {Object.} JSON object + */ + CloudStorageFailure.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + /** + * Gets the default type url for CloudStorageFailure + * @function getTypeUrl + * @memberof google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure + * @static + * @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com") + * @returns {string} The default type url + */ + CloudStorageFailure.getTypeUrl = function getTypeUrl(typeUrlPrefix) { + if (typeUrlPrefix === undefined) { + typeUrlPrefix = "type.googleapis.com"; + } + return typeUrlPrefix + "/google.pubsub.v1.IngestionFailureEvent.CloudStorageFailure"; + }; + + return CloudStorageFailure; + })(); + + return IngestionFailureEvent; + })(); + v1.Topic = (function() { /** diff --git a/protos/protos.json b/protos/protos.json index 8921f219f..a72a72967 100644 --- a/protos/protos.json +++ b/protos/protos.json @@ -451,6 +451,93 @@ } } }, + "IngestionFailureEvent": { + "oneofs": { + "failure": { + "oneof": [ + "cloudStorageFailure" + ] + } + }, + "fields": { + "topic": { + "type": "string", + "id": 1, + "options": { + "(google.api.field_behavior)": "REQUIRED" + } + }, + "errorMessage": { + "type": "string", + "id": 2, + "options": { + "(google.api.field_behavior)": "REQUIRED" + } + }, + "cloudStorageFailure": { + "type": "CloudStorageFailure", + "id": 3, + "options": { + "(google.api.field_behavior)": "OPTIONAL" + } + } + }, + "nested": { + "ApiViolationReason": { + "fields": {} + }, + "AvroFailureReason": { + "fields": {} + }, + "CloudStorageFailure": { + "oneofs": { + "reason": { + "oneof": [ + "avroFailureReason", + "apiViolationReason" + ] + } + }, + "fields": { + "bucket": { + "type": "string", + "id": 1, + "options": { + "(google.api.field_behavior)": "OPTIONAL" + } + }, + "objectName": { + "type": "string", + "id": 2, + "options": { + "(google.api.field_behavior)": "OPTIONAL" + } + }, + "objectGeneration": { + "type": "int64", + "id": 3, + "options": { + "(google.api.field_behavior)": "OPTIONAL" + } + }, + "avroFailureReason": { + "type": "AvroFailureReason", + "id": 5, + "options": { + "(google.api.field_behavior)": "OPTIONAL" + } + }, + "apiViolationReason": { + "type": "ApiViolationReason", + "id": 6, + "options": { + "(google.api.field_behavior)": "OPTIONAL" + } + } + } + } + } + }, "Topic": { "options": { "(google.api.resource).type": "pubsub.googleapis.com/Topic", From 798270db9c5ef71f75c3e24e70d9592bbd068212 Mon Sep 17 00:00:00 2001 From: Megan Potter <57276408+feywind@users.noreply.github.com> Date: Tue, 12 Nov 2024 16:50:25 -0500 Subject: [PATCH 8/9] fix: KiB, not MiB for ack size limits (#1999) --- src/message-queues.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/message-queues.ts b/src/message-queues.ts index b5d1275d2..adc565c3e 100644 --- a/src/message-queues.ts +++ b/src/message-queues.ts @@ -67,7 +67,7 @@ export interface BatchOptions { // This is the maximum number of bytes we will send for a batch of // ack/modack messages. The server itself has a maximum of 512KiB, so // we just pull back a little from that in case of unknown fenceposts. -export const MAX_BATCH_BYTES = 510 * 1024 * 1024; +export const MAX_BATCH_BYTES = 510 * 1024; /** * Error class used to signal a batch failure. From ed621a25d9058607af5e10ead5badeccff7e26c5 Mon Sep 17 00:00:00 2001 From: "release-please[bot]" <55107282+release-please[bot]@users.noreply.github.com> Date: Tue, 12 Nov 2024 17:12:20 -0500 Subject: [PATCH 9/9] chore(main): release 4.9.0 (#1997) Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com> --- CHANGELOG.md | 12 ++++++++++++ package.json | 2 +- samples/package.json | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 96023ed8a..2f6317eac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,18 @@ [1]: https://www.npmjs.com/package/@google-cloud/pubsub?activeTab=versions +## [4.9.0](https://github.com/googleapis/nodejs-pubsub/compare/v4.8.0...v4.9.0) (2024-11-12) + + +### Features + +* Add IngestionFailureEvent to the external proto ([#1984](https://github.com/googleapis/nodejs-pubsub/issues/1984)) ([7075430](https://github.com/googleapis/nodejs-pubsub/commit/70754309fb600c54d0a573f2d49ad4c419577550)) + + +### Bug Fixes + +* KiB, not MiB for ack size limits ([#1999](https://github.com/googleapis/nodejs-pubsub/issues/1999)) ([798270d](https://github.com/googleapis/nodejs-pubsub/commit/798270db9c5ef71f75c3e24e70d9592bbd068212)) + ## [4.8.0](https://github.com/googleapis/nodejs-pubsub/compare/v4.7.2...v4.8.0) (2024-10-15) diff --git a/package.json b/package.json index 279df9e5c..c31ea1b14 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@google-cloud/pubsub", "description": "Cloud Pub/Sub Client Library for Node.js", - "version": "4.8.0", + "version": "4.9.0", "license": "Apache-2.0", "author": "Google Inc.", "engines": { diff --git a/samples/package.json b/samples/package.json index 083fd4e4a..87fcd15ca 100644 --- a/samples/package.json +++ b/samples/package.json @@ -22,7 +22,7 @@ }, "dependencies": { "@google-cloud/opentelemetry-cloud-trace-exporter": "^2.0.0", - "@google-cloud/pubsub": "^4.8.0", + "@google-cloud/pubsub": "^4.9.0", "@google-cloud/storage": "^7.11.1", "@opentelemetry/api": "^1.6.0", "@opentelemetry/resources": "^1.17.0",