diff --git a/README.md b/README.md index b1a1df25..e9b2c9cb 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Kafka-node is a Node.js client with Zookeeper integration for Apache Kafka 0.8.1 - [FailedToRebalanceConsumerError: Exception: NODE_EXISTS[-110]](#failedtorebalanceconsumererror-exception-node_exists-110) - [HighLevelConsumer does not consume on all partitions](#highlevelconsumer-does-not-consume-on-all-partitions) - [How to throttle messages / control the concurrency of processing messages](#how-to-throttle-messages--control-the-concurrency-of-processing-messages) - - [How do I consume binary data?](#how-do-i-consume-binary-data) + - [How do I produce and consume binary data?](#how-do-i-produce-and-consume-binary-data) - [Running Tests](#running-tests) - [LICENSE - "MIT"](#license---mit) @@ -892,11 +892,21 @@ Reference to issue [#339](https://github.com/SOHU-Co/kafka-node/issues/339) 2. Set the `queue.drain` to resume the consumer 3. The handler for consumer's `message` event pauses the consumer and pushes the message to the queue. -## How do I consume binary data? +## How do I produce and consume binary data? -In the consumer set the `encoding` option to `buffer` there not settings on producers needed for this. +### Consume +In the consumer set the `encoding` option to `buffer`. -Reference to issue [#470](https://github.com/SOHU-Co/kafka-node/issues/470) +### Produce +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`. + +```js +{ + messages: Buffer.from(data.buffer) +} +``` + +Reference to issue [#470](https://github.com/SOHU-Co/kafka-node/issues/470) [#514](https://github.com/SOHU-Co/kafka-node/issues/514) # Running Tests