简体   繁体   English

无法从通过 intellij 运行的 spring 引导应用程序连接到我在 docker 上运行的 kafka

[英]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.

相关问题 通过IntelliJ运行Spring Boot Application.main()找不到我的本地配置文件 - Running Spring Boot Application.main() via IntelliJ doesn't find my local profile 无法连接到 Spring 本地启动在 Docker 上运行的应用程序 - Can't connect to Spring Boot app running on Docker locally 通过 Spring Boot Run 但不通过 IntelliJ Idea 运行的应用程序 - Application Running via Spring Boot Run but not via IntelliJ Idea Spring Boot 应用程序无法连接到在 Docker 容器中运行的 MySQL 数据库 - Spring Boot application not able to connect to MySQL database running in Docker container 无法连接到在本地 Spring Boot 中运行在 docker 上的 redis sentinel - Unable to connect to redis sentinel running on docker in my local Spring boot 通过IntelliJ运行配置运行Spring引导 - Running Spring boot via IntelliJ run configuration 我的 Spring-Boot 应用程序不会停止在 IntelliJ 中运行 - My Spring-Boot app won't stop running in IntelliJ 在docker上运行的mysql容器无法与spring boot java api服务连接 - mysql container which is running on docker can't able to connect with spring boot java api service 无法将在 google 应用程序引擎中的 docker 容器中运行的 Spring Boot 应用程序连接到 google cloud sql? - Can't connect spring boot app running in docker container in google app engine to google cloud sql? 即使 MySQL 服务器正在运行,也无法通过 Spring Boot 应用程序连接到 MySQL 服务器 - can't connect to MySQL server via Spring Boot app even though MySQL server is running
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM