SOHU-Co / kafka-node

Node.js client for Apache Kafka 0.8 and later.
MIT License
2.66k stars 628 forks source link

Kafka consumer receives nothing when there is data in the topic from kafka producer #1443

Open Neo0165CA opened 3 years ago

Neo0165CA commented 3 years ago

Hi there, I am facing issue with kafka-node, Kafka consumer can not receive nothing when there is data in the topic from kafka producer but when we change the topic name then it can access the data, please check the below sample code and let me know where i am getting wrong

For specific cases also provide

var kafka = require("kafka-node");
var Consumer = kafka.Consumer,
client = new kafka.KafkaClient({kafkaHost: hostClient});
consumer = new Consumer(
client, [ {
   topic: 'stock_prices12',

}],
{
   autoCommit: true,
   fetchMaxWaitMs: 100,
   fetchMaxBytes: 1024 * 1024,
   encoding: 'utf8',
   fromOffset: false,
   fromBeginning: false

 },
  options =
        {
            fromOffset: 'latest'
        },
);

consumer.on('message', function (message) {
   wss.broadcast(JSON.parse(message.value));
});

const wss = new SocketServer({ server });
wss.broadcast = function broadcast(data) {
  wss.clients.forEach(function each(client) {
    client.send(JSON.stringify(data));
  });
};

Include output with Debug turned on

Thanks for your contribution!

traoremp commented 3 years ago

Have you been able to fix this ? I am having the same exact issue. @Neo0165CA

bailakahn commented 3 years ago

Same problem here. It was working fine few days ago

bayuardiantoid commented 3 years ago

Same issue, but only on AWS EKS. While on local (kubernetes docker for windows), it works

Neo0165CA commented 3 years ago

Try groupId in options={}, I have set groupId on basis of environments (like Development, Production, QA)

deepal commented 2 years ago

If your consumer is connecting to the topic for the first time (if your consumer's groupId is not yet registered), you will need to set fromOffset: 'earliest' if you want to consume existing messages in the topic.