I have set up a Kafka cluster with docker-compose file where i specify the brokers like this:
kafka1:
image: confluentinc/cp-kafka:latest
hostname: kafka1
ports:
- "19092:19092"
depends_on:
- zookeeper-1
- zookeeper-2
- zookeeper-3
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper-1:12181,zookeeper-2:12181,zookeeper-3:12181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka1:19092
Now when i try to create topic with js script and i refer to the brokers like follows(for the sake of this post i only attach code about 1 broker):
try
{
const kafka = new Kafka({
clientId: 'myapp',
brokers: ['kafka1:19092','kafka2:29092','kafka3:39092']
})
I get this error:
{"level":"ERROR","timestamp":"2020-03-21T19:06:13.653Z","logger":"kafkajs","message":"[Connection] Connection error: getaddrinfo ENOTFOUND kafka1","broker":"kafka1:19092","clientId":"myapp","stack":"Error: getaddrinfo ENOTFOUND kafka1\n at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:66:26)"}
I feel like i have exhausted internet trying to troubleshoot this. Anyone have any suggestions how to connect to the broker in the docker?