• dubbo异步与一致性hash负载均衡


    一致性hash

    /**
     * 指定方法设置负载均衡
     *
     * @param serviceConfig
     * @author Jamin
     * @date 2020/8/23 18:07
     */
     public static void setLoadbalance(ServiceConfig serviceConfig) {
     serviceConfig.setLoadbalance("consistenthash");
     MethodConfig methodConfig = new MethodConfig();
     methodConfig.setName("getByName");
     Map<String, String> params = new HashMap<>(10);
     params.put("hash.arguments", "0,1");
     params.put("hash.nodes", "200");
     methodConfig.setParameters(params);        serviceConfig.setMethods(Collections.singletonList(methodConfig));
     }
    

    异步

    public static void main(String[] args) throws IOException {
        ApplicationConfig applicationConfig = new ApplicationConfig("client");
        RegistryConfig registryConfig = new RegistryConfig("zookeeper://192.168.150.120:2181");
        ReferenceConfig referenceConfig = new ReferenceConfig();
        referenceConfig.setRegistry(registryConfig);
        referenceConfig.setInterface(UserService.class);
        // referenceConfig.setUrl("dubbo://192.168.21.1:20880/cn.jaminye.base.UserService");
        referenceConfig.setApplication(applicationConfig);
        // referenceConfig.setGroup("jamin");
        setLoadbalance(referenceConfig);
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            if (bufferedReader.readLine().equals("quit")) {
                break;
            }
            UserService userService = (UserService) referenceConfig.get();
    
            System.out.println(userService.getByName("测试", "12"));
            System.out.println(userService.getByName("212121212", "313dsdas"));
            System.out.println(userService.getByName("1231asdas", "casdas"));
            System.out.println(userService.getByName("12cacas3344D", "12121213122112"));
            System.out.println(userService.getByName("12312adsd", "dasdas"));
            System.out.println(userService.getByName("测试", "12"));
    
        }
    }
    
    作者: JaminYe
    版权声明:本文原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
  • 相关阅读:
    数据仓库-数据清洗
    数据仓库-维度模型(模型类型、建模过程)
    数据仓库-维度
    I am going to India on a business trip
    Android O编译前修改文件和目录权限
    apktool介绍
    Android中国官网资源网站
    android7.0后对于detected problems with app native libraries提示框显示
    android7.0后对于file://的限制
    android7.0对于SharedPreferences设置模式的限制
  • 原文地址:https://www.cnblogs.com/JaminYe/p/13584555.html
Copyright © 2020-2023  润新知