2. 运行Dubbo admin
(1) 下载Dubbo-admin 的 develop分支
git clone https://github.com/apache/dubbo-admin.git
cd dubbo-admin
(2) 修改配置
`dubbo-admin-server/src/main/resources/application.properties
(3) 编译
maven clean package -Dmaven.test.skip=true
(4) 运行
cd dubbo-admin-distribution/target; java -jar dubbo-admin-0.1.jar
3. 配置dubbo-admin,防止出现无元数据信息,请升级的情况
(1) 访问并登陆dubbo-admin http://localhost:8080 用户名和密码都为root
(2) 进入配置管理,新建Dubbo配置,应用名为global,内容为
dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.metadata-report.address=zookeeper://127.0.0.1:2181
新建后可以用zookeeper的zkcli命令行或zkui工具查看到zookeeper新建了一个/dubbo/config/dubbo/dubbo.properties的节点。参考官方说明
4. 运行AP配置方式的Demo
(1) 下载Dubbo2.7.7的源码,并修改demo代码
(2) 修改dubbo-demo-api的代码
## 修改dubbo-demo/dubbo-demo-api/pom.xml增加
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-metadata-report-zookeeper</artifactId>
</dependency>
## 修改dubbo-demo/dubbo-demo-api/dubbo-demo-api-provider/src/main/java/org/apache/dubbo/demo/provider/Application.java代码增加config-center和metadata-report的设置
private static void startWithBootstrap() {
ConfigCenterConfig configCenter = new ConfigCenterConifg();
configCenter.setAddress("zookeeper://127.0.0.1:2181");
MetadataReportConfig metadataReport = new MetadataReportConfig();
metadataReport.setAddress("zookeeper://127.0.0.1:2181");
ServiceConfig<DemoServiceImpl> service = new ServiceConfig<>();
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
DubboBootstrap bootstrap = DubboBootstrap.getInstance();
bootstrap.application(new ApplicationConfig("dubbo-demo-api-provider"))
.registry(new RegistryConfig("zookeeper://127.0.0.1:2181"))
.configCenter(configCenter)
.metadataReport(metadataReport )
.service(service)
.start()
.await();
}
private static void startWithExport() throws InterruptedException {
ConfigCenterConfig configCenter = new ConfigCenterConifg();
configCenter.setAddress("zookeeper://127.0.0.1:2181");
MetadataReportConfig metadataReport = new MetadataReportConfig();
metadataReport.setAddress("zookeeper://127.0.0.1:2181");
ServiceConfig<DemoServiceImpl> service = new ServiceConfig<>();
service.setInterface(DemoService.class);
service.setRef(new DemoServiceImpl());
service.setApplication(new ApplicationConfig("dubbo-demo-api-provider"));
service.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181"));
service.setConfigCenter(configCenter);
service.setMetadataReportConfig(metadataReport);
service.export();
System.out.println("dubbo service started");
new CountDownLatch(1).await();
}
4. 运行注解annotation方式的Demo
(1) 修改配置,增加config-center,metadata-report的设置
## dubbo-demo/dubbo-demo-annotation/dubbo-demo-annotation-provider/src/main/resources/spring/dubbo-provider.properties
## 增加如下配置
dubbo.registry.address=zookeeper://127.0.0.1:2181
dubbo.metadata-report.address=zookeeper://127.0.0.1:2181