I am new to node-red. I am using node-red to accept HTTP Post from another server. I need to respond to the with the success or failure status (200 or 400 response). If the received message is successfully stored to a kafka queue (or to database) then send http response 200, otherwise send 400.
I tried building a flow using KafkaJS node-red-contrib-kafkajs . I am able to stores the message to kafka queue successfully, but has this node has no output. So I am unable to send the response after this.
Try pointing a complete node at the node. Attach a debug to that. Does it send a message when the kafka node succeeds / fails?
Alternatively, does the node display any status underneath it after completion that signals success/failure? If so, try a status node looking at the kafka node.
Additionally (and likely the better solution), I would raise an issue on the nodes repo describing your requirement. If the dev is responsive, they might add an output to the node that indicates success or failure.
Try pointing a complete node at the node. Attach a debug to that. Does it send a message when the kafka node succeeds / fails?
I tried with "Complete". It does not send success / fail.
does the node display any status underneath it after completion that signals success/failure? If so, try a status node looking at the kafka node.
The kafka node does display the status underneath. However it is not useful. When I connect debug to the node, it keeps sending this connectivity messages every second or so.
@lu4t Probably you are right. Yes, it looks like I am trying to make Kafka client synchronous. If I was writing this code in, let's say "express", I would have handled it that way but managed it with async calls.
This begs a different question. (forgive me if I am going back to basics). In my given scenario should I just return the response (http 200) even though I am not sure if the client successfully stored the message in kafka? Otherwise, client just keeps waiting for node-red to respond, it will either timeout eventually and if it makes thousands of requests each of those requests will have to timeout.
@bakman2 No. You cannot. Because you have to respond to http request with the http response in the same branch of the flow where "Http in" node is. Otherwise you don't get the "response" object.
I have tried this with "Complete" as well as "Status" nodes. They don't work because you do not have http response object when responding. It has to be in the same path where "Http In" is. This is FYI for @Steve-Mcl response to earlier discussion.
Got it. You could store the output of the kafka client in a context variable and show that as output to the http response node. Probably wise to keep the context for this only in memory (not write to disk).