1.1 下載源碼
我們可以在下面鏈接下載Soul源碼 鏈接,下載完成后通過(guò)以下命令進(jìn)行編譯。
mvn clean package install -Dmaven.test.skip=true -Dmaven.javadoc.skip=true -Drat.skip=true -Dcheckstyle.skip=true
1.1.1 Soul-admin
soul-admin soul控制臺(tái)勿侯,主要負(fù)載soul的元數(shù)據(jù)管理拓瞪,它是集成了一個(gè)前端管理控制臺(tái),可以配置插件助琐,限流荞膘,防火墻等功能疟暖。
server:
port: 9095
address: 0.0.0.0
spring:
thymeleaf:
cache: true
encoding: utf-8
enabled: true
prefix: classpath:/static/
suffix: .html
datasource:
url: jdbc:mysql://localhost:3306/soul?useUnicode=true&characterEncoding=utf-8
username: root
password:
driver-class-name: com.mysql.jdbc.Driver
mybatis:
config-location: classpath:/mybatis/mybatis-config.xml
mapper-locations: classpath:/mappers/*.xml
soul:
sync:
websocket:
enabled : true
如上卡辰,我們只需要將我們的Mysql數(shù)據(jù)庫(kù)配上去钠右,然后啟動(dòng),Soul會(huì)自動(dòng)為我們創(chuàng)建數(shù)據(jù)庫(kù)和對(duì)應(yīng)的表掘譬。
Database changed
mysql> show tables
-> ;
+--------------------+
| Tables_in_soul |
+--------------------+
| app_auth |
| auth_param |
| auth_path |
| dashboard_user |
| meta_data |
| plugin |
| plugin_handle |
| rule |
| rule_condition |
| selector |
| selector_condition |
| soul_dict |
+--------------------+
12 rows in set (0.01 sec)
然后我們?cè)L問(wèn)這個(gè)鏈接就可以進(jìn)行訪問(wèn)了 http://localhost:9095/ 用戶名和密碼是admin/123456泰演。
1.1.2 soul-bootstrap
soul-bootstrap 根據(jù)soul-admin的配置負(fù)責(zé)將請(qǐng)求轉(zhuǎn)發(fā)的后面的服務(wù)
配置文件:
# 這里配置soul-bootstrap 與 soul-admin的交互的方式,我們先使用最簡(jiǎn)單的websocket葱轩,這里配置上soul-admin的地址
soul :
file:
enabled: true
corss:
enabled: true
dubbo :
parameter: multi
sync:
websocket :
urls: ws://localhost:9095/websocket
soul-bootstrap 的地址是 http://127.0.0.1:9195 訪問(wèn)結(jié)果如圖
soul-admin 目前還沒有任何信息睦焕,soul-bootstrap 可以集成dubbo SpringCloud SpringBoot等模塊,我們接來(lái)一個(gè)個(gè)使用靴拱。
1.1.3 soul-test-dubbo
首先我們需要在插件管理開啟Dubbo插件
然后我們?cè)?spring-dubbo.xml 這個(gè)文件配置上zookeeper 就可以啟動(dòng)了
<dubbo:registry address="zookeeper://localhost:2181"/>
我們?cè)倏匆幌略獢?shù)據(jù)管理就可以看到注冊(cè)上soul-admin 的內(nèi)容了
dubbo中暴露的接口信息如下
@Service("dubboTestService")
public class DubboTestServiceImpl implements DubboTestService {
@Override
@SoulDubboClient(path = "/findById", desc = "根據(jù)用戶查詢")
public DubboTest findById(final String id) {
DubboTest dubboTest = new DubboTest();
dubboTest.setId(id);
dubboTest.setName("hello world Soul Alibaba Dubbo, findById");
return dubboTest;
}
@Override
@SoulDubboClient(path = "/findAll", desc = "獲取所有")
public DubboTest findAll() {
DubboTest dubboTest = new DubboTest();
dubboTest.setName("hello world Soul Alibaba Dubbo , findAll");
dubboTest.setId(String.valueOf(new Random().nextInt()));
return dubboTest;
}
@Override
@SoulDubboClient(path = "/insert", desc = "插入一條數(shù)據(jù)")
public DubboTest insert(final DubboTest dubboTest) {
dubboTest.setName("hello world Soul Alibaba Dubbo: " + dubboTest.getName());
return dubboTest;
}
}
我們需要重啟一下 soul-admin 和 soul-bootstrap 然后就可以訪問(wèn)了垃喊。
壓測(cè)得到以下數(shù)據(jù)
mac@AndydeMacBook-Pro ~ wrk -t 4 -c 20 http://localhost:9195/dubbo/findAll
Running 10s test @ http://localhost:9195/dubbo/findAll
4 threads and 20 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 3.26ms 2.80ms 48.48ms 94.34%
Req/Sec 1.71k 257.03 2.16k 78.00%
68000 requests in 10.01s, 12.13MB read
Requests/sec: 6789.82
Transfer/sec: 1.21MB
1.1.3 soul-test-http 測(cè)試SpringBoot 項(xiàng)目
soul 配置如下,設(shè)置contextPath 和 admin 的地址
soul:
http:
adminUrl: http://localhost:9095
port: 8188
contextPath: /http
appName: http
full: false
主要接口如下:只需要配置 @SoulSpringMvcClient 這個(gè)注解即可使用
@RestController
@RequestMapping("/test")
@SoulSpringMvcClient(path = "/test/**")
public class HttpTestController {
@PostMapping("/payment")
public UserDTO post(@RequestBody final UserDTO userDTO) {
return userDTO;
}
@GetMapping("/findByUserId")
public UserDTO findByUserId(@RequestParam("userId") final String userId) {
UserDTO userDTO = new UserDTO();
userDTO.setUserId(userId);
userDTO.setUserName("hello world");
return userDTO;
}
@GetMapping("/path/{id}")
public UserDTO getPathVariable(@PathVariable("id") final String id, @RequestParam("name") final String name) {
UserDTO userDTO = new UserDTO();
userDTO.setUserId(id);
userDTO.setUserName("hello world");
return userDTO;
}
@GetMapping("/path/{id}/name")
public UserDTO testRestFul(@PathVariable("id") final String id) {
UserDTO userDTO = new UserDTO();
userDTO.setUserId(id);
userDTO.setUserName("hello world");
return userDTO;
}
@PutMapping("/putPathBody/{id}")
public UserDTO putPathVariableAndBody(@PathVariable("id") final String id, @RequestBody final UserDTO userDTO) {
userDTO.setUserId(id);
userDTO.setUserName("hello world");
return userDTO;
}
}
開啟Divide 插件
如圖已經(jīng)能查看到元數(shù)據(jù)信息
訪問(wèn)情況
壓測(cè)情況
mac@AndydeMacBook-Pro ~ wrk -t 4 -c 20 http://localhost:9195/http/test/findByUserId\?userId\=1
Running 10s test @ http://localhost:9195/http/test/findByUserId?userId=1
4 threads and 20 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 11.85ms 14.74ms 126.42ms 86.84%
Req/Sec 667.48 163.61 1.22k 72.25%
26616 requests in 10.02s, 2.79MB read
Requests/sec: 2656.05
Transfer/sec: 285.34KB