can't connect to broker
See original GitHub issuei just copied the code from readme.md
and change the broker address to localhost:9092
but why the server address like this ?
broker":“f43be2dafb3b:9092”,
btw i use this one to start kafka https://hub.docker.com/r/bitnami/kafka
{"level":"ERROR","timestamp":"2019-08-23T07:15:04.982Z","logger":"kafkajs","message":"[Connection] Connection error: getaddrinfo ENOTFOUND f43be2dafb3b f43be2dafb3b:9092","broker":"f43be2dafb3b:9092","clientId":"my-app","stack":"Error: getaddrinfo ENOTFOUND f43be2dafb3b f43be2dafb3b:9092\n at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:57:26)"}
{"level":"ERROR","timestamp":"2019-08-23T07:15:04.984Z","logger":"kafkajs","message":"[BrokerPool] Failed to connect to broker, reconnecting","retryCount":0,"retryTime":314}
{"level":"ERROR","timestamp":"2019-08-23T07:15:05.304Z","logger":"kafkajs","message":"[Connection] Connection error: getaddrinfo ENOTFOUND f43be2dafb3b f43be2dafb3b:9092","broker":"f43be2dafb3b:9092","clientId":"my-app","stack":"Error: getaddrinfo ENOTFOUND f43be2dafb3b f43be2dafb3b:9092\n at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:57:26)"}
{"level":"ERROR","timestamp":"2019-08-23T07:15:05.304Z","logger":"kafkajs","message":"[BrokerPool] Failed to connect to broker, reconnecting","retryCount":1,"retryTime":604}
{"level":"ERROR","timestamp":"2019-08-23T07:15:05.911Z","logger":"kafkajs","message":"[Connection] Connection error: getaddrinfo ENOTFOUND f43be2dafb3b f43be2dafb3b:9092","broker":"f43be2dafb3b:9092","clientId":"my-app","stack":"Error: getaddrinfo ENOTFOUND f43be2dafb3b f43be2dafb3b:9092\n at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:57:26)"}
{"level":"ERROR","timestamp":"2019-08-23T07:15:05.911Z","logger":"kafkajs","message":"[BrokerPool] Failed to connect to broker, reconnecting","retryCount":2,"retryTime":1138}
{"level":"ERROR","timestamp":"2019-08-23T07:15:07.055Z","logger":"kafkajs","message":"[Connection] Connection error: getaddrinfo ENOTFOUND f43be2dafb3b f43be2dafb3b:9092","broker":"f43be2dafb3b:9092","clientId":"my-app","stack":"Error: getaddrinfo ENOTFOUND f43be2dafb3b f43be2dafb3b:9092\n at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:57:26)"}
{"level":"ERROR","timestamp":"2019-08-23T07:15:07.055Z","logger":"kafkajs","message":"[BrokerPool] Failed to connect to broker, reconnecting","retryCount":3,"retryTime":2218}
{"level":"ERROR","timestamp":"2019-08-23T07:15:09.278Z","logger":"kafkajs","message":"[Connection] Connection error: getaddrinfo ENOTFOUND f43be2dafb3b f43be2dafb3b:9092","broker":"f43be2dafb3b:9092","clientId":"my-app","stack":"Error: getaddrinfo ENOTFOUND f43be2dafb3b f43be2dafb3b:9092\n at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:57:26)"}
{"level":"ERROR","timestamp":"2019-08-23T07:15:09.278Z","logger":"kafkajs","message":"[BrokerPool] Failed to connect to broker, reconnecting","retryCount":4,"retryTime":4694}
{"level":"ERROR","timestamp":"2019-08-23T07:15:13.975Z","logger":"kafkajs","message":"[Connection] Connection error: getaddrinfo ENOTFOUND f43be2dafb3b f43be2dafb3b:9092","broker":"f43be2dafb3b:9092","clientId":"my-app","stack":"Error: getaddrinfo ENOTFOUND f43be2dafb3b f43be2dafb3b:9092\n at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:57:26)"}
{"level":"ERROR","timestamp":"2019-08-23T07:15:13.975Z","logger":"kafkajs","message":"[BrokerPool] Failed to connect to broker, reconnecting","retryCount":5,"retryTime":10562}
{"level":"ERROR","timestamp":"2019-08-23T07:15:13.977Z","logger":"kafkajs","message":"[Producer] Connection error: getaddrinfo ENOTFOUND f43be2dafb3b f43be2dafb3b:9092","retryCount":0,"retryTime":340}
version: '2'
services:
zookeeper:
image: 'bitnami/zookeeper:3'
ports:
- '2181:2181'
volumes:
- 'zookeeper_data:/bitnami'
environment:
- ALLOW_ANONYMOUS_LOGIN=yes
kafka:
image: 'bitnami/kafka:2'
ports:
- '9092:9092'
volumes:
- 'kafka_data:/bitnami'
environment:
- KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
- ALLOW_PLAINTEXT_LISTENER=yes
depends_on:
- zookeeper
volumes:
zookeeper_data:
driver: local
kafka_data:
driver: local
const { Kafka } = require('kafkajs')
const kafka = new Kafka({
clientId: 'my-app',
brokers: 'localhost:9092',
})
const producer = kafka.producer()
const consumer = kafka.consumer({ groupId: 'test-group' })
const run = async () => {
// Producing
await producer.connect()
await producer.send({
topic: 'test-topic',
messages: [
{ value: 'Hello KafkaJS user!' },
],
})
// Consuming
await consumer.connect()
await consumer.subscribe({ topic: 'test-topic', fromBeginning: true })
await consumer.run({
eachMessage: async ({ topic, partition, message }) => {
console.log({
partition,
offset: message.offset,
value: message.value.toString(),
})
},
})
}
run().catch(console.error)
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Why Can't I Connect to Kafka? | Troubleshoot Connectivity
When a client wants to send or receive a message from Apache Kafka ®, there are two types of connection that must succeed:...
Read more >How to handle "Could not connect to broker"? #298 - GitHub
I have a somewhat related issue. I need to connect to brokers dynamically, not statically. Having the broker defined in config is a...
Read more >Can't connect to Mosquitto broker with local IP address
I have a Mosquitto broker running on my Windows machine. I can connect to this on the same machine using an MQTT client...
Read more >Can't connect to mqtt broker - Stack Overflow
First you have to make sure that you can connect to the Raspberry Pi. You can try using libraries other than Paho or...
Read more >[MQTT Web Client] Can't connect to broker | OutSystems
The most common reason for a connection refused with and MQTT client is that it cannot reach the server itself. Where is the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If it helps anyone, I received the same error and I managed to solve it by providing the hostname to kafka service in
docker-compose.yml
:Hi @crapthings, your setup is advertising the docker hostnames. Kafka has a configuration for that, so it can correctly pick up the host IP. Try setting the
KAFKA_ADVERTISED_HOST_NAME
to the host IP.