public class Application {
private static String zookeeperHost = System
.getProperty("zookeeper.address", "127.0.0.1");
private static String zookeeperPort = System.getProperty("zookeeper.port",
"2181");
public static void main(String[] args) {
//3.服务消费方(Consumer)的视角,通过调用 Dubbo 框架提供的 API 可以获得一个服务代理(stub)对象,然后就可以像使用本地服务一样对服务方法发起调用了。
ReferenceConfig<GreetingsService> reference = new ReferenceConfig<>();
reference.setApplication(new ApplicationConfig("first-dubbo-consumer"));
reference.setRegistry(new RegistryConfig(
"zookeeper://" + zookeeperHost + ":" + zookeeperPort));
reference.setInterface(GreetingsService.class);
GreetingsService service = reference.get();
String message = service.sayHi("dubbo");
System.out.println(message);
}
}