If there is no service "Registration Center Management Backend", just build one yourself

Party A's RPC service is developed based on Netty itself, and the registration center uses ZooKeeper, so there is no problem in using it. Unfortunately, after Party A's colleagues developed the service and released it to the SIT environment, they just released it and did not care whether the service started normally or not. The RPC service was unavailable from time to time. For this reason, Xiaohei decided to build a registration center management backend.

In Xiaohei's words, it is to release a registration center management background, so that all services registered to zk are directly listed. RPC services that are not in the registration center are not released normally. Let Party A's colleagues check whether the service status is normal, saving both parties A and B's time. At the same time, you can also see whether any colleagues' local development environments are currently registered to the registration center of the SIT environment. The following is a simplified version of Xiao Hei's code:

private static ZkClient client = null;
public static void main(String[] args) {
    
    
    client = new ZkClient("xx.xx.xxx.xxx:2181", 5000);
    client.setZkSerializer(new MySerializable());
    Scanner scan = new Scanner(System.in);
    while (true) {
    
    
        String s = scan.next();
        if ("quit".equals(s)) {
    
    
            break;
        }
        System.out.println(String.format("输入的path: %s", s));
        getList(s);
    }
    scan.close();
    client.close();
}
public static void getList(String path) {
    
    
    List<String> list = client.getChildren(path);
    if (list.size() == 0) {
    
    
        Object o = client.readData(path);
        System.out.println(o);
    }
    list.forEach((s) -> {
    
    
        String t = path.concat("/").concat(s);
        getList(t);
    });
}

Guess you like

Origin blog.csdn.net/weixin_43275277/article/details/121957958