我想在容器b中生成从容器a到Kafka主题的消息,但是我在这些容器的网络中遇到了一些奇怪的问题。你知道我怎样才能把这些容器连接起来吗?问题是收集器服务无法从另一个容器中看到kafka,也无法向其中添加消息。更具体地说,我有以下服务:
docker-compose.yml公司
version: '3.5'
services:
zookeeper:
image: confluentinc/cp-zookeeper:latest
ports:
- "2181:2181"
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
ADVERTISED_HOST: zookeeper
ADVERTISED_PORT: 2181
extra_hosts:
- "moby:127.0.0.1"
networks:
- meetup-net
kafka:
image: confluentinc/cp-kafka:latest
depends_on:
- zookeeper
ports:
- "9092:9092"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
extra_hosts:
- "moby:127.0.0.1"
networks:
- meetup-net
collector:
image: collector:v1
environment:
- kafka-bootstrap-servers=docker_kafka_1.docker_meetup-net
restart: always
depends_on:
- kafka
networks:
- meetup-net
networks:
meetup-net:
driver: bridge
另一边是application.conf文件
streaming {
window-size = 50
window-interval = 5
kafka-bootstrap-servers = ${?kafka-bootstrap-servers}
kafka-bootstrap-servers = "localhost:9092"
sink-topic = ${?source-topic}
sink-topic = "meetup"
key-value-json-path = ${key-value-json-path}
key-value-json-path = "./data/keyvalue"
source-topic-checkpoint-location = ${source-topic-checkpoint-location}
source-topic-checkpoint-location = "./target/source-topic"
sink-topic-checkpoint-location = ${sink-topic-checkpoint-location}
sink-topic-checkpoint-location = "./target/sink-topic"
}
zookeeper.server = ${?zookeeper-server}
zookeeper.server = "localhost:2181"
1条答案
按热度按时间f2uvfpb91#
你需要设置
KAFKA_ADVERTISED_LISTENERS
正确地。目前
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
意味着任何连接到代理的客户端都将获得localhost
作为用于连接后续请求的代理地址。除非客户机正在代理上运行(这里没有),否则您需要更改此配置。对于在一个独立的docker环境中运行,这非常简单:现在任何客户端连接都应该
kafka:29092
. 这也意味着您可以将在docker主机上运行的客户机连接到kafka代理,例如在笔记本电脑上运行并在本地运行客户机时,kafka代理非常有用。下面是一个docker compose示例,展示了它的实际应用。
有关详细信息和背景,请参阅https://rmoff.net/2018/08/02/kafka-listeners-explained/