dubbo泛化调用和泛化引用

import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ReferenceConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.utils.ReferenceConfigCache;
import com.alibaba.dubbo.rpc.service.GenericService;  
  
  
public class DubboClientTest {  
      
          
    public static void main(String[] args) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, ClassNotFoundException {  
          
        ApplicationConfig application=new ApplicationConfig();  
        application.setName("hello-world-app");  
        RegistryConfig registryConfig =new RegistryConfig ();
        registryConfig.setAddress("zookeeper://localhost:2181");
        ReferenceConfig rc = new ReferenceConfig();  
        rc.setApplication(application);  
        rc.setGeneric(true);  
        rc.setInterface("com.znn.provider.DemoService");  
        rc.setRegistry(registryConfig);  
        
        System.out.println(rc);  
        
        ReferenceConfigCache cache = ReferenceConfigCache.getCache();
        GenericService genericService = cache.get(rc); 
       // GenericService genericService = rc.get();  
          
        Map user = new HashMap();  
        user.put("name", "chenjihong");
        Object result = genericService.$invoke("sayHello",  
                new String[] { "com.znn.provider.User" },  
                new Object[] { user });  
  
        System.out.println(result);  
       
    }  
          
  
}  


你可能感兴趣的:(前端开发)