Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

publishResult does not work - should use publisher #557

Closed
mooose opened this issue Jan 22, 2018 · 2 comments
Closed

publishResult does not work - should use publisher #557

mooose opened this issue Jan 22, 2018 · 2 comments

Comments

@mooose
Copy link

mooose commented Jan 22, 2018

Instead of

function publishResult (topicName, data) {
  return pubsub.topic(topicName).get({ autoCreate: true })
    .then(([topic]) => topic.publish(data));
}

the following function works:

function publishMessage(topicName, data) {
  const dataBuffer = Buffer.from(data);
  pubsub
    .topic(topicName)
    .publisher()
    .publish(dataBuffer)
    .then(results => {
      const messageId = results[0];
      console.log(`Message ${messageId} published.`);
    })
    .catch(err => {
      console.error('ERROR:', err);
    });
}
@sadohert
Copy link

I just bumped into this too. Following the docs here:

https://cloud.google.com/pubsub/docs/publisher#pubsub-publish-message-nodejs

I noticed the 2nd approach from @mooose was described. When I looked at the github project these docs pointed to I was taken to:

https://github.com/googleapis/nodejs-pubsub/blob/master/samples/topics.js

... which is part of the googleapis project.

So seems like there is some redundancy happening, and the "GoogleCloudPlatform" project has out of date pubsub example code.

@fhinkel
Copy link
Contributor

fhinkel commented Nov 8, 2018

Closed due to inactivity. Feel free to reopen if needed.

@fhinkel fhinkel closed this as completed Nov 8, 2018
NimJay pushed a commit that referenced this issue Nov 11, 2022
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
ace-n pushed a commit that referenced this issue Nov 11, 2022
See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants