gpt4 book ai didi

java - 如何使用 jhipster 在 Kafka 集群上设置多个代理

转载 作者:行者123 更新时间:2023-12-02 09:40:14 24 4
gpt4 key购买 nike

我使用 jhipster 创建了一个基本应用程序并添加了 Apache Kafka。即使使用其他解决方案(从我的应用程序到 kafka 的 php 客户端),我的生产和消费也没有问题。现在,我想在集群上创建多个代理,但从 java 而不是 .sh 文件。

我知道集群是使用 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 应用程序,在集群中创建多个代理,而不是一个。因此我会有多个主题。我没有任何结果

最佳答案

通过这个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'

关于java - 如何使用 jhipster 在 Kafka 集群上设置多个代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57141825/

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