Skip to content

Publishing a string in to PubSub topic introduces quotes to the message #2204

Description

@JanPretzel

Environment details

  • OS: OS X 10.12.3
  • Node.js version: v6.10.0
  • npm version: 3.10.10
  • @google-cloud/pubsub version: 0.9.0

Steps to reproduce

  1. require @google-cloud/pubsub
  2. publish a message topic.publish('someMessage') (as described in the documentation)
  3. pull the message and it will have "someMessage" as data

I think this is caused because the message data is being stringified if it is not a Buffer here but I do not think it is the intended behaviour? At least the documentation does not make it clear.

Activity

  1. stephenplusplus commented on Apr 11, 2017

    @stephenplusplus
    Contributor

    This is intended. We consistently publish messages in JSON format so that a JSON parser on the receiving end has a predictable way to handle the messages it receives. When our library returns the messages, we do a JSON.parse to decode it back to its native JS form:

    topic.publish('test')
    
    subscription.on('message', function(message) {
      message.data === 'test'
    })
  2. JanPretzel commented on Apr 11, 2017

    @JanPretzel
    ContributorAuthor

    Thanks for the explanation @stephenplusplus, that explains a lot. The receiving end in my example was written in Ruby. It seems the Ruby API does not expect this behaviour. An alternate service publishing messages to the same queue was written in Python, no problems here. Shouldn't this inconsistency between the different APIs be documented?

  3. stephenplusplus commented on Apr 11, 2017

    @stephenplusplus
    Contributor

    I'm glad that cleared it up, and thank you for bringing it up. I don't know of a precedent or requirement that the client libraries are expected to behave the same way, but the fact that you experienced an annoying delay while you tried to figure it out and move on with your app is a good enough reason to me that we should add this in the docs somewhere. I'll keep the issue open and mark with a help wanted label-- feel free to send us a PR if you're up for it!

  4. stephenplusplus commented on Apr 11, 2017

    @stephenplusplus
    Contributor

    Fixed in #2212-- thanks again!

  5. JanPretzel commented on Apr 11, 2017

    @JanPretzel
    ContributorAuthor

    Cool! Thank you too!

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

Metadata

Metadata

Labels

api: pubsubIssues related to the Pub/Sub API.type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions