-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support for detaching subscriptions (#1032)
* feat: add porcelain support for detaching subscriptions * docs: update comment for createSubscription test * samples: add detach subscription sample * docs: update doc links for subscription detach * feat: add detached() method as an easy shortcut for grabbing the 'detached' metadata from a subscription * docs: update the new detach subscription sample to use the better detached() call (and a few CR comments) * tests: add a sample system-test for testing the detach subscriptions sample * fix: properly handle alternate API endpoints (not all of which are emulators) * feat: move detach methods into the main PubSub object * tests: don't try to system-test the detach sample yet * feat: remove the detach call from Topic since it doesn't need any topic-related info * fix: allow multiple trailing slashes in API endpoint again * fix: revert alterate API endpoint changes, to put into another PR * docs: use arrow functions for examples * tests: re-enable the detach subscription test * tests: add missing unit tests for the newly added library bits * tests: add a system-test for the subscription detach methods
- Loading branch information
Showing
7 changed files
with
309 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2020 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 sample demonstrates how to detach 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. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// sample-metadata: | ||
// title: Detach Subscription | ||
// description: Detaches a subscription from a topic. | ||
// usage: node detachSubscription.js <existing-subscription-name> | ||
|
||
function main(subscriptionName = 'YOUR_EXISTING_SUBSCRIPTION_NAME') { | ||
// [START pubsub_detach_subscription] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// const subscriptionName = 'YOUR_EXISTING_SUBSCRIPTION_NAME'; | ||
|
||
// 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 detachSubscription() { | ||
// Gets the status of the existing subscription | ||
const sub = pubSubClient.subscription(subscriptionName); | ||
const [detached] = await sub.detached(); | ||
console.log( | ||
`Subscription ${subscriptionName} 'before' detached status: ${detached}` | ||
); | ||
|
||
await pubSubClient.detachSubscription(subscriptionName); | ||
console.log(`Subscription ${subscriptionName} detach request was sent.`); | ||
|
||
const [updatedDetached] = await sub.detached(); | ||
console.log( | ||
`Subscription ${subscriptionName} 'after' detached status: ${updatedDetached}` | ||
); | ||
} | ||
|
||
detachSubscription(); | ||
// [END pubsub_detach_subscription] | ||
} | ||
|
||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
main(...process.argv.slice(2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.