不使用spring配置 的 dubbo例子
生产者
public class Provider {
public static void main(String[] args) throws IOException {
ApplicationConfig app = new ApplicationConfig();
app.setName("provider");
RegistryConfig registry = new RegistryConfig("zookeeper://127.0.0.1:2181");
ProtocolConfig protocol = new ProtocolConfig("dubbo", 20880);
ServiceConfig<TService> service = new ServiceConfig<TService>();
service.setInterface(TService.class);
service.setRef(new TServiceImpl());
service.setProtocol(protocol);
service.setRegistry(registry);
service.setApplication(app);
service.export();
System.in.read(); // 按任意键退出
}
}
消费者
public class Consumer {
public static void main(String[] args) {
ApplicationConfig app = new ApplicationConfig();
app.setName("consumer");
RegistryConfig registry = new RegistryConfig("zookeeper://127.0.0.1:2181");
ReferenceConfig<TService> reference = new ReferenceConfig<TService>();
reference.setApplication(app);
reference.setRegistry(registry);
reference.setInterface(TService.class);
reference.setCheck(false);
TService t = reference.get();
System.out.println(t.say("sb"));
}
}
通过此例子 理解dubbo运行原理