简体   繁体   English

从docker内部连接主机kafka包含spring boot服务

[英]Connect host kafka from inside docker contained spring boot service

I would like to connect to a kafka broker hosted on my local machine from a spring boot service inside a docker container on the same machine. 我想从同一台机器上的docker容器内的spring boot服务连接到我本地计算机上托管的kafka代理。

Kafka Listener config in spring boot. Kafka Listener配置在春季启动。 This works outside of the container on the local machine: 这适用于本地计算机上的容器外部:

config.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "127.0.0.1:9092");
        config.put(ConsumerConfig.GROUP_ID_CONFIG, "my_test_application");
        config.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
        config.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);

Kafka server properties file: Kafka服务器属性文件:

  # Hostname and port the broker will advertise to producers and consumers. 
 If not set, 
  # it uses the value for "listeners" if configured.  Otherwise, it will use 
 the value
  # returned from java.net.InetAddress.getCanonicalHostName().
 advertised.listeners=PLAINTEXT://localhost:9092

Docker file of image: Docker文件的图片:

FROM openjdk:8-slim
 FROM apacheignite/ignite:2.4.0
 COPY decoupling.jar decoupling.jar
 EXPOSE 9081 3306 9092 2181
 CMD java -jar decoupling.jar

run command: 运行命令:

docker run decoupling

在docker run命令中使用--network =“host”,然后docker容器中的127.0.0.1将指向您的docker主机。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法从 docker 容器内的 Spring Boot 连接到 Redis - Cannot connect to Redis from Spring Boot inside docker container 无法从通过 intellij 运行的 spring 引导应用程序连接到我在 docker 上运行的 kafka - Can't connect to my kafka running on docker from spring boot application running via intellij Spring 本地 docker 服务的引导 Kafka 连接问题 - Spring Boot Kafka Connection Problem for local docker service 如何从 Spring 引导 docker 容器在同一台机器上运行访问 RabbitMQ 服务(在主机上) - How to access RabbitMQ service (on host machine) from Spring boot docker container running on same machine docker 中的 truststore 与 spring boot 和 kafka 的问题路径 - problem path for truststore inside docker with spring boot and kafka 通知服务(Spring boot + Kafka) - Notification service ( Spring boot + Kafka) 在 Docker 容器内运行 Spring Boot 应用程序,无法连接 MySQL - Running Spring Boot app inside Docker container, unable to connect MySQL 如何在 Spring Boot Docker 中连接到 MongoDB Atlas? - How can I connect to MongoDB Atlas inside Spring Boot Docker? 无法从 spring 启动 Z05B6053C41A2140AFD6FC3BE6Z 容器连接 mysql docker 容器 - not able to connect mysql docker container from spring boot docker container 通过 IP 地址访问远程主机中的 Kafka 运行 Docker-Compose 和 Spring 引导 - Access Kafka in Remote Host by IP Address running with Docker-Compose and Spring Boot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM