SOHU-Co / kafka-node

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

consumer and producer are unable to connect to broker (timeout error) #1288

Open yishain11 opened 5 years ago

yishain11 commented 5 years ago

Questions?

Bug Report

producer it giving timeout error when trying to send data, and consumer cannot connect (with the same time out error.

Environment

kafka-node env: windows 7

kafka env: centos 7

For specific cases also provide

Include Sample Code to reproduce behavior

producer:

// include code here
const kclient = new kafka.KafkaClient({kafkaHost:'ADDR'});
kclient.on('error',(err) => {
    console.log(err)
})
kprod = new producer (kclient);
kprod.on('error',(err) => {
    console.log(`error: ${err}`);
})

kprod.on('ready',() => {
    console.log(`connected to kafka`);
    let tranNumSentToKafka = 0
    for (let index = 0; index < transArray.length; index++) {
        const element = JSON.stringify(transArray[index])
        // console.log(`data before sending: ${element}`);
        console.log(`sending data to kafka`);
        kprod.send([{
            topic:'test',
            messages:element
        }],
            (err,data) => { 
            if(err){console.error(err)}
            else{
                tranNumSentToKafka += 1
                console.log(`data sent: ${JSON.stringify(data)}`);
                console.log(`sent ${tranNumSentToKafka} transactions to kafka`);
            }
        })
    }

Include output with Debug turned on

simple log error: at ontimeout (timers.js:436:11) at tryOnTimeout (timers.js:300:5) at listOnTimeout (timers.js:263:5) at Timer.processTimers (timers.js:223:10) message: 'Request timed out after 30000ms' } debug producer error: kafka-node:KafkaClient kafka-node-client reconnecting to localhost:9092 +1s kafka-node:KafkaClient kafka-node-client createBroker localhost:9092 +1ms kafka-node:KafkaClient kafka-node-client socket closed localhost:9092 (hadError: true) +1s kafka-node:KafkaClient kafka-node-client reconnecting to localhost:9092 +1s kafka-node:KafkaClient kafka-node-client createBroker localhost:9092 +0ms kafka-node:KafkaClient kafka-node-client socket closed localhost:9092 (hadError: true) +1s kafka-node:KafkaClient kafka-node-client reconnecting to localhost:9092 +1s kafka-node:KafkaClient kafka-node-client createBroker localhost:9092 +1ms kafka-node:KafkaClient kafka-node-client socket closed localhost:9092 (hadError: true) +1s ...

Include Sample Code to reproduce behavior

consumer in expressjs:

// include code here
app.listen(PORT, () => {
    console.log(`Server started on ${PORT}`);
    const kclient = new kafka.KafkaClient({kafkaHost:'ADDR'});
    kclient.on('ready',() => {
        console.log(`kclient ready`);
        kconsumer = new consumer(kclient,[{
            topic:'test'
        }]);
        kconsumer.on('error',(err) => {
            console.error(` in kconsumer: \n${err}\n`)
        })
        kconsumer.on('ready',() => {
            console.log(`kconsumer ready`);
            kconsumer.on('message',(msg) => {
                console.log(`recived kafka msg`);
            })
        })
    })
    kclient.on('error',(err) => {
        console.error(`err in kclient: \n${err}\n`)
    })

});

consumer error simple output: in kconsumer: TimeoutError: Request timed out after 30000ms

DEBUG error output: kafka-node:KafkaClient broker is now ready +6ms kafka-node:KafkaClient kafka-node-client updated internal metadata +14ms kclient ready kafka-node:KafkaClient kafka-node-client updated internal metadata +12ms kafka-node:KafkaClient kafka-node-client createBroker localhost:9092 +2ms kafka-node:KafkaClient waitUntilReady [BrokerWrapper localhost:9092 (connected: true) (ready: false) (idle: false) (needAuthentication: false) (authenticated: false)] +17ms kafka-node:Consumer connection closed +1s kafka-node:KafkaClient kafka-node-client socket closed localhost:9092 (hadError: true) +3ms kafka-node:KafkaClient kafka-node-client reconnecting to localhost:9092 +1s kafka-node:KafkaClient kafka-node-client createBroker localhost:9092 +1ms kafka-node:Consumer connection closed +1s ...

Kafka is working fine on my remote centos7 machine, using the consumer and producer consoles works ok.

Its seems that both the consumer and the producer are unable to connect to kafka broker, even if the client is able to - the consumer failes on initial connection, and the producer on sending data. I have checked issue #1275 and found no answer there.

Thanks for your contribution!

hyperlink commented 5 years ago

Your kafkaHost is the string ADDR is that correct ?

yishain11 commented 5 years ago

@hyperlink ADDR is a placeholder for the real address, and the address is correct (double checked it with http request via postman)

rhyek commented 4 years ago

@yishain11 did you ever solve this?