SOHU-Co/kafka-node

How do you publish binary data?

lenzenmi opened this issue · 2 comments

The documentation mentions how to consume binary data. It does not say how to produce one.

Sending a buffer or Uint8Array sends only their string representation.

It looks like the code from #29 is still in place. Try setting the messages attribute in the payload to be a Buffer. Does this not work?

Thanks for the tip. A Buffer object does work. I was trying to send a TypedArray and the associated .buffer attribute of the TypedArray with no luck.

Doing this works:
messages: Buffer.from(data.buffer)

It would be nice to have a note in the documentation like there is for consuming a binary message:

how do I publish binary data?
Set the messages attribute in the payload to a Buffer. TypedArrays such as Uint8Array are not supported and need to be converted to a Buffer.