dubbo的泛化调用
dubbo的泛化调用是分布式事务dubbo服务的基础,无论是对dubbo服务的补偿机制,还是二阶段的commit或者cancel都要用到它,所以自己也写了些demo。总的感觉类似Java的反射机制,官网也有详细介绍。
1.dubbo官网
2. 测试demo
ReferenceConfig<com.alibaba.dubbo.rpc.service.GenericService> reference = new ReferenceConfig<com.alibaba.dubbo.rpc.service.GenericService>(); reference.setInterface("com.xxx.haitao.account.service.AccountService"); reference.setVersion("1.0"); reference.setGroup("stable_dev"); reference.setGeneric(true); // 声明为泛化接口 RegistryConfig registry = new RegistryConfig(); registry.setAddress("zookeeper://xxx:2181?backup=xxx:2181,xxx:2181"); reference.setRegistry(registry); reference.setApplication(new ApplicationConfig("call-dubbo-demo")); // 用com.alibaba.dubbo.rpc.service.GenericService可以替代所有接口引用 com.alibaba.dubbo.rpc.service.GenericService genericService = reference.get(); // 基本类型以及Date,List,Map等不需要转换,直接调用 Object result = genericService.$invoke("getAccount", new String[] {"java.lang.String"}, new Object[] {"[email protected]"}); System.out.println(result);
相关推荐
aNian 2020-06-16
香帅 2020-05-09
ATenhong 2020-10-15
supperme 2020-09-08
doctorvian 2020-08-02
aNian 2020-08-01
kongjunlongaa 2020-06-29
Fightingxr 2020-06-26
whileinsist 2020-06-24
doctorvian 2020-06-16
XuNeely 2020-06-16
wangyangsoftware 2020-06-16
大步流星 2020-06-16
gaoyongstone 2020-06-16
MartellJenkins 2020-06-11
范群松 2020-06-11
Fightingxr 2020-06-08
XuNeely 2020-06-07