OneCricketeer / apache-kafka-connect-docker

[KAFKA-9774] Un-official Docker Image for Apache Kafka Connect
https://issues.apache.org/jira/browse/KAFKA-9774
Apache License 2.0
36 stars 16 forks source link

Cannot access kafka on port 9092 #3

Closed vishnu-chalil closed 3 years ago

vishnu-chalil commented 3 years ago

Hi, I tried using this for a running kafka connect on docker. But Iam not able to acess kafka from the port 9092. below is the code.

` Properties prop = new Properties();

    prop.setProperty("bootstrap.servers", "host.docker.internal:9092");

    AdminClient admin = AdminClient.create(prop);

    boolean topicExists = admin.listTopics().names().get().stream().anyMatch(topicName -> topicName.equalsIgnoreCase(queryTopic));

    admin.close();
    `

Apart from host.docker.internal:9092 I have tried localhost:9092 and kafka-connect_kafka_1:9092(image name). But no luck. Any thoughts on how to get around this.

OneCricketeer commented 3 years ago

Where is your broker actually running? Why are you writing code to list topics inside a connector?

vishnu-chalil commented 3 years ago

Why are you writing code to list topics inside a connector?

Its for the purpose of checking weather a topic I'am trying to create exists.

Where is your broker actually running?

The broker is running on port 9092 as far as I understood, that's the port that has been exposed too in the docker compose file. The kafka connect is able to communicate with kafka though, I was able to create connectors etc. Not sure why direct access doesn't work.

OneCricketeer commented 3 years ago

Assuming you have a similar compose file as me, you need to use kafka:29092, as listed in the advertised listeners

https://github.com/OneCricketeer/apache-kafka-connect-docker/blob/master/docker-compose.yml#L32

vishnu-chalil commented 3 years ago

kafka:29092 didn't work, but localhost:29092 did work. kafka:29092 was throowing error org.apache.kafka.common.config.ConfigException: No resolvable bootstrap urls given in bootstrap.servers.

I have changed the docker-compose file and have used different versions of kafka and zookeeper. The whole docker-compose is given below.

`

version: '3'

services: zookeeper: image: bitnami/zookeeper:3.5.7-debian-10-r23 ports:

volumes: zookeeper_data: driver: local kafka_data: driver: local

`

Any thoughts on why kafka:29092 didn't work?

OneCricketeer commented 3 years ago

used different versions of kafka and zookeeper.

You're mixing up KAFKA_CFG_ADVERTISED_LISTENERS and KAFKA_ADVERTISED_LISTENERS, then

I think bitnami might have modified the names of those since I made this repo

OneCricketeer commented 3 years ago

localhost would not work, unless you're running this code outside of Docker

vishnu-chalil commented 3 years ago

Yes. Iam running the code outside the docker container.

OneCricketeer commented 3 years ago

Then that would explain why using Docker service names wouldn't work

If you'd like more details, read https://www.confluent.io/blog/kafka-listeners-explained/