无法从通过 Intellij 运行的 Spring 启动应用程序连接到在 docker 上运行的 kafka



我有一个docker compose文件,其中包含Kafka、zookeeper和spring-boot应用程序。当我运行整个文件时,一切都很好。当我在没有spring启动应用程序的情况下运行它以便通过intellij进行调试时,它无法连接到Kafka,也无法正常工作。

我的docker撰写文件:

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

在我尝试的应用程序中:

spring.kafka.bootstrap-servers=kafka:9092

当我通过docker运行它时,它是有效的,但不是从intellij 运行的

我在使用intellij:运行时也尝试过

spring.kafka.bootstrap-servers=localhost:9092
spring.kafka.bootstrap-servers=localhost:29092

我发现了问题,我使用的图像:

image: debezium/kafka:1.2

出现问题,它没有读取我添加的环境的任何参数。我升级到:

image: debezium/kafka:1.4

一切正常。

相关内容

  • 没有找到相关文章