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: API refactor · Issue #98 · googleapis/google-cloud-node

pubsub: API refactor #98

New issue
Copy link
New issue
Copy link
Closed
#245
Closed
pubsub: API refactor#98
#245
Copy link
Assignees
stephenplusplus
Labels
🚨This issue needs some love.api: pubsubIssues related to the Pub/Sub API.triage meI really want to be triaged.
Milestone
Pub/Sub Alpha

Description

@stephenplusplus
stephenplusplus
opened on Aug 7, 2014
Issue body actions

9/30/14:

PR: #245

9/29/14:

http://stephenplusplus.github.io/gcloud-node/#/docs/master/pubsub

9/22/14:

Outdated:

Initializing

var gcloud = require('gcloud')({ projectId: 'test-project' });
var pubsub = gcloud.pubsub();
// to override global defaults:
// var pubsub = gcloud.pubsub({ keyFilename: '/', etc: '...' });

Topics

// Create a topic
pubsub.createTopic('a-new-topic-name', function(err, topic) {});

// Get topics
pubsub.getTopics(function(err, topics) {});
pubsub.getTopics({ maxResults: 3 }, function(err, topics) {});

// Reference a topic
var topic = pubsub.topic('an-existing-topic-name');

// Publish message
topic.publish('Hi', function(err) {});

// Publish raw message
topic.publishRaw({
  data: 'Hi',
  label: [
    { key: 'priority', numValue: 0 },
    { key: 'foo', stringValue: 'bar' }
  ]
}, function(err) {});

Subscriptions

// Create a subscription
topic.subscribe('a-new-subscription-name', {
  autoAck: true
}, function(err, subscription));

// Get subscriptions
topic.getSubscriptions(function(err, subscriptions) {});
topic.getSubscriptions({ maxResults: 5 }, function(err, subscriptions) {});

// Reference a subscription
var subscription = topic.subscription('an-existing-subscription-name');

// Handle a message event
subscription.on('message', function(message) {});

// Close a subscription
subscription.close();

Example Usage

Create a topic and publish a message
pubsub.createTopic('newTopic', function(err, topic) {
  if (err) {/*...*/}
  topic.publish('Hey!', function(err) {
    if (err) {/*...*/}
  });
});
Publish a message to a topic
pubsub.topic('myTopic')
  .publish('Hey!', function(err) {
    if (err) {/*...*/}
  });
Create a subscription on a topic to listen for messages
pubsub.topic('myTopic')
  .subscribe('newSubscription', function(err, subscription) {
    if (err) {/*...*/}
    subscription.on('message', function() {
      console.log(msg);
    });
  });
Get an existing subscription on a topic to listen for messages, and auto ack them.
pubsub.topic('myTopic')
  .subscription('mySubscription', { autoAck: true })
  .on('message', function() {
    console.log(msg);
  });

Old recommended api, for historic purposes:

// New PubSub creation
var PubSub = require('lib/pubsub');
var pubsub = new PubSub({ projectId: 'test-project' });

// Create Topic
var TOPIC_NAME = 'puppies';
var PuppiesTopic = new pubsub.Topic(TOPIC_NAME);

// Publish Message (simple)
PuppiesTopic.publish('Hi', function(err) {});

// Publish Message (specific [raw format])
PuppiesTopic.publishRaw({
  data: 'Hi',
  label: [
    { key: 'priority', numValue: 0 },
    { key: 'foo', stringValue: 'bar' }
  ]
}, function(err) {});

// Subscribe to a Topic (specific [subscription name specified])
var puppyLogger = PuppiesTopic.subscribe({
  name: 'puppyLogger',
  autoAck: true,
  ackDeadlineSeconds: 60
});

puppyLogger.on('message', function(message) {
  console.log('New message from a puppy!', message);
});

// Close subscription after 5 minutes
setTimeout(puppyLogger.close, 300000);

// Get Subscriptions for a topic (simple)
PuppiesTopic.getSubscriptions(function(err, subscriptions) {});

// Get Subscriptions for a topic (specific)
PuppiesTopic.getSubscriptions({ maxResults: 5 }, function(err, subscriptions) {});

// Get Individual Subscription
PuppiesTopic.getSubscription('puppyLogger', function(err, subscription) {});

// Get Topics (simple)
pubsub.getTopics(function(err, topics) {});

// Get Topics (specific)
pubsub.getTopics({ maxResults: 5 }, function(err, topics) {});

// Get Inidividual Topic
pubsub.getTopic(TOPIC_NAME, function(err, topic) {});

Activity

Next
  1. rakyll commented on Aug 7, 2014

    @rakyll
    rakyll
    on Aug 7, 2014
    Contributor
    More actions

    Looks generally good.

    Two issues:

    • Is there a way we provide creation of topics and subscriptions? https://developers.google.com/pubsub/v1beta1/topics/create and https://developers.google.com/pubsub/v1beta1/subscriptions/create
    • publishMessage may be misleading. Message is the raw message format's entity name. My initial propose is to provide topic.publish(<String>) and topic.publishRaw(<Message>rawMessage), but they proposed me to use publishMessage(rawMessage). What about publish and publishRaw instead. I think they are more self-explanatory.
  2. stephenplusplus commented on Aug 7, 2014

    @stephenplusplus
    stephenplusplus
    on Aug 7, 2014
    ContributorAuthor
    More actions

    Is there a way we provide creation of topics...

    I was thinking that would happen with the initial new pubsub.Topic('Topic Name') - if a topic with that name already exists, it would still return a "new Topic" object, but would refer to the already existing topic.

    ...and subscriptions?

    I forgot to annotate what I did with that. Both of these bits would create a subscription:

    // Subscribe to a Topic (simple [auto subscription name generated])
    var puppyLogger = PuppiesTopic.subscribe({
      autoAck: true,
      ackDeadlineSeconds: 60
    });
    
    // Subscribe to a Topic (specific [subscription name specified])
    var puppyLogger = PuppiesTopic.subscribe({
      name: 'puppyLogger',
      autoAck: true,
      ackDeadlineSeconds: 60
    });

    The first one would generate a subscription name for you, but if you wanted to provide one, simply provide a "name" property in the configuration object. I'm not sure if that's a great idea, definitely need more thoughts on that. My thought was, I may not care about naming it, as I never intend to refer to it again from another connection. If I do need to, I can provide a name. Is that a common enough scenario, or should we require user specification of a name?

    publishMessage may be misleading.

    publish and publishRaw sgtm. They definitely can't be mistaken for anything else that way.

  3. rakyll commented on Aug 8, 2014

    @rakyll
    rakyll
    on Aug 8, 2014
    Contributor
    More actions

    If I do need to, I can provide a name. Is that a common enough scenario, or should we require user specification of a name?

    I filed an issue against API that name should be generated if not provided, and team said my assumption about subscriptions being transient is wrong. In the typical scenario, a user will create a set of topics and subscriptions via a script before deploying their app. They will embed the topic and subscription names to their app config and will never run CRUD operations on topics and subscriptions from the application context.

  4. rakyll commented on Aug 8, 2014

    @rakyll
    rakyll
    on Aug 8, 2014
    Contributor
    More actions

    b/16462864

  5. stephenplusplus commented on Aug 8, 2014

    @stephenplusplus
    stephenplusplus
    on Aug 8, 2014
    ContributorAuthor
    More actions

    No problemo. Updated the first post with these changes.

  6. rakyll commented on Aug 8, 2014

    @rakyll
    rakyll
    on Aug 8, 2014
    Contributor
    More actions

    Looks great!

  7. rakyll
    modified the milestones: This milestone has been deleted, This milestone has been deleted on Aug 8, 2014
  8. rakyll commented on Aug 11, 2014

    @rakyll
    rakyll
    on Aug 11, 2014
    Contributor
    More actions

    @stephenplusplus, I think we can start working on this issue. Would you like to focus on it?

  9. stephenplusplus commented on Aug 11, 2014

    @stephenplusplus
    stephenplusplus
    on Aug 11, 2014
    ContributorAuthor
    More actions

    Yep! I actually have a good start, just fine tuning and writing tests
    currently.

    On Monday, August 11, 2014, Burcu Dogan [email protected] wrote:

    @stephenplusplus https://github.com/stephenplusplus, I think we can
    start working on this issue. Would you like to focus on it?

    —
    Reply to this email directly or view it on GitHub
    #98 (comment)
    .

  10. rakyll commented on Aug 11, 2014

    @rakyll
    rakyll
    on Aug 11, 2014
    Contributor
    More actions

    Great!

  11. stephenplusplus
    added 3 commits that reference this issue on Aug 12, 2014

    pubsub: refactor (fixes googleapis#98).

    This issue will close once commit 0024e15 is merged into the 'master' branch.
    0024e15

    pubsub: refactor (fixes googleapis#98).

    This issue will close once commit ee72aff is merged into the 'master' branch.
    ee72aff

    pubsub: refactor (fixes googleapis#98).

    This issue will close once commit 7c1fc2f is merged into the 'master' branch.
    7c1fc2f
  12. 141 remaining items

  13. GautamSharda
    added a commit that references this issue on Feb 26, 2026

    fix: fix the `build` dir missing from releases (#98)

    2c766f5
  14. sofisl
    added a commit that references this issue on Feb 26, 2026

    1.0.2 (#98)

    26f1744
  15. GautamSharda
    added a commit that references this issue on Mar 5, 2026

    Update google-auto-auth (#98)

    f841cb1
  16. sofisl
    added 2 commits that reference this issue on Mar 5, 2026

    chore: Retry request migration (#858)

    6dcb8a6

    fix(docs): add jsdoc-region-tag plugin (#98)

    c6361bf
  17. codyoss
    added 2 commits that reference this issue on Mar 9, 2026

    build: fix types for sinon (#98)

    86df058

    build: fix types for sinon (#98)

    11216d3
  18. GautamSharda
    added 2 commits that reference this issue on Mar 11, 2026

    Upgrade repo-tools and regenerate scaffolding. (#98)

    09293ed

    feat: convert util.ts to es6 (#98)

    fbbfb92
  19. sofisl
    added a commit that references this issue on Mar 17, 2026

    chore: [node] add auto-approve templates, and install dependencies wi…

    bcc33a2
  20. GautamSharda
    added 2 commits that reference this issue on Mar 23, 2026

    added fix for row.get bug issue #98 (#141)

    faf0402

    added fix for row.get bug issue #98 (#141)

    254a0ff
  21. feywind
    added a commit that references this issue on Mar 27, 2026

    Upgrade repo-tools and regenerate scaffolding. (#98)

    bd90b09
  22. shivanee-p
    added a commit that references this issue on Mar 27, 2026

    added fix for row.get bug issue #98 (#141)

    f9842f8
  23. thiyaguk09
    added a commit that references this issue on May 5, 2026

    added fix for row.get bug issue googleapis#98 (googleapis#141)

    551f619
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @stephenplusplus
    stephenplusplus

Labels

🚨This issue needs some love.api: pubsubIssues related to the Pub/Sub API.triage meI really want to be triaged.

Type

No type

Projects

No projects

    Milestone

    • Pub/Sub Alpha

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    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.