Skip to content

pubsub: topic.publish string payloads sent wrapped with quotation marks #2403

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

Closed
fixermark opened this issue Jun 21, 2017 · 2 comments
Closed
Assignees
Labels
api: pubsub Issues related to the Pub/Sub API. type: question Request for information or clarification. Not an issue.

Comments

@fixermark
Copy link

fixermark commented Jun 21, 2017

Environment details

  • OS: (Google Cloud Function)
  • Node.js version: (Google Cloud Function default)
  • npm version: (Google Cloud Function)
  • google-cloud-node version: ~0.10.0

Steps to reproduce

  1. const pubsub = require("@google-cloud/pubsub")();
  2. const topic = pubsub.topic('my-topic');
  3. topic..publish('hello!', (err) => console.log(err));

Expected result:
topic subscriber receives
hello!

Observed result
topic subscriber receives
"hello!"

(... i.e. it appears the data payload is escaped into a string before being sent instead of the string content itself being sent)

@fixermark fixermark changed the title topic.publish string payloads sent wrapped with quotation marks pubsub: topic.publish string payloads sent wrapped with quotation marks Jun 21, 2017
@fixermark
Copy link
Author

fixermark commented Jun 21, 2017

Might be working as intended. As per the documentation,

All messages not provided as Buffer will be published in JSON format.
If your receiving end uses another library, make sure it parses the
message properly.

... however, this is surprising in the raw string case, that the output is a JSON-ified string.

@stephenplusplus stephenplusplus added the api: pubsub Issues related to the Pub/Sub API. label Jun 21, 2017
@stephenplusplus
Copy link
Contributor

Yes, this was done so that the user would have a consistent way of handling the data. JSON.parse() (or its equivalent on the receiving end) should always work off the assumption google-cloud-node published something it can handle:

$ node -p "JSON.stringify('hi')"
"hi"
$ node -p "JSON.parse(JSON.stringify('hi'))"
hi

The Pub/Sub API is under a big re-factor that will force the users of google-cloud-node to only publish Buffer objects. This means you will be in charge of precisely what is sent to the Pub/Sub API. The next release of @­google-cloud/pubsub will likely have this behavior. Stay tuned to the PR here: #2380.

Sorry for the confusion.

@stephenplusplus stephenplusplus added the type: question Request for information or clarification. Not an issue. label Jun 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the Pub/Sub API. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

2 participants