Skip to content

Commit

Permalink
docs: Add and improve ordering keys examples (#1071)
Browse files Browse the repository at this point in the history
* chore: Remove notes about ordering keys being experimental.

* feat: Add support for server-side flow control

* Revert "chore: Remove notes about ordering keys being experimental."

This reverts commit d02f328.

* docs: Add and improve ordering keys samples

* Fix test format and documentation

* Lint fixes

Co-authored-by: Megan Potter <57276408+feywind@users.noreply.github.com>
  • Loading branch information
kamalaboulhosn and feywind authored Aug 17, 2020
1 parent 78a45ff commit c693830
Show file tree
Hide file tree
Showing 7 changed files with 270 additions and 136 deletions.
144 changes: 30 additions & 114 deletions protos/protos.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 39 additions & 1 deletion samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ guides.
* [Create Push Subscription](#create-push-subscription)
* [Create Subscription](#create-subscription)
* [Create Subscription With Dead Letter Policy](#create-subscription-with-dead-letter-policy)
* [Create Subscription With Ordering Enabled](#create-subscription-with-ordering)
* [Create Topic](#create-topic)
* [Delete Subscription](#delete-subscription)
* [Delete Topic](#delete-topic)
Expand Down Expand Up @@ -126,6 +127,24 @@ __Usage:__



### Create Subscription With Ordering Enabled

Creates a new subscription With Ordering Enabled.

View the [source code](https://github.com/googleapis/nodejs-pubsub/blob/master/samples/createSubscriptionWithOrdering.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/createSubscriptionWithOrdering.js,samples/README.md)

__Usage:__


`node createSubscriptionWithOrdering.js <topic-name> <subscription-name>`


-----



### Create Topic

Creates a new topic.
Expand Down Expand Up @@ -460,7 +479,26 @@ View the [source code](https://github.com/googleapis/nodejs-pubsub/blob/master/s
__Usage:__


`node publishOrderedMessage.js <topic-name> <data>`
`node publishOrderedMessage.js <topic-name> <data> <ordering-key>`


-----




### Resume Publishing

Demonstrates how to resume publishing for an ordering key after a publish fails.

View the [source code](https://github.com/googleapis/nodejs-pubsub/blob/master/samples/resumePublish.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/resumePublish.js,samples/README.md)

__Usage:__


`node resumePublish.js <topic-name> <data> <ordering-key>`


-----
Expand Down
64 changes: 64 additions & 0 deletions samples/createSubscriptionWithOrdering.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// 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 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.
*/

'use strict';

// sample-metadata:
// title: Create Subscription with ordering enabled
// description: Creates a new subscription with ordering enabled.
// usage: node createSubscriptionWithOrdering.js <topic-name> <subscription-name>

function main(
topicName = 'YOUR_TOPIC_NAME',
subscriptionName = 'YOUR_SUBSCRIPTION_NAME'
) {
// [START pubsub_ordering_keys_create_subscription]
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const topicName = 'YOUR_TOPIC_NAME';
// const subscriptionName = 'YOUR_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 createSubscriptionWithOrdering() {
// Creates a new subscription
await pubSubClient.topic(topicName).createSubscription(subscriptionName, {
enableMessageOrdering: true,
});
console.log(
`Created subscription ${subscriptionName} with ordering enabled.`
);
console.log(
'To process messages in order, remember to add an ordering key to your messages.'
);
}

createSubscriptionWithOrdering().catch(console.error);
// [END pubsub_ordering_keys_create_subscription]
}

main(...process.argv.slice(2));
Loading

0 comments on commit c693830

Please sign in to comment.