What is causing this intermittent issue with Node Kafka Streams?

42 views Asked by At

I have a Kafka producer and consumer.

The producer does this:

    const returnMessage = {
        prop1: 'some string',
        prop2: 'another string',
        prop3: nestedObject
    };
    console.log(JSON.stringify(returnMessage))
    await stream.writeToStream(JSON.stringify(returnMessage));

The consumer does this:

incomingStream.forEach(
                message => {
                        console.log(message.value)
                        let messageObject = message.value;
                        ...other stuff...
                }
            );

Now, on the producer side, the return message is always logged as a proper string, everything is good. But on the consumer side, at first, the message.value is a proper string from which it's possible to parse a JSON, but on subsequent requests, it comes across as '[object Object]'. If

I feel like I'm missing something crucial here...please help if you have any insights.

1

There are 1 answers

0
Boris K On BEST ANSWER

OK, I've got it. The incomingStream.forEach was happening inside a route, while the stream was being instantiated at the controller level. I fixed it by moving the forEach to the controller level, and having it emit a parsed message on every message, then subscribing to the events inside the route.