一、项目整体结构
 整体包括如下子服务: api 公用的entity和service接口 provider-log log服务提供方 provider-message message服务提供方 consumer 消费方
代码地址链接 spring-boot-dubbo-master.
1.1 api公用的entity和service接口
 api添加两个entity和两个service,更有区分性
1.2 consumer消费方
 application.yml
server:
port: 5051
dubbo:
application:
name: sea-consumer-web
registry:
protocol: zookeeper
address: localhost:2181
protocol:
name: dubbo
port: 20551
version: 1.0.0
scan:
base-packages: com.web
consumer:
timeout: 5000
check: false
dubbo.application.name 给provider起的名称 dubbo.registry.address 表示注册的地址,不一定非得是zookeeper dubbo.protocol.name 就是dubbo dubbo.protocol.port 是注册的端口号,多个提供者使用的port需要区分开来 dubbo.protocol.scan 是表示扫描哪些包下面的服务 version是自定的一个版本属性
1.3 provider-log log服务提供方
 两个提供者provider,为的是更有区分性。 发布的服务通过@Service注解,加载被扫描的实现类上面,这里使用的是dubbo的注解。 SmsServiceImpl.java
package com.log.service.impl;
import org.apache.dubbo.config.annotation.Service;
import com.service.SmsService;
@Service(version = "${dubbo.version}")
public class SmsServiceImpl implements SmsService {
@Override
public String sendMsg(String msg) {
System.out.println("log project");
return "log project send msg is " + msg;
}
@Override
public void sendMsgVoid(String msg) {
System.out.println("sendMsgVoid log enter");
int i = 1 / 0;
System.out.println("sendMsgVoid log out");
}
}
1.4 provider-message message服务提供方

1.5 provider-xxp

二、测试发布
注意:一定要先保证zookeeper和dubbo服务正常启动
2.1 通过命令行方式查看dubbo服务
telnet 192.168.153.1 20552
按回车,得到结果 
2.2 通过Web界面查看
将war包放入Tomcat的webapps目录下,解压后,将apache-tomcat-8.5.20\webapps\dubbo-admin-2.5.7\WEB-INF\dubbo.properties修改成自己的zookeeper地址,启动Tomcat,输入 http://localhost:8080/dubbo-admin-2.5.7,账号密码默认都是root war包下载地址. 
2.3 方案测试
http://localhost:5051/hello  http://localhost:5051/aaa  http://localhost:5051/bbb    http://localhost:5051/msg/aaa  http://localhost:5051/msg/ddd  
|