Node-rdkafka: Piping consumer stream to Rx, handling backpressure

Created on 17 Jul 2017  路  2Comments  路  Source: Blizzard/node-rdkafka

I would like to pipe the consumer stream to Rx and to handle backpressure. My logic consists of reading from a Kafka topic (using the consumer stream), normalizing the data, and uploading to AWS's S3.
I thought of:

  1. "Pulling" messages from the consumer stream, and continuing to pull only when the service is ready to handle more messages (after uploading to S3). Is this possible with the new consumer stream?
  2. "Pipe" the stream directly to an Rx observable. However, I do not know of a way to tell the Kafka stream to "stopAndWait" in case of backpressure.
question

Most helpful comment

The Kafka Consumer stream will not read unless the node stream calls read on it. The way node streams work is that the write stream has a write callback, and it will only read as fast as it can write. The read events are "deferred" in the sense that the read callback is expected to push data eventually, and the writes will not process anything until they get the readable event, which happens when there is data to read.

Node streams should provide what you are looking for out of the box provided you do not call the write callback in your piped to write stream until you have fully uploaded the message to s3.

If you have a code sample I'd be happy to take a look.

All 2 comments

The Kafka Consumer stream will not read unless the node stream calls read on it. The way node streams work is that the write stream has a write callback, and it will only read as fast as it can write. The read events are "deferred" in the sense that the read callback is expected to push data eventually, and the writes will not process anything until they get the readable event, which happens when there is data to read.

Node streams should provide what you are looking for out of the box provided you do not call the write callback in your piped to write stream until you have fully uploaded the message to s3.

If you have a code sample I'd be happy to take a look.

Going to close this issue because of inactivity, but if you're still having difficulties feel free to comment or re-open if needed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

8lueberry picture 8lueberry  路  5Comments

idangozlan picture idangozlan  路  3Comments

jdowning picture jdowning  路  4Comments

michallevin picture michallevin  路  5Comments

Avielyo10 picture Avielyo10  路  5Comments