[英]Can't connect to my kafka running on docker from spring boot application running via intellij
I have a docker-compose file with Kafka, zookeeper, and spring boot application.我有一个带有 Kafka、zookeeper 和 spring 引导应用程序的 docker-compose 文件。 while I run the entire file everything works fine.当我运行整个文件时,一切正常。 when I run it without my spring boot application in order to debug it via intellij It cannot connect to Kafka and doesn't work properly.当我在没有 spring 启动应用程序的情况下运行它以通过 intellij 对其进行调试时,它无法连接到 Kafka 并且无法正常工作。
my docker-compose file:我的 docker-compose 文件:
version: "3.5" services: # Install Zookeeper. zookeeper:
container_name: zookeeper
image: debezium/zookeeper:1.2
networks:
- mynetwork
ports:
- 2181:2181
- 2888:2888
- 3888:3888 # Install Kafka. kafka:
container_name: kafka
image: debezium/kafka:1.2
depends_on:
- zookeeper
ports:
- 9092:9092
- 29092:29092
networks:
- mynetwork
extra_hosts:
- "host.docker.internal:host-gateway"
environment:
- ZOOKEEPER_CONNECT=zookeeper:2181
- KAFKA_LISTENER_SECURITY_PROTOCOL_MAP= INTERNAL:PLAINTEXT,PLAINTEXT:PLAINTEXT,EXTERNAL_SAME_HOST:PLAINTEXT
- KAFKA_ADVERTISED_LISTENERS= INTERNAL://kafka:9092,EXTERNAL_SAME_HOST://localhost:29092
- KAFKA_LISTENERS= EXTERNAL_SAME_HOST://:29092,INTERNAL://:9092
- KAFKA_INTER_BROKER_LISTENER_NAME= PLAINTEXT # Install Postgres. postgres:
container_name: postgres
image: debezium/postgres:12
volumes:
- ./sql/init.sql:/docker-entrypoint-initdb.d/init.sql
ports:
- 5432:5432
networks:
- mynetwork
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=postgres kafka-ui:
container_name: kafka-ui
image: provectuslabs/kafka-ui:0.2.1
ports:
- 8080:8080
networks:
- mynetwork
environment:
- KAFKA_CLUSTERS_0_NAME=local
- KAFKA_CLUSTERS_0_BOOTSTRAPSERVERS=kafka:9092 #Deploy a Consumer. consumer:
build:
context: .
container_name: pledge-consumer
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://postgres:5432/postgres
ports:
- 8101:8080
networks:
- mynetwork
image: isber/ssm-pledgeservice:v1
depends_on:
- zookeeper
- kafka
- postgres
networks: mynetwork:
external: true
In the application I tried:在我尝试的应用程序中:
spring.kafka.bootstrap-servers=kafka:9092
which works when I run it via docker but not from intellij当我通过 docker 但不是从 intellij 运行它时,它可以工作
I also tried when running with intellij:使用intellij运行时我也尝试过:
spring.kafka.bootstrap-servers=localhost:9092
spring.kafka.bootstrap-servers=localhost:29092
I found the problem, the image I used:我发现了问题,我使用的图像:
image: debezium/kafka:1.2
had a problem and it didn't read any of the parameters of the environment I added.有问题,它没有读取我添加的环境的任何参数。 I upgraded to:我升级到:
image: debezium/kafka:1.4
everything works.一切正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.