gpt4 book ai didi

docker - 从 Spring Boot 应用程序连接到本地 Bitnami Docker Kafka 时出错

转载 作者:行者123 更新时间:2023-12-02 20:43:17 24 4
gpt4 key购买 nike

带有 Spring Kafka(2.4 版)的 Spring Boot(2.2 版)应用程序无法与 Bitnami Docker Kafka 建立连接(版本 2)从官方执行docker-compose.yml

version: '2'

services:
zookeeper:
image: 'bitnami/zookeeper:3'
ports:
- '2181:2181'
volumes:
- 'zookeeper_data:/bitnami'
environment:
- ALLOW_ANONYMOUS_LOGIN=yes
kafka:
image: 'bitnami/kafka:2'
ports:
- '9092:9092'
volumes:
- 'kafka_data:/bitnami'
environment:
- KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
- ALLOW_PLAINTEXT_LISTENER=yes
depends_on:
- zookeeper

volumes:
zookeeper_data:
driver: local
kafka_data:
driver: local

Spring 应用程序不断产生以下警告:

[kafka-admin-client-thread | adminclient-1] WARN  o.apache.kafka.clients.NetworkClient.initiateConnect - [AdminClient clientId=adminclient-1] Error connecting to node 2228a9a3b8c5:9092 (id: 1001 rack: null) java.net.UnknownHostException: 2228a9a3b8c5

[kafka-admin-client-thread | adminclient-1] WARN  o.apache.kafka.clients.NetworkClient.processDisconnection - [AdminClient clientId=adminclient-1] Connection to node -1 (localhost/127.0.0.1:9092) could not be established. Broker may not be available.

最佳答案

要与在 `localhost 上运行的 Bitnami Docker Kafka 建立连接,请添加以下环境变量:

  • KAFKA_CFG_LISTENERS=PLAINTEXT://:9092
  • KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://localhost:9092

docker-compose.yml kafka服务:

kafka:
image: 'bitnami/kafka:2'
ports:
- '9092:9092'
volumes:
- 'kafka_data:/bitnami'
environment:
- KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
- ALLOW_PLAINTEXT_LISTENER=yes
- KAFKA_CFG_LISTENERS=PLAINTEXT://:9092
- KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://localhost:9092

关于docker - 从 Spring Boot 应用程序连接到本地 Bitnami Docker Kafka 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59899283/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com