Node server hangs. Not sure if it is due to scope of the variable

18 views
Skip to first unread message

Tippur

unread,
Mar 23, 2016, 12:12:32 AM3/23/16
to nodejs
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.


Reply all
Reply to author
Forward
0 new messages