我有docker-compose.yml文件:

version: '3.7'
  services:
  zookeeper-1:
  image: confluentinc/cp-zookeeper:latest
  ports:
    - 22181:22181
  environment:
  ZOOKEEPER_SERVER_ID: 1
  ZOOKEEPER_CLIENT_PORT: 22181
  ZOOKEEPER_TICK_TIME: 2000
  ZOOKEEPER_INIT_LIMIT: 5
  ZOOKEEPER_SYNC_LIMIT: 2
  ZOOKEEPER_SERVERS: zookeeper-1:22888:23888;zookeeper-2:32888:33888;zookeeper-3:42888:43888
  networks:
  - zk_net


zookeeper-2:
image: confluentinc/cp-zookeeper:latest
ports:
  - 32181:32181
environment:
  ZOOKEEPER_SERVER_ID: 2
  ZOOKEEPER_CLIENT_PORT: 32181
  ZOOKEEPER_TICK_TIME: 2000
  ZOOKEEPER_INIT_LIMIT: 5
  ZOOKEEPER_SYNC_LIMIT: 2
  ZOOKEEPER_SERVERS: zookeeper-1:22888:23888;zookeeper-2:32888:33888;zookeeper-3:42888:43888
networks:
  - zk_net

zookeeper-3:
image: confluentinc/cp-zookeeper:latest
ports:
  - 42181:42181
environment:
  ZOOKEEPER_SERVER_ID: 3
  ZOOKEEPER_CLIENT_PORT: 42181
  ZOOKEEPER_TICK_TIME: 2000
  ZOOKEEPER_INIT_LIMIT: 5
  ZOOKEEPER_SYNC_LIMIT: 2
  ZOOKEEPER_SERVERS: zookeeper-1:22888:23888;zookeeper-2:32888:33888;zookeeper-3:42888:43888
networks:
  - zk_net


kafka-1:
image: confluentinc/cp-kafka:latest
ports:
  - 19092:19092
depends_on:
  - zookeeper-1
  - zookeeper-2
  - zookeeper-3
environment:
  KAFKA_BROKER_ID: 1
  KAFKA_ZOOKEEPER_CONNECT: zookeeper-1:22181,zookeeper-2:32181,zookeeper-3:42181
  KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka-1:19092
  KAFKA_SOCKET_REQUEST_MAX_BYTES: 500000000
networks:
  - zk_net

kafka-2:
image: confluentinc/cp-kafka:latest
ports:
  - 29092:29092
depends_on:
  - zookeeper-1
  - zookeeper-2
  - zookeeper-3
environment:
  KAFKA_BROKER_ID: 2
  KAFKA_ZOOKEEPER_CONNECT: zookeeper-1:22181,zookeeper-2:32181,zookeeper-3:42181
  KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka-2:29092
  KAFKA_SOCKET_REQUEST_MAX_BYTES: 500000000
networks:
  - zk_net

kafka-3:
image: confluentinc/cp-kafka:latest
ports:
  - 39092:39092
depends_on:
  - zookeeper-1
  - zookeeper-2
  - zookeeper-3
environment:
  KAFKA_BROKER_ID: 3
  KAFKA_ZOOKEEPER_CONNECT: zookeeper-1:22181,zookeeper-2:32181,zookeeper-3:42181
  KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka-3:39092
  KAFKA_SOCKET_REQUEST_MAX_BYTES: 500000000
networks:
  zk_net:
   driver: bridge


当我试图杀死docker中的node-1并从我的Java代码中获取节点数时,如下所示:

DescribeClusterResult describeClusterResult = adminClient.describeCluster(new DescribeClusterOptions());List<Node> nodeList = new ArrayList<>(describeClusterResult.nodes().get(TIME_OUT, TimeUnit.MILLISECONDS));

节点数量为空,因为节点1处于关闭状态。但我认为,如果节点1发生故障,则有节点2和节点3处于活动状态,因此它必须正常工作,并返回2个活动节点,但事实并非如此。

最佳答案

如果有助于查看您使用哪个属性创建AdminClient,以及是否要传递所有引导服务器,则将很有帮助。

10-06 15:14