低级错误 先给自己两个大嘴巴子(好疼!!!)

 

按照官网配置好以后 一定 一定 一定要加配置

dubbo.config-center.timeout  这个参数值 可以写大一点 没关系

 

如果你的报错和我一样 并且出错位置如下 那就可以解决这个问题 

    public CuratorZookeeperClient(URL url) {
        super(url);
        try {
            int timeout = url.getParameter(TIMEOUT_KEY, DEFAULT_CONNECTION_TIMEOUT_MS);
            int sessionExpireMs = url.getParameter(ZK_SESSION_EXPIRE_KEY, DEFAULT_SESSION_TIMEOUT_MS);
            CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder()
                    .connectString(url.getBackupAddress())
                    .retryPolicy(new RetryNTimes(1, 1000))
                    .connectionTimeoutMs(timeout)
                    .sessionTimeoutMs(sessionExpireMs);
            String authority = url.getAuthority();
            if (authority != null && authority.length() > 0) {
                builder = builder.authorization("digest", authority.getBytes());
            }
            client = builder.build();
            client.getConnectionStateListenable().addListener(new CuratorConnectionStateListener(url));
            client.start();
            boolean connected = client.blockUntilConnected(timeout, TimeUnit.MILLISECONDS);// 就是这里报错 timeout太小在默认3000之内没有链接上
            if (!connected) {
                throw new IllegalStateException("zookeeper not connected");
            }
        } catch (Exception e) {
            throw new IllegalStateException(e.getMessage(), e);
        }
    }

 

# Spring boot application
spring:
  application:
    name: consumer
  # Base packages to scan Dubbo Component: @org.apache.dubbo.config.annotation.Service
dubbo:
  registry:
    address: zookeeper://192.168.1.146:${embedded.zookeeper.port}
    file: ${user.home}/dubbo-cache/${spring.application.name}/dubbo.cache
    parameters:
      max-wait: -1
      max.idle: 8
      max-active: 8
      max-idle: 8
      min-idle: 0
  config-center:
    timeout: 6000
embedded:
  zookeeper:
    port: 2181
demo:
  service:
    version: 1.0.0

留作警示 没事 多琢磨一些 看看源码 这个问题浪费了大半天的时间 一直以为是服务器配置搓搓

version: '3.1'

services:
  zoo1:
    image: zookeeper:3.4.13
    restart: always
    hostname: zoo1
    container_name: zoo1
    networks:
     - zookeeper-network
    volumes:
     - /etc/localtime:/etc/localtime:ro
     - /usr/local/docker_app/zookeeper/zoo1/data:/data
     - /usr/local/docker_app/zookeeper/zoo1/datalog:/datalog
    ports:
      - 2181:2181
    environment:
      ZOO_MY_ID: 1
      ZOO_SERVERS: server.1=0.0.0.0:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
      ZOO_TICK_TIME: 6000

  zoo2:
    image: zookeeper:3.4.13
    restart: always
    hostname: zoo2
    container_name: zoo2
    networks:
     - zookeeper-network
    volumes: 
     - /etc/localtime:/etc/localtime:ro
     - /usr/local/docker_app/zookeeper/zoo2/data:/data
     - /usr/local/docker_app/zookeeper/zoo2/datalog:/datalog
    ports:
      - 2182:2181
    environment:
      ZOO_MY_ID: 2
      ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=0.0.0.0:2888:3888 server.3=zoo3:2888:3888
      ZOO_TICK_TIME: 6000

  zoo3:
    image: zookeeper:3.4.13
    restart: always
    hostname: zoo3
    container_name: zoo3
    networks:
     - zookeeper-network
    volumes: 
     - /etc/localtime:/etc/localtime:ro
     - /usr/local/docker_app/zookeeper/zoo3/data:/data
     - /usr/local/docker_app/zookeeper/zoo3/datalog:/datalog
    ports:
      - 2183:2181
    environment:
      ZOO_MY_ID: 3
      ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=0.0.0.0:2888:3888
      ZOO_TICK_TIME: 6000
networks:
  zookeeper-network:

 

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐