Hello,

I am trying to use kafka-node to produce and send messages. The message is 
produced via a POST api call.

I am following the document https://www.npmjs.com/package/kafka-node

I am trying to avoid calling this code each time I get a post call as this 
will reinitiate the connection to Kafka multiple times. As you can see in 
the code, there is a payloads section which I get from the API call each 
time I this endpoint gets called.
I dont want to put the complete code here as it may take up a lot more 
space. If I am not clear enough, please let me know. I will try to refactor 
the code and paste it here.

var kafka = require('kafka-node'),
          HighLevelProducer = kafka.HighLevelProducer,
          KeyedMessage = kafka.KeyedMessage,
          client = new kafka.Client("localhost:2181"),
          producer = new HighLevelProducer(client),
          km = new KeyedMessage('key', 'message'),
*          payloads = [ {topic: topic,messages: bodyfd} ];*

If I *declare it at the beginning of the code*, *my api call hangs *but if 
I declare it *in the event loop*, the *message gets written to kafka topic 
and API returns a good response.*


-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/00f42a1d-9a0a-4254-889f-8129503b3b65%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to