From 1ebc08d80a36bf5efc34ba2cef021d0367a6d617 Mon Sep 17 00:00:00 2001 From: feywind <57276408+feywind@users.noreply.github.com> Date: Wed, 20 Dec 2023 16:26:22 -0500 Subject: [PATCH 01/11] samples: add sample for push subscription with no wrapper --- samples/createPushSubscriptionNoWrapper.js | 79 +++++++++++++++++++ samples/system-test/subscriptions.test.ts | 19 +++++ .../createPushSubscriptionNoWrapper.ts | 75 ++++++++++++++++++ 3 files changed, 173 insertions(+) create mode 100644 samples/createPushSubscriptionNoWrapper.js create mode 100644 samples/typescript/createPushSubscriptionNoWrapper.ts diff --git a/samples/createPushSubscriptionNoWrapper.js b/samples/createPushSubscriptionNoWrapper.js new file mode 100644 index 000000000..6297ff659 --- /dev/null +++ b/samples/createPushSubscriptionNoWrapper.js @@ -0,0 +1,79 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// This is a generated sample, using the typeless sample bot. Please +// look for the source TypeScript sample (.ts) for modifications. +'use strict'; + +/** + * This application demonstrates how to perform basic operations on + * subscriptions with the Google Cloud Pub/Sub API. + * + * For more information, see the README.md under /pubsub and the documentation + * at https://cloud.google.com/pubsub/docs. + */ + +// sample-metadata: +// title: Create Push Subscription With No Wrapper +// description: Creates a new push subscription, but disables metadata wrapping. +// usage: node createPushSubscriptionNoWrapper.js + +// [START pubsub_create_push_no_wrapper_subscription] +/** + * TODO(developer): Uncomment these variables before running the sample. + */ +// const topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID'; +// const subscriptionNameOrId = 'YOUR_SUBSCRIPTION_NAME_OR_ID'; + +// Imports the Google Cloud client library +const {PubSub} = require('@google-cloud/pubsub'); + +// Creates a client; cache this for further use +const pubSubClient = new PubSub(); + +async function createPushSubscriptionNoWrapper( + topicNameOrId, + subscriptionNameOrId +) { + const options = { + pushConfig: { + // Set to an HTTPS endpoint of your choice. If necessary, register + // (authorize) the domain on which the server is hosted. + pushEndpoint: `https://${pubSubClient.projectId}.appspot.com/push`, + noWrapper: { + writeMetadata: true, + }, + }, + }; + + await pubSubClient + .topic(topicNameOrId) + .createSubscription(subscriptionNameOrId, options); + console.log(`Subscription ${subscriptionNameOrId} created.`); +} +// [END pubsub_create_push_no_wrapper_subscription] + +function main( + topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID', + subscriptionNameOrId = 'YOUR_SUBSCRIPTION_NAME_OR_ID' +) { + createPushSubscriptionNoWrapper(topicNameOrId, subscriptionNameOrId).catch( + err => { + console.error(err.message); + process.exitCode = 1; + } + ); +} + +main(...process.argv.slice(2)); diff --git a/samples/system-test/subscriptions.test.ts b/samples/system-test/subscriptions.test.ts index 4ce7c12df..8d39405f7 100644 --- a/samples/system-test/subscriptions.test.ts +++ b/samples/system-test/subscriptions.test.ts @@ -186,6 +186,25 @@ describe('subscriptions', () => { assert(subscriptions.some(s => s.name === fullSubName(subName))); }); + it('should create a push subscription w/no wrapper', async () => { + const testId = 'push_sub_nw'; + const topic = await createTopic(testId); + const subName = reserveSub(testId); + const output = execSync( + `${commandFor('createPushSubscriptionNoWrapper')} ${ + topic.name + } ${subName}` + ); + assert.include(output, `Subscription ${subName} created.`); + const sub = await pubsub.subscription(subName); + const [subInfo] = await sub.get(); + assert(subInfo.name === fullSubName(subName)); + const [meta] = await subInfo.getMetadata(); + assert(meta.pushConfig!.noWrapper!.writeMetadata === true); + /*const [subscriptions] = await pubsub.topic(topic.name).getSubscriptions(); + assert(subscriptions.some(s => s.name === fullSubName(subName)));*/ + }); + it('should create a BigQuery subscription', async () => { const testId = 'bigquery_sub'; const topic = await createTopic(testId); diff --git a/samples/typescript/createPushSubscriptionNoWrapper.ts b/samples/typescript/createPushSubscriptionNoWrapper.ts new file mode 100644 index 000000000..3a3644003 --- /dev/null +++ b/samples/typescript/createPushSubscriptionNoWrapper.ts @@ -0,0 +1,75 @@ +// Copyright 2023 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** + * This application demonstrates how to perform basic operations on + * subscriptions with the Google Cloud Pub/Sub API. + * + * For more information, see the README.md under /pubsub and the documentation + * at https://cloud.google.com/pubsub/docs. + */ + +// sample-metadata: +// title: Create Push Subscription With No Wrapper +// description: Creates a new push subscription, but disables metadata wrapping. +// usage: node createPushSubscriptionNoWrapper.js + +// [START pubsub_create_push_no_wrapper_subscription] +/** + * TODO(developer): Uncomment these variables before running the sample. + */ +// const topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID'; +// const subscriptionNameOrId = 'YOUR_SUBSCRIPTION_NAME_OR_ID'; + +// Imports the Google Cloud client library +import {PubSub, CreateSubscriptionOptions} from '@google-cloud/pubsub'; + +// Creates a client; cache this for further use +const pubSubClient = new PubSub(); + +async function createPushSubscriptionNoWrapper( + topicNameOrId: string, + subscriptionNameOrId: string +) { + const options: CreateSubscriptionOptions = { + pushConfig: { + // Set to an HTTPS endpoint of your choice. If necessary, register + // (authorize) the domain on which the server is hosted. + pushEndpoint: `https://${pubSubClient.projectId}.appspot.com/push`, + noWrapper: { + writeMetadata: true, + }, + }, + }; + + await pubSubClient + .topic(topicNameOrId) + .createSubscription(subscriptionNameOrId, options); + console.log(`Subscription ${subscriptionNameOrId} created.`); +} +// [END pubsub_create_push_no_wrapper_subscription] + +function main( + topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID', + subscriptionNameOrId = 'YOUR_SUBSCRIPTION_NAME_OR_ID' +) { + createPushSubscriptionNoWrapper(topicNameOrId, subscriptionNameOrId).catch( + err => { + console.error(err.message); + process.exitCode = 1; + } + ); +} + +main(...process.argv.slice(2)); From 902b94977c8bf202875a1de04babafdc4dd74e1a Mon Sep 17 00:00:00 2001 From: Megan Potter <57276408+feywind@users.noreply.github.com> Date: Wed, 3 Jan 2024 12:23:40 -0500 Subject: [PATCH 02/11] samples: update samples/createPushSubscriptionNoWrapper.js Co-authored-by: Alex Hong <9397363+hongalex@users.noreply.github.com> --- samples/createPushSubscriptionNoWrapper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/createPushSubscriptionNoWrapper.js b/samples/createPushSubscriptionNoWrapper.js index 6297ff659..d5ebbd1db 100644 --- a/samples/createPushSubscriptionNoWrapper.js +++ b/samples/createPushSubscriptionNoWrapper.js @@ -29,7 +29,7 @@ // description: Creates a new push subscription, but disables metadata wrapping. // usage: node createPushSubscriptionNoWrapper.js -// [START pubsub_create_push_no_wrapper_subscription] +// [START pubsub_create_unwrapped_push_subscription] /** * TODO(developer): Uncomment these variables before running the sample. */ From 38bd2cc72de526680556c9f17d79b5e6dbafcdfc Mon Sep 17 00:00:00 2001 From: Megan Potter <57276408+feywind@users.noreply.github.com> Date: Wed, 3 Jan 2024 12:23:51 -0500 Subject: [PATCH 03/11] samples: update samples/createPushSubscriptionNoWrapper.js Co-authored-by: Alex Hong <9397363+hongalex@users.noreply.github.com> --- samples/createPushSubscriptionNoWrapper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/createPushSubscriptionNoWrapper.js b/samples/createPushSubscriptionNoWrapper.js index d5ebbd1db..1f2c26311 100644 --- a/samples/createPushSubscriptionNoWrapper.js +++ b/samples/createPushSubscriptionNoWrapper.js @@ -62,7 +62,7 @@ async function createPushSubscriptionNoWrapper( .createSubscription(subscriptionNameOrId, options); console.log(`Subscription ${subscriptionNameOrId} created.`); } -// [END pubsub_create_push_no_wrapper_subscription] +// [END pubsub_create_unwrapped_push_subscription] function main( topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID', From 2d431ce001f23e22bcf1e14b9d749e4d828c0535 Mon Sep 17 00:00:00 2001 From: Megan Potter <57276408+feywind@users.noreply.github.com> Date: Wed, 3 Jan 2024 12:25:07 -0500 Subject: [PATCH 04/11] samples: update copyright createPushSubscriptionNoWrapper.js --- samples/createPushSubscriptionNoWrapper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/createPushSubscriptionNoWrapper.js b/samples/createPushSubscriptionNoWrapper.js index 1f2c26311..b865b4657 100644 --- a/samples/createPushSubscriptionNoWrapper.js +++ b/samples/createPushSubscriptionNoWrapper.js @@ -1,4 +1,4 @@ -// Copyright 2023 Google LLC +// Copyright 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. From 148b10ab0f5b9917757c1cb647a107030d566b4a Mon Sep 17 00:00:00 2001 From: Megan Potter <57276408+feywind@users.noreply.github.com> Date: Wed, 3 Jan 2024 12:25:30 -0500 Subject: [PATCH 05/11] samples: update copyright createPushSubscriptionNoWrapper.ts --- samples/typescript/createPushSubscriptionNoWrapper.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/typescript/createPushSubscriptionNoWrapper.ts b/samples/typescript/createPushSubscriptionNoWrapper.ts index 3a3644003..b05331382 100644 --- a/samples/typescript/createPushSubscriptionNoWrapper.ts +++ b/samples/typescript/createPushSubscriptionNoWrapper.ts @@ -1,4 +1,4 @@ -// Copyright 2023 Google LLC +// Copyright 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. From 9ca775d3416f021ce0f624269b592e3874e3611f Mon Sep 17 00:00:00 2001 From: Megan Potter <57276408+feywind@users.noreply.github.com> Date: Wed, 3 Jan 2024 12:26:40 -0500 Subject: [PATCH 06/11] samples: update region tag in ts as well --- samples/typescript/createPushSubscriptionNoWrapper.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/samples/typescript/createPushSubscriptionNoWrapper.ts b/samples/typescript/createPushSubscriptionNoWrapper.ts index b05331382..f762f59ee 100644 --- a/samples/typescript/createPushSubscriptionNoWrapper.ts +++ b/samples/typescript/createPushSubscriptionNoWrapper.ts @@ -25,7 +25,7 @@ // description: Creates a new push subscription, but disables metadata wrapping. // usage: node createPushSubscriptionNoWrapper.js -// [START pubsub_create_push_no_wrapper_subscription] +// [START pubsub_create_unwrapped_push_subscription] /** * TODO(developer): Uncomment these variables before running the sample. */ @@ -58,7 +58,7 @@ async function createPushSubscriptionNoWrapper( .createSubscription(subscriptionNameOrId, options); console.log(`Subscription ${subscriptionNameOrId} created.`); } -// [END pubsub_create_push_no_wrapper_subscription] +// [END pubsub_create_unwrapped_push_subscription] function main( topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID', From 499e62377b713a5aa78ee9579e46a9212df7773b Mon Sep 17 00:00:00 2001 From: Megan Potter <57276408+feywind@users.noreply.github.com> Date: Wed, 10 Jan 2024 15:40:11 -0500 Subject: [PATCH 07/11] chore: remove commented code in subscriptions.test.ts --- samples/system-test/subscriptions.test.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/samples/system-test/subscriptions.test.ts b/samples/system-test/subscriptions.test.ts index 8d39405f7..3e17a0001 100644 --- a/samples/system-test/subscriptions.test.ts +++ b/samples/system-test/subscriptions.test.ts @@ -201,8 +201,6 @@ describe('subscriptions', () => { assert(subInfo.name === fullSubName(subName)); const [meta] = await subInfo.getMetadata(); assert(meta.pushConfig!.noWrapper!.writeMetadata === true); - /*const [subscriptions] = await pubsub.topic(topic.name).getSubscriptions(); - assert(subscriptions.some(s => s.name === fullSubName(subName)));*/ }); it('should create a BigQuery subscription', async () => { From a2a7f815ca551c7c201b538d6a7e55a00ad719f6 Mon Sep 17 00:00:00 2001 From: feywind <57276408+feywind@users.noreply.github.com> Date: Wed, 10 Jan 2024 15:56:28 -0500 Subject: [PATCH 08/11] docs: update comments to be clearer --- samples/createPushSubscriptionNoWrapper.js | 5 ++++- samples/typescript/createPushSubscriptionNoWrapper.ts | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/samples/createPushSubscriptionNoWrapper.js b/samples/createPushSubscriptionNoWrapper.js index 6297ff659..8e4b04e78 100644 --- a/samples/createPushSubscriptionNoWrapper.js +++ b/samples/createPushSubscriptionNoWrapper.js @@ -26,7 +26,7 @@ // sample-metadata: // title: Create Push Subscription With No Wrapper -// description: Creates a new push subscription, but disables metadata wrapping. +// description: Creates a new push subscription, but disables wrapping for payloads. // usage: node createPushSubscriptionNoWrapper.js // [START pubsub_create_push_no_wrapper_subscription] @@ -51,6 +51,9 @@ async function createPushSubscriptionNoWrapper( // Set to an HTTPS endpoint of your choice. If necessary, register // (authorize) the domain on which the server is hosted. pushEndpoint: `https://${pubSubClient.projectId}.appspot.com/push`, + // When true, writes the Pub/Sub message metadata to + // `x-goog-pubsub-:` headers of the HTTP request. Writes the + // Pub/Sub message attributes to `:` headers of the HTTP request. noWrapper: { writeMetadata: true, }, diff --git a/samples/typescript/createPushSubscriptionNoWrapper.ts b/samples/typescript/createPushSubscriptionNoWrapper.ts index 3a3644003..be1caf644 100644 --- a/samples/typescript/createPushSubscriptionNoWrapper.ts +++ b/samples/typescript/createPushSubscriptionNoWrapper.ts @@ -22,7 +22,7 @@ // sample-metadata: // title: Create Push Subscription With No Wrapper -// description: Creates a new push subscription, but disables metadata wrapping. +// description: Creates a new push subscription, but disables wrapping for payloads. // usage: node createPushSubscriptionNoWrapper.js // [START pubsub_create_push_no_wrapper_subscription] @@ -47,6 +47,9 @@ async function createPushSubscriptionNoWrapper( // Set to an HTTPS endpoint of your choice. If necessary, register // (authorize) the domain on which the server is hosted. pushEndpoint: `https://${pubSubClient.projectId}.appspot.com/push`, + // When true, writes the Pub/Sub message metadata to + // `x-goog-pubsub-:` headers of the HTTP request. Writes the + // Pub/Sub message attributes to `:` headers of the HTTP request. noWrapper: { writeMetadata: true, }, From 7749fd8257df4417dfcbdc550cfae5d1e3d4c33a Mon Sep 17 00:00:00 2001 From: feywind <57276408+feywind@users.noreply.github.com> Date: Wed, 10 Jan 2024 17:42:54 -0500 Subject: [PATCH 09/11] samples: update push subscription samples to take a URL parameter for extra clarity --- samples/createPushSubscription.js | 16 +++++++++++++--- samples/createPushSubscriptionNoWrapper.js | 19 ++++++++++++------- samples/system-test/subscriptions.test.ts | 6 ++++-- samples/typescript/createPushSubscription.ts | 11 +++++++++-- .../createPushSubscriptionNoWrapper.ts | 19 ++++++++++++------- 5 files changed, 50 insertions(+), 21 deletions(-) diff --git a/samples/createPushSubscription.js b/samples/createPushSubscription.js index 12afa91b5..10115b98f 100644 --- a/samples/createPushSubscription.js +++ b/samples/createPushSubscription.js @@ -33,6 +33,7 @@ /** * TODO(developer): Uncomment these variables before running the sample. */ +// const pushEndpoint = 'YOUR_ENDPOINT_URL'; // const topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID'; // const subscriptionNameOrId = 'YOUR_SUBSCRIPTION_NAME_OR_ID'; @@ -42,12 +43,16 @@ const {PubSub} = require('@google-cloud/pubsub'); // Creates a client; cache this for further use const pubSubClient = new PubSub(); -async function createPushSubscription(topicNameOrId, subscriptionNameOrId) { +async function createPushSubscription( + pushEndpoint, + topicNameOrId, + subscriptionNameOrId +) { const options = { pushConfig: { // Set to an HTTPS endpoint of your choice. If necessary, register // (authorize) the domain on which the server is hosted. - pushEndpoint: `https://${pubSubClient.projectId}.appspot.com/push`, + pushEndpoint, }, }; @@ -59,10 +64,15 @@ async function createPushSubscription(topicNameOrId, subscriptionNameOrId) { // [END pubsub_create_push_subscription] function main( + pushEndpoint = 'YOUR_ENDPOINT_URL', topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID', subscriptionNameOrId = 'YOUR_SUBSCRIPTION_NAME_OR_ID' ) { - createPushSubscription(topicNameOrId, subscriptionNameOrId).catch(err => { + createPushSubscription( + pushEndpoint, + topicNameOrId, + subscriptionNameOrId + ).catch(err => { console.error(err.message); process.exitCode = 1; }); diff --git a/samples/createPushSubscriptionNoWrapper.js b/samples/createPushSubscriptionNoWrapper.js index c8912244f..c26f1080a 100644 --- a/samples/createPushSubscriptionNoWrapper.js +++ b/samples/createPushSubscriptionNoWrapper.js @@ -33,6 +33,7 @@ /** * TODO(developer): Uncomment these variables before running the sample. */ +// const pushEndpoint = 'YOUR_ENDPOINT_URL'; // const topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID'; // const subscriptionNameOrId = 'YOUR_SUBSCRIPTION_NAME_OR_ID'; @@ -43,6 +44,7 @@ const {PubSub} = require('@google-cloud/pubsub'); const pubSubClient = new PubSub(); async function createPushSubscriptionNoWrapper( + pushEndpoint, topicNameOrId, subscriptionNameOrId ) { @@ -50,7 +52,7 @@ async function createPushSubscriptionNoWrapper( pushConfig: { // Set to an HTTPS endpoint of your choice. If necessary, register // (authorize) the domain on which the server is hosted. - pushEndpoint: `https://${pubSubClient.projectId}.appspot.com/push`, + pushEndpoint, // When true, writes the Pub/Sub message metadata to // `x-goog-pubsub-:` headers of the HTTP request. Writes the // Pub/Sub message attributes to `:` headers of the HTTP request. @@ -68,15 +70,18 @@ async function createPushSubscriptionNoWrapper( // [END pubsub_create_unwrapped_push_subscription] function main( + pushEndpoint = 'YOUR_ENDPOINT_URL', topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID', subscriptionNameOrId = 'YOUR_SUBSCRIPTION_NAME_OR_ID' ) { - createPushSubscriptionNoWrapper(topicNameOrId, subscriptionNameOrId).catch( - err => { - console.error(err.message); - process.exitCode = 1; - } - ); + createPushSubscriptionNoWrapper( + pushEndpoint, + topicNameOrId, + subscriptionNameOrId + ).catch(err => { + console.error(err.message); + process.exitCode = 1; + }); } main(...process.argv.slice(2)); diff --git a/samples/system-test/subscriptions.test.ts b/samples/system-test/subscriptions.test.ts index 3e17a0001..36582602b 100644 --- a/samples/system-test/subscriptions.test.ts +++ b/samples/system-test/subscriptions.test.ts @@ -179,7 +179,9 @@ describe('subscriptions', () => { const topic = await createTopic(testId); const subName = reserveSub(testId); const output = execSync( - `${commandFor('createPushSubscription')} ${topic.name} ${subName}` + `${commandFor('createPushSubscription')} http://url-fake./ ${ + topic.name + } ${subName}` ); assert.include(output, `Subscription ${subName} created.`); const [subscriptions] = await pubsub.topic(topic.name).getSubscriptions(); @@ -191,7 +193,7 @@ describe('subscriptions', () => { const topic = await createTopic(testId); const subName = reserveSub(testId); const output = execSync( - `${commandFor('createPushSubscriptionNoWrapper')} ${ + `${commandFor('createPushSubscriptionNoWrapper')} http://url-fake./ ${ topic.name } ${subName}` ); diff --git a/samples/typescript/createPushSubscription.ts b/samples/typescript/createPushSubscription.ts index a1a0f31e8..808f3aa8c 100644 --- a/samples/typescript/createPushSubscription.ts +++ b/samples/typescript/createPushSubscription.ts @@ -29,6 +29,7 @@ /** * TODO(developer): Uncomment these variables before running the sample. */ +// const pushEndpoint = 'YOUR_ENDPOINT_URL'; // const topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID'; // const subscriptionNameOrId = 'YOUR_SUBSCRIPTION_NAME_OR_ID'; @@ -39,6 +40,7 @@ import {PubSub, CreateSubscriptionOptions} from '@google-cloud/pubsub'; const pubSubClient = new PubSub(); async function createPushSubscription( + pushEndpoint: string, topicNameOrId: string, subscriptionNameOrId: string ) { @@ -46,7 +48,7 @@ async function createPushSubscription( pushConfig: { // Set to an HTTPS endpoint of your choice. If necessary, register // (authorize) the domain on which the server is hosted. - pushEndpoint: `https://${pubSubClient.projectId}.appspot.com/push`, + pushEndpoint, }, }; @@ -58,10 +60,15 @@ async function createPushSubscription( // [END pubsub_create_push_subscription] function main( + pushEndpoint = 'YOUR_ENDPOINT_URL', topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID', subscriptionNameOrId = 'YOUR_SUBSCRIPTION_NAME_OR_ID' ) { - createPushSubscription(topicNameOrId, subscriptionNameOrId).catch(err => { + createPushSubscription( + pushEndpoint, + topicNameOrId, + subscriptionNameOrId + ).catch(err => { console.error(err.message); process.exitCode = 1; }); diff --git a/samples/typescript/createPushSubscriptionNoWrapper.ts b/samples/typescript/createPushSubscriptionNoWrapper.ts index 5f2335400..f0d97e33c 100644 --- a/samples/typescript/createPushSubscriptionNoWrapper.ts +++ b/samples/typescript/createPushSubscriptionNoWrapper.ts @@ -29,6 +29,7 @@ /** * TODO(developer): Uncomment these variables before running the sample. */ +// const pushEndpoint = 'YOUR_ENDPOINT_URL'; // const topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID'; // const subscriptionNameOrId = 'YOUR_SUBSCRIPTION_NAME_OR_ID'; @@ -39,6 +40,7 @@ import {PubSub, CreateSubscriptionOptions} from '@google-cloud/pubsub'; const pubSubClient = new PubSub(); async function createPushSubscriptionNoWrapper( + pushEndpoint: string, topicNameOrId: string, subscriptionNameOrId: string ) { @@ -46,7 +48,7 @@ async function createPushSubscriptionNoWrapper( pushConfig: { // Set to an HTTPS endpoint of your choice. If necessary, register // (authorize) the domain on which the server is hosted. - pushEndpoint: `https://${pubSubClient.projectId}.appspot.com/push`, + pushEndpoint, // When true, writes the Pub/Sub message metadata to // `x-goog-pubsub-:` headers of the HTTP request. Writes the // Pub/Sub message attributes to `:` headers of the HTTP request. @@ -64,15 +66,18 @@ async function createPushSubscriptionNoWrapper( // [END pubsub_create_unwrapped_push_subscription] function main( + pushEndpoint = 'YOUR_ENDPOINT_URL', topicNameOrId = 'YOUR_TOPIC_NAME_OR_ID', subscriptionNameOrId = 'YOUR_SUBSCRIPTION_NAME_OR_ID' ) { - createPushSubscriptionNoWrapper(topicNameOrId, subscriptionNameOrId).catch( - err => { - console.error(err.message); - process.exitCode = 1; - } - ); + createPushSubscriptionNoWrapper( + pushEndpoint, + topicNameOrId, + subscriptionNameOrId + ).catch(err => { + console.error(err.message); + process.exitCode = 1; + }); } main(...process.argv.slice(2)); From ac7b9adc71a9f27a32a60927d5c5839b6a703759 Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Wed, 10 Jan 2024 22:47:58 +0000 Subject: [PATCH 10/11] =?UTF-8?q?=F0=9F=A6=89=20Updates=20from=20OwlBot=20?= =?UTF-8?q?post-processor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --- README.md | 1 + samples/README.md | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/README.md b/README.md index ceefb3891..6a2dfa06d 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-pubsub/tree | Create BigQuery Subscription | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/createBigQuerySubscription.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/createBigQuerySubscription.js,samples/README.md) | | Create a Proto based Schema | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/createProtoSchema.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/createProtoSchema.js,samples/README.md) | | Create Push Subscription | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/createPushSubscription.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/createPushSubscription.js,samples/README.md) | +| Create Push Subscription With No Wrapper | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/createPushSubscriptionNoWrapper.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/createPushSubscriptionNoWrapper.js,samples/README.md) | | Create Subscription | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/createSubscription.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/createSubscription.js,samples/README.md) | | Create Subscription With Dead Letter Policy | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/createSubscriptionWithDeadLetterPolicy.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/createSubscriptionWithDeadLetterPolicy.js,samples/README.md) | | Create an exactly-once delivery subscription | [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/createSubscriptionWithExactlyOnceDelivery.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/createSubscriptionWithExactlyOnceDelivery.js,samples/README.md) | diff --git a/samples/README.md b/samples/README.md index 749f4493f..6260da752 100644 --- a/samples/README.md +++ b/samples/README.md @@ -24,6 +24,7 @@ guides. * [Create BigQuery Subscription](#create-bigquery-subscription) * [Create a Proto based Schema](#create-a-proto-based-schema) * [Create Push Subscription](#create-push-subscription) + * [Create Push Subscription With No Wrapper](#create-push-subscription-with-no-wrapper) * [Create Subscription](#create-subscription) * [Create Subscription With Dead Letter Policy](#create-subscription-with-dead-letter-policy) * [Create an exactly-once delivery subscription](#create-an-exactly-once-delivery-subscription) @@ -165,6 +166,25 @@ __Usage:__ +### Create Push Subscription With No Wrapper + +Creates a new push subscription, but disables wrapping for payloads. + +View the [source code](https://github.com/googleapis/nodejs-pubsub/blob/main/samples/createPushSubscriptionNoWrapper.js). + +[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-pubsub&page=editor&open_in_editor=samples/createPushSubscriptionNoWrapper.js,samples/README.md) + +__Usage:__ + + +`node createPushSubscriptionNoWrapper.js ` + + +----- + + + + ### Create Subscription Creates a new subscription. From dff6cfda652de3c734200334051e0fcea16ef5cb Mon Sep 17 00:00:00 2001 From: feywind <57276408+feywind@users.noreply.github.com> Date: Thu, 11 Jan 2024 15:39:02 -0500 Subject: [PATCH 11/11] tests: use a real URL for the actual testing --- samples/system-test/subscriptions.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/system-test/subscriptions.test.ts b/samples/system-test/subscriptions.test.ts index 36582602b..bcd60c3fb 100644 --- a/samples/system-test/subscriptions.test.ts +++ b/samples/system-test/subscriptions.test.ts @@ -178,10 +178,9 @@ describe('subscriptions', () => { const testId = 'push_sub'; const topic = await createTopic(testId); const subName = reserveSub(testId); + const url = `https://${pubsub.projectId}.appspot.com/push`; const output = execSync( - `${commandFor('createPushSubscription')} http://url-fake./ ${ - topic.name - } ${subName}` + `${commandFor('createPushSubscription')} ${url} ${topic.name} ${subName}` ); assert.include(output, `Subscription ${subName} created.`); const [subscriptions] = await pubsub.topic(topic.name).getSubscriptions(); @@ -192,8 +191,9 @@ describe('subscriptions', () => { const testId = 'push_sub_nw'; const topic = await createTopic(testId); const subName = reserveSub(testId); + const url = `https://${pubsub.projectId}.appspot.com/push`; const output = execSync( - `${commandFor('createPushSubscriptionNoWrapper')} http://url-fake./ ${ + `${commandFor('createPushSubscriptionNoWrapper')} ${url} ${ topic.name } ${subName}` );