生产者代码:
public static void main(String[] args) throws Exception{
ServiceConfig<InfoService> serviceConfig = new ServiceConfig<>();
serviceConfig.setApplication(new ApplicationConfig("hbr-dubbo-provider"));
RegistryConfig registryConfig = new RegistryConfig("zookeeper://127.0.0.1:2181");
serviceConfig.setRegistry(registryConfig);
serviceConfig.setInterface(InfoService.class);
serviceConfig.setRef(new InfoServiceAImpl());
serviceConfig.export();
System.out.println("service start!");
System.in.read();
}
消费者代码:
public static void main(String[] args) {
ReferenceConfig<InfoService> referenceConfig =new ReferenceConfig<>();
referenceConfig.setApplication(new ApplicationConfig("hbr-dubbo-customer"));
RegistryConfig registryConfig = new RegistryConfig("zookeeper://127.0.0.1:2181");
referenceConfig.setRegistry(registryConfig);
referenceConfig.setInterface(InfoService.class);
InfoService infoService = referenceConfig.get();
Object result = infoService.sayHello("what?");
System.out.println("服务端返回 "+result);
}
|