Skip to main content
Post Closed as "Duplicate" by OneCricketeer apache-kafka
edited tags
Link
OneCricketeer
  • 193k
  • 20
  • 146
  • 276
added 509 characters in body
Source Link
Don Rhummy
  • 26.1k
  • 53
  • 197
  • 364

EDIT: Tried these changes:

kafka: image: 'bitnami/kafka:latest' ports: - 9092:9092 environment: - KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 - ALLOW_PLAINTEXT_LISTENER=yes - KAFKA_ADVERTISED_PORT=9092 - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092 

and:

spring: application: name: testkafka kafka: bootstrap-servers: kafka:9092 server: port: 8080 

This still times out

EDIT: Tried these changes:

kafka: image: 'bitnami/kafka:latest' ports: - 9092:9092 environment: - KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 - ALLOW_PLAINTEXT_LISTENER=yes - KAFKA_ADVERTISED_PORT=9092 - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092 

and:

spring: application: name: testkafka kafka: bootstrap-servers: kafka:9092 server: port: 8080 

This still times out

Source Link
Don Rhummy
  • 26.1k
  • 53
  • 197
  • 364

Unable to connect to Kafka run in container from Spring Boot app run outside container

I'm running kafka locally via:

docker-compose.yml

 zookeeper: image: 'bitnami/zookeeper:latest' ports: - 2181:2181 environment: - ALLOW_ANONYMOUS_LOGIN=yes kafka: image: 'bitnami/kafka:latest' ports: - 9092:9092 environment: - KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 - ALLOW_PLAINTEXT_LISTENER=yes - KAFKA_ADVERTISED_PORT=9092 - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://localhost:9092 

My Spring Boot application is run with:

application.yml:

spring: application: name: testkafka kafka: bootstrap-servers: localhost:9092 server: port: 8080 

When I run it and it tries to send to a topic on kafka, I get:

org.springframework.kafka.KafkaException: Reply timed out at org.springframework.kafka.requestreply.ReplyingKafkaTemplate.lambda$sendAndReceive$0(ReplyingKafkaTemplate.java:196) ~[spring-kafka-2.1.10.RELEASE.jar:2.1.10.RELEASE] at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-5.0.10.RELEASE.jar:5.0.10.RELEASE] at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) ~[na:na] at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264) ~[na:na] at java.base/java.util.concurrent.FutureTask.run(FutureTask.java) ~[na:na] at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) ~[na:na] at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na] at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na] at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na] 

If I run the spring boot from inside a docker container (using one docker compose file), then it does work:

Running Both in the Same Compose:

version: "3.0" services: service1: build: ./Service ports: - 8080:8080 - 5005:5005 links: - zookeeper - kafka zookeeper: image: 'bitnami/zookeeper:latest' ports: - 2181:2181 environment: - ALLOW_ANONYMOUS_LOGIN=yes kafka: image: 'bitnami/kafka:latest' ports: - 9092:9092 environment: - KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 - ALLOW_PLAINTEXT_LISTENER=yes - KAFKA_ADVERTISED_PORT=9092 - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://localhost:9092 

How can I get the kafka container to allow connections from outside itself/docker?