我用jhipster创建了一个基本应用程序,并添加了Apache Kafka。即使使用其他解决方案(从我的应用程序到kafka的php客户端),我也可以毫无问题地生产和使用。 现在,我想在群集上创建多个代理,但是不是从.sh文件而是从Java创建。
我知道集群是使用server.properties文件设置的,其中包含代理的ID,日志目录和其他内容。但是在我的jhipster应用程序中,经纪人ID是在kafka.yml中声明的,所以我想我必须编辑.yml文件来声明另一个经纪人。
version: '2'
services:
zookeeper:
image: confluentinc/cp-zookeeper:5.2.1
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
ZOOKEEPER_SYNC_LIMIT: 2
ports:
- 2181:2181
kafka:
image: confluentinc/cp-kafka:5.2.1
environment:
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_BROKER_ID: 2
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
ports:
- 9092:9092
目标是使用kafka创建一个jhipster应用程序,从而在集群中创建多个代理,而不是一个。因此,我将有多个主题。 我没有任何结果
答案 0 :(得分:2)
有了这个docker-compose.yml
,您将获得一个包含三个代理的集群。可以从docker内部以kafka1:9092, kafka2:9092, kafka3:9092
和docker主机以localhost:19092,localhost:29092,localhost:39092
的身份访问代理:
version: "3.7"
services:
zookeeper:
image: confluentinc/cp-zookeeper:5.4.0
hostname: zookeeper
container_name: zookeeper
ports:
- "2181:2181"
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
kafka1:
image: confluentinc/cp-server:5.4.0
hostname: kafka1
container_name: kafka1
depends_on:
- zookeeper
ports:
- "19092:19092"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP:PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka1:9092,PLAINTEXT_HOST://localhost:19092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 2
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
KAFKA_CONFLUENT_LICENSE_TOPIC_REPLICATION_FACTOR: 1
KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'false'
kafka2:
image: confluentinc/cp-server:5.4.0
hostname: kafka2
container_name: kafka2
depends_on:
- zookeeper
ports:
- "29092:29092"
environment:
KAFKA_BROKER_ID: 102
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka2:9092,PLAINTEXT_HOST://localhost:29092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 2
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
KAFKA_CONFLUENT_LICENSE_TOPIC_REPLICATION_FACTOR: 1
KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'false'
kafka3:
image: confluentinc/cp-server:5.4.0
hostname: kafka3
container_name: kafka3
depends_on:
- zookeeper
ports:
- "39092:39092"
environment:
KAFKA_BROKER_ID: 3
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka3:9092,PLAINTEXT_HOST://localhost:39092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 2
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
KAFKA_CONFLUENT_LICENSE_TOPIC_REPLICATION_FACTOR: 1
KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'false'
答案 1 :(得分:1)
您可以通过在docker-compose.yml文件中添加更多代理来使用confluentince/cp-kafka
创建多个代理。
version: '2'
services:
zookeeper:
image: confluentinc/cp-zookeeper:5.2.1
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
ZOOKEEPER_SYNC_LIMIT: 2
ports:
- 2181:2181
kafka-1:
image: confluentinc/cp-kafka:latest
hostname: kafka-1
ports:
- "19092:19092"
depends_on:
- zookeeper
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka-1:19092
kafka-2:
image: confluentinc/cp-kafka:latest
hostname: kafka-2
ports:
- "29092:29092"
depends_on:
- zookeeper
environment:
KAFKA_BROKER_ID: 2
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka-2:29092
kafka-3:
image: confluentinc/cp-kafka:latest
hostname: kafka-3
ports:
- "39092:39092"
depends_on:
- zookeeper
environment:
KAFKA_BROKER_ID: 3
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka-3:39092
参考:https://better-coding.com/building-apache-kafka-cluster-using-docker-compose-and-virtualbox/
答案 2 :(得分:0)
“因此,我将有多个主题” ==>不确定要理解,但是您不需要多个经纪人来拥有多个主题,您可以让一个经纪人来处理多个主题。
我不太了解jhipster,但是您的yml文件就像docker compose文件一样,所以我给您2美分,好像它们都是由docker compose启动的。
您首先需要您的代理连接到相同的Zookeeper集群,从我的观察中可以看出来(如果您在同一docker compose yml文件中声明所有代理)
您需要使用客户端将访问的IP地址设置播发的侦听器,如果您使用localhost,则它们将无法连接到您的代理:
KAFKA_ADVERTISED_LISTENERS:PLAINTEXT:// localhost:9092
应该是这样的:
KAFKA_ADVERTISED_LISTENERS:PLAINTEXT:// EXPOSEDIPADDRESS:9092
您还可以添加LISTENERS,例如: KAFKA_LISTENERS:PLAINTEXT://0.0.0.0:9092
请确保为每个代理使用不同的代理ID,并为每个代理使用不同的端口(如果它们在docker后面的同一框中运行)
Yannick