GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — pubsub: support generated subscription names by stephenplusplus · Pull Request #1799 · googleapis/google-cloud-node

Conversation

@stephenplusplus

@stephenplusplus stephenplusplus commented Nov 16, 2016 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Fixes #1257

  • removes opts.reuseExisting from topic.subscribe('name', opts)
  • automatically generates a subscription name for the user if they don't provide one

@jgeewax explained the worker vs broadcast model:

A worker takes an item from the message queue, works, acks. The name of the subscription is important to the worker, so the same work isn't performed on the same message multiple times.

The broadcast model is for a listener who just wants to tap into the incoming messages. The name of the subscription doesn't matter in this case.

Before

topic.subscribe('my-subscription', { reuseExisting: true }, function(err, subscription) {
  // subscription was either created or re-used
})

After

topic.subscribe('my-subscription', function(err, subscription) {
  // subscription was either created or re-used
})

To differentiate between the worker and broadcast models, this PR uses the presence of a subscription name in place of opts.reuseExisting. So, if I just want to receive all of the messages:

topic.subscribe(function(err, subscription) {
  // subscription with a random name was created
})

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@stephenplusplus stephenplusplus added enhancement api: pubsub Issues related to the Pub/Sub API. labels Nov 16, 2016
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Nov 16, 2016
stephenplusplus
stephenplusplus commented Nov 16, 2016
View reviewed changes
Comment thread packages/pubsub/src/subscription.js
*
* @private
*/
Subscription.generateName_ = function() {

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stephenplusplus
stephenplusplus force-pushed the spp--1257 branch from ff6e4f7 to c5a497e Compare November 16, 2016 19:16
@stephenplusplus stephenplusplus mentioned this pull request Nov 16, 2016
pubsub.subscribe fails if called twice with the same subscription name #1257
Closed
@stephenplusplus

stephenplusplus commented Nov 16, 2016

Copy link
Copy Markdown
Contributor Author

cc: @jgeewax @tmatsuo

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

stephenplusplus added 2 commits November 17, 2016 10:13
@stephenplusplus
pubsub: support generated subscription names
ff779ab
@stephenplusplus
test coverage
7e2b679
@stephenplusplus
stephenplusplus force-pushed the spp--1257 branch from c5a497e to 7e2b679 Compare November 17, 2016 15:28
@coveralls

coveralls commented Nov 17, 2016

Copy link
Copy Markdown

Coverage Status

Changes Unknown when pulling 7e2b679 on stephenplusplus:spp--1257 into * on GoogleCloudPlatform:master*.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stephenplusplus stephenplusplus assigned callmehiphop Nov 22, 2016
@callmehiphop

callmehiphop commented Nov 28, 2016

Copy link
Copy Markdown
Contributor

@stephenplusplus this LGTM, do we want a review from a googler before going with it?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stephenplusplus

stephenplusplus commented Nov 28, 2016

Copy link
Copy Markdown
Contributor Author

Let's just go with it.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stephenplusplus
stephenplusplus merged commit 2a67398 into googleapis:master Nov 28, 2016
@stephenplusplus stephenplusplus mentioned this pull request Feb 9, 2017
Update README.md #1258
Closed
@c0b

c0b commented Feb 14, 2017 •
edited by stephenplusplus
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

question here: after I changed code from

topic.subscribe('my-subscription', { ackDeadlineSeconds: 90, autoAck: true, interval: 30, reuseExisting: true }).then(...).catch(err => ...)

to just remove the reuseExisting

topic.subscribe('my-subscription', { ackDeadlineSeconds: 90, autoAck: true, interval: 30, }).then(...).catch(err => { console.error(err); })

why it ran into catch error clause?

fail to subscribe:
{ Error: Resource already exists in the project (resource=subscriber-name).
    at /node_modules/grpc/src/node/src/client.js:434:17
  code: 409,
  metadata: 
   Metadata {
     _internal_repr: 
      { 'google.rpc.debuginfo-bin': 
         [ Buffer [
             67,
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@stephenplusplus

stephenplusplus commented Feb 16, 2017

Copy link
Copy Markdown
Contributor Author

I tried with the following code and couldn't reproduce using the latest @google-cloud/pubsub:

'use strict'

var pubsub = require('@google-cloud/pubsub')()
var topic = pubsub.topic('stephen-topic')

topic.get({ autoCreate: true })
  .then(() => {
    return topic.subscribe('my-new-subscription', {
      ackDeadlineSeconds: 90,
      autoAck: true,
      interval: 30
    })
  })
  .then(console.log) // fires
  .catch(console.log) // does not

Can you try this code, modifying only the topic name?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rhagigi

rhagigi commented Feb 21, 2017

Copy link
Copy Markdown

Question -- if you use an auto-generated subscription name, won't it create a bunch of these every time you start up a new listener? And if the listeners don't cleanly delete the subscription on shutdown, won't those "randomly named" subscriptions still exist but not be drained, queueing up any and all messages on the topic for whatever the max is (7 days I think?) until they're eventually shut down in 30 days? And if it does that, would that affect my GCP quota?

Or is the idea here that you must gracefully shut down and delete the unnamed subscription?

I'm in a situation where I need my node process to just be one of many listeners to a topic and notify any users connected over a websocket if a message comes across that interests them. What's my best way to ephemerally subscribe to a topic without creating a long-lasting subscription?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@fab-1

fab-1 commented Apr 25, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Indeed, it does generate new subs for the topic (there is a cap of 10,000 subs per topics I believe)
I would have liked a specific 'broadcast' function at the topic level (instead of publish), but this pull request at least solve the problem - thanks @stephenplusplus

In my case, I just automatically clean up previously generated subscription before subscribing to the topic :

topicObj.getSubscriptions().then(function(subscriptionInstances) {
   if (subscriptionInstances.length) {
      subscriptionInstances[0].forEach((subInstance)=>{
           logging.info('cleaning up subscription ' + subInstance.name);
           subInstance.delete()
      })
   }
});

Not very pretty, but it does the job :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rhagigi

rhagigi commented Apr 25, 2017

Copy link
Copy Markdown

Be careful doing this. At least for me the point of the broadcast model is that you can have multiple listeners at the same time... Be careful that you don't delete another instance's' subscription that is still running.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@fab-1

fab-1 commented Apr 25, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Yes, good point @rhagigi . In my case, I run this before deploying, so the new subs get re-created once the instances start. There might be a small risk but I don't know any other options.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rhagigi

rhagigi commented Apr 25, 2017 via email

Copy link
Copy Markdown
What I ended up doing was at least attempting to clean up the subscription and delete it during shut down, assuming a proper clean application shut down. If some slip through the cracks, no big deal, they'll get autodeleted after inactivity for an amount of time, but at least under ideal circumstances it should prevent the subscriptions for ballooning on every single deploy to every machine.
…
On Tue, Apr 25, 2017, 6:09 PM fab-1 ***@***.***> wrote: Yes, good point @rhagigi <https://github.com/rhagigi> . In my case, I run this before deploying, so the new instances get re-created once the instances start. There might be a small risk but I don't know any other options. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#1799 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ABmFIkLhZ3Uop1kYEtgY3eRUMo7HhvO3ks5rzm77gaJpZM4K0Ub8> .
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jeremy-albuixech jeremy-albuixech mentioned this pull request Feb 8, 2018
Documentation is misleading - Topic.createSubscription Subscription name is not optional googleapis/nodejs-pubsub#59
Closed
sofisl pushed a commit that referenced this pull request Feb 25, 2026
@ddelgrosso1
chore: fix npm link url (provided by github user galkin) (#1799)
dc84c30
GautamSharda pushed a commit that referenced this pull request Mar 11, 2026
@stephenplusplus
pubsub: support generated subscription names (#1799)
4b46f4a
GautamSharda pushed a commit that referenced this pull request Mar 11, 2026
@renovate-bot
fix(deps): update dependency @google-cloud/paginator to v5 (#1799)
2d9c1ff
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [@google-cloud/paginator](https://togithub.com/googleapis/nodejs-paginator) | [`^4.0.1` -> `^5.0.0`](https://renovatebot.com/diffs/npm/@google-cloud%2fpaginator/4.0.1/5.0.0) | [![age](https://developer.mend.io/api/mc/badges/age/npm/@google-cloud%2fpaginator/5.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/@google-cloud%2fpaginator/5.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/@google-cloud%2fpaginator/4.0.1/5.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/@google-cloud%2fpaginator/4.0.1/5.0.0?slim=true)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>googleapis/nodejs-paginator (@&#8203;google-cloud/paginator)</summary>

### [`v5.0.0`](https://togithub.com/googleapis/nodejs-paginator/blob/HEAD/CHANGELOG.md#500-2023-08-09)

[Compare Source](https://togithub.com/googleapis/nodejs-paginator/compare/v4.0.1...v5.0.0)

##### ⚠ BREAKING CHANGES

-   update to Node 14 ([#&#8203;346](https://togithub.com/googleapis/nodejs-paginator/issues/346))

##### Miscellaneous Chores

-   Update to Node 14 ([#&#8203;346](https://togithub.com/googleapis/nodejs-paginator/issues/346)) ([262ad70](https://togithub.com/googleapis/nodejs-paginator/commit/262ad70d3cc5e1aa8a67ece54c04920b24ceea09))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 9am and before 3pm" (UTC), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/googleapis/nodejs-pubsub).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi40MC4zIiwidXBkYXRlZEluVmVyIjoiMzYuNDAuMyIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->
GautamSharda pushed a commit that referenced this pull request Mar 11, 2026
@release-please
chore(main): release 4.0.1 (#1804)
925a20b
🤖 I have created a release *beep* *boop*
---


## [4.0.1](https://togithub.com/googleapis/nodejs-pubsub/compare/v4.0.0...v4.0.1) (2023-08-11)


### Bug Fixes

* **deps:** Update dependency @google-cloud/paginator to v5 ([#1799](https://togithub.com/googleapis/nodejs-pubsub/issues/1799)) ([3195d21](https://togithub.com/googleapis/nodejs-pubsub/commit/3195d21bf817cf10daa86b019532c9405dc42405))
* **deps:** Update dependency @google-cloud/precise-date to v4 ([#1803](https://togithub.com/googleapis/nodejs-pubsub/issues/1803)) ([2c22d67](https://togithub.com/googleapis/nodejs-pubsub/commit/2c22d67b0fbaf3409101a830ee0c5be002ed6c7b))
* **deps:** Update dependency @google-cloud/projectify to v4 ([#1800](https://togithub.com/googleapis/nodejs-pubsub/issues/1800)) ([5787d56](https://togithub.com/googleapis/nodejs-pubsub/commit/5787d56b95d46544bf8c59fe4bc4cb374bc53d0a))
* **deps:** Update dependency @google-cloud/promisify to v4 ([#1798](https://togithub.com/googleapis/nodejs-pubsub/issues/1798)) ([093c46b](https://togithub.com/googleapis/nodejs-pubsub/commit/093c46bd0a4713ad9702bde03eaa5e8b0acedb28))

---
This PR was generated with [Release Please](https://togithub.com/googleapis/release-please). See [documentation](https://togithub.com/googleapis/release-please#release-please).
@GautamSharda GautamSharda mentioned this pull request Mar 11, 2026
migrate code from googleapis/nodejs-pubsub #7592
Merged
4 tasks
sofisl pushed a commit that referenced this pull request Mar 17, 2026
@renovate-bot
chore(deps): update dependency @types/node to ^22.17.1 (#1799)
45f108e
thiyaguk09 pushed a commit to thiyaguk09/google-cloud-node-fork that referenced this pull request Mar 18, 2026
@ddelgrosso1
chore: fix npm link url (provided by github user galkin) (googleapis#…
5f81c5a
…1799)
feywind pushed a commit that referenced this pull request Mar 27, 2026
@release-please
chore(main): release 4.0.1 (#1804)
a221baa
🤖 I have created a release *beep* *boop*
---


## [4.0.1](https://togithub.com/googleapis/nodejs-pubsub/compare/v4.0.0...v4.0.1) (2023-08-11)


### Bug Fixes

* **deps:** Update dependency @google-cloud/paginator to v5 ([#1799](https://togithub.com/googleapis/nodejs-pubsub/issues/1799)) ([3195d21](https://togithub.com/googleapis/nodejs-pubsub/commit/3195d21bf817cf10daa86b019532c9405dc42405))
* **deps:** Update dependency @google-cloud/precise-date to v4 ([#1803](https://togithub.com/googleapis/nodejs-pubsub/issues/1803)) ([2c22d67](https://togithub.com/googleapis/nodejs-pubsub/commit/2c22d67b0fbaf3409101a830ee0c5be002ed6c7b))
* **deps:** Update dependency @google-cloud/projectify to v4 ([#1800](https://togithub.com/googleapis/nodejs-pubsub/issues/1800)) ([5787d56](https://togithub.com/googleapis/nodejs-pubsub/commit/5787d56b95d46544bf8c59fe4bc4cb374bc53d0a))
* **deps:** Update dependency @google-cloud/promisify to v4 ([#1798](https://togithub.com/googleapis/nodejs-pubsub/issues/1798)) ([093c46b](https://togithub.com/googleapis/nodejs-pubsub/commit/093c46bd0a4713ad9702bde03eaa5e8b0acedb28))

---
This PR was generated with [Release Please](https://togithub.com/googleapis/release-please). See [documentation](https://togithub.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@callmehiphop callmehiphop

Labels

api: pubsub Issues related to the Pub/Sub API. cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@stephenplusplus @coveralls @callmehiphop @c0b @rhagigi @fab-1 @googlebot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.