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" });
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.
Here's the origin discussion for anyone that can see it: https://docs.google.com/document/d/12QHQnF7ThXcNnFTOyQgsmygAYk8QiWvPjUfoYs_kKng/edit?disco=AAAABEGnPOE
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.
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.