Nodejs-pubsub: pubish() should be able to take a JS object as input

Created on 28 Apr 2018  Â·  7Comments  Â·  Source: googleapis/nodejs-pubsub

I wanted to publish a JSON payload to a topic:

Observed:

const data = JSON.stringify({ hello : "world" });
const dataBuffer = Buffer.from(data);
await publisher.publish(dataBuffer);

Expected:

await publisher.publish({ hello : "world" });

pubsub p2 enhancement question

Most helpful comment

I'd love for it to be another method name for such a function, like .publishJson().
Having the same method do multiple things and then sending it over the wire makes things harder to debug when someone sends in the wrong argument. And not even typescript will help in this case since any object shape will be allowed.

All 7 comments

We used to support this, but the PubSub team specifically requested we remove this feature and only accept Buffers. I'm not sure if they still have strong feelings on this subject. @kir-titievsky any thoughts here?

I don't remember why we said this. But I presume that one can have non-json Buffers.

To clarify: I am not asking for .publish() to only take JS objects, I am asking that when I pass a JS object to publish()that is not a buffer, it gets transformed into a buffer for me.

Ah. Thanks, Steren. Could you say more on how this addition would help you?
On Mon, Apr 30, 2018 at 5:34 PM Steren notifications@github.com wrote:

To clarify: I am not asking for .publish() to only take JS objects, I am
asking that when I pass a JS object to publish()that is not a buffer, it
gets transformed into a buffer for me.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/googleapis/nodejs-pubsub/issues/121#issuecomment-385535789,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ARrMFu_Vqhlv-zWBYCBjOgATnD4e3_SWks5tt4NVgaJpZM4TrLAX
.

>

Kir Titievsky | Product Manager | Google Cloud Pub/Sub

This would improve the developer experience by simplifying a very common use case. See my first message in this issue to understand the difference.

I'd love for it to be another method name for such a function, like .publishJson().
Having the same method do multiple things and then sending it over the wire makes things harder to debug when someone sends in the wrong argument. And not even typescript will help in this case since any object shape will be allowed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ThomWright picture ThomWright  Â·  6Comments

steffiisawesome picture steffiisawesome  Â·  8Comments

davidtom picture davidtom  Â·  3Comments

colmsnowplow picture colmsnowplow  Â·  8Comments

marcusradell picture marcusradell  Â·  4Comments