dubbo泛化调用(参数为bean)


public static Object dubbogeneric (String applicationName, String interfaceName, String dubboGroup, String dubboVersion, String method, String className, String param) {

    // 普通编码配置方式
    ApplicationConfig application = new ApplicationConfig();
    application.setName(applicationName);

    // 连接注册中心配置
    RegistryConfig registry = new RegistryConfig();
    registry.setAddress("zookeeper://x.x.x.x:2181");

    ReferenceConfig<GenericService> reference = new ReferenceConfig<GenericService>();

    reference.setApplication(application);
    reference.setRegistry(registry);
    reference.setInterface(interfaceName);
    reference.setGroup(dubboGroup);
    reference.setVersion(dubboVersion);
    // 声明为泛化接口
    reference.setGeneric(true);

    ReferenceConfigCache cache = ReferenceConfigCache.getCache();
    GenericService genericService = cache.get(reference);

    //基本类型以及Date,List,Map等不需要转换,直接调用
    String[] parameterTypes = new String[]{className};

    Map params = JSON.parseObject(param);
    params.put("class", className);

    Object result = genericService.$invoke(method, parameterTypes,new Object[]{params});

    return result;
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM