soul 示例项目

This commit is contained in:
YunaiV
2020-05-23 09:04:24 +08:00
parent 899e8670b3
commit 19df98faed
5 changed files with 55 additions and 5 deletions

View File

@@ -193,7 +193,7 @@
> 如下非 Spring Cloud 网关,先放在这里...
* [《芋道 APISIX 极简入门(国产微服务网关)》](http://www.iocoder.cn/iocoder.cn/APISIX/install/?github) 对应 [lab-56](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-56)
* [《芋道 APISIX 极简入门(国产微服务网关)》](http://www.iocoder.cn/APISIX/install/?github) 对应 [lab-56](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-56)
## 配置中心

View File

@@ -1,7 +1,11 @@
package cn.iocoder.springboot.lab60.userservice.api;
import cn.iocoder.springboot.lab60.userservice.api.dto.UserCreateDTO;
public interface UserService {
String getUser(Integer id);
Integer createUser(UserCreateDTO createDTO);
}

View File

@@ -0,0 +1,34 @@
package cn.iocoder.springboot.lab60.userservice.api.dto;
/**
* 用户创建 DTO
*/
public class UserCreateDTO {
/**
* 昵称
*/
private String nickname;
/**
* 性别
*/
private Integer gender;
public String getNickname() {
return nickname;
}
public UserCreateDTO setNickname(String nickname) {
this.nickname = nickname;
return this;
}
public Integer getGender() {
return gender;
}
public UserCreateDTO setGender(Integer gender) {
this.gender = gender;
return this;
}
}

View File

@@ -1,16 +1,28 @@
package cn.iocoder.springboot.lab60.userservice.service;
import cn.iocoder.springboot.lab60.userservice.api.UserService;
import cn.iocoder.springboot.lab60.userservice.api.dto.UserCreateDTO;
import org.dromara.soul.client.common.annotation.SoulClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@org.apache.dubbo.config.annotation.Service(version = "1.0.0")
public class UserServiceImpl implements UserService {
private Logger logger = LoggerFactory.getLogger(getClass());
@Override
@SoulClient(path = "/user/get", desc = "获得用户详细")
public String getUser(Integer id) {
return "User:" + id;
}
@Override
@SoulClient(path = "/user/create", desc = "创建用户")
public Integer createUser(UserCreateDTO createDTO) {
logger.info("[createUser][username({}) password({})]", createDTO.getNickname(), createDTO.getGender());
return 1;
}
}

View File

@@ -6,7 +6,6 @@ dubbo:
# Dubbo 注册中心配
registry:
address: nacos://127.0.0.1:8848 # 注册中心地址。个鞥多注册中心,可见 http://dubbo.apache.org/zh-cn/docs/user/references/registry/introduction.html 文档。
# address: zookeeper://127.0.0.1:2181 # 注册中心地址。多注册中心,可见 http://dubbo.apache.org/zh-cn/docs/user/references/registry/introduction.html 文档。
# Dubbo 服务提供者协议配置
protocol:
port: -1 # 协议端口。使用 -1 表示随机端口。
@@ -21,6 +20,7 @@ dubbo:
soul:
# Soul 针对 Dubbo 的配置项,对应 DubboConfig 配置类
dubbo:
admin-url: http://127.0.0.1:9095
context-path: /demo-api
app-name: demo-service
admin-url: http://127.0.0.1:9095 # Soul Admin 地址
context-path: /user-api # 设置在 Soul 网关的路由前缀,例如说 /order、/product 等等。
# 后续,网关会根据该 context-path 来进行路由
app-name: user-service # 应用名。未配置情况下,默认使用 Dubbo 的应用名