Skip to content

Commit d4669fe

Browse files
committed
update readme
1 parent 76f5117 commit d4669fe

File tree

1 file changed

+109
-1
lines changed

1 file changed

+109
-1
lines changed

README.md

Lines changed: 109 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,109 @@
1-
# spring-boot-cloud
1+
# 基于 Spring Cloud 的微服务架构
2+
3+
本项目是一个基于 Spring Boot、Spring Cloud、Spring Oauth2 和 Netflix OSS 等框架构建的微服务基础架构。
4+
5+
# 技术栈
6+
* Spring boot - 微服务的入门级微框架,用来简化 Spring 应用的初始搭建以及开发过程。
7+
* Eureka - 云端服务发现,一个基于 REST 的服务,用于定位服务,以实现云端中间层服务发现和故障转移。
8+
* Spring Cloud Config - 配置管理工具包,让你可以把配置放到远程服务器,集中化管理集群配置,目前支持本地存储、Git 以及 Subversion。
9+
* Hystrix - 熔断器,容错管理工具,旨在通过熔断机制控制服务和第三方库的节点,从而对延迟和故障提供更强大的容错能力。
10+
* Zuul - Zuul 是在云平台上提供动态路由,监控,弹性,安全等边缘服务的框架。Zuul 相当于是设备和 Netflix 流应用的 Web 网站后端所有请求的前门。
11+
* Spring Cloud Bus - 事件、消息总线,用于在集群(例如,配置变化事件)中传播状态变化,可与 Spring Cloud Config 联合实现热部署。
12+
* Spring Cloud Sleuth - 日志收集工具包,封装了 Dapper 和 log-based 追踪以及 Zipkin 和 HTrace 操作,为 SpringCloud 应用实现了一种分布式追踪解决方案。
13+
* Ribbon - 提供云端负载均衡,有多种负载均衡策略可供选择,可配合服务发现和断路器使用。
14+
* Turbine - Turbine 是聚合服务器发送事件流数据的一个工具,用来监控集群下 hystrix 的 metrics 情况。
15+
* Spring Cloud Stream - Spring 数据流操作开发包,封装了与 Redis、Rabbit、Kafka 等发送接收消息。
16+
* Feign - Feign 是一种声明式、模板化的 HTTP 客户端。
17+
* Spring Cloud OAuth2 - 基于 Spring Security 和 OAuth2 的安全工具包,为你的应用程序添加安全控制。
18+
19+
# 应用架构
20+
21+
该项目包含 8 个服务
22+
23+
* registry - 服务注册于发现
24+
* config - 外部配置
25+
* monitor - 监控
26+
* zipkin - 分布式跟踪
27+
* gateway - 代理所有微服务的接口网关
28+
* auth-service - OAuth2 认证服务
29+
* svca-service - 业务服务A
30+
* svcb-service - 业务服务B
31+
32+
## 体系架构
33+
//TODO 架构图
34+
## 应用组件
35+
//TODO 架构图
36+
37+
# 启动项目
38+
39+
* 使用 Docker 快速启动
40+
1. 配置 Docker 环境
41+
2. `mvn clean package` 打包项目及 Docker 镜像
42+
3. 在项目根目录下执行 `docker-compose up -d` 启动所有项目
43+
* 本地手动启动
44+
1. 配置 rabbitmq
45+
2. 修改 hosts 将主机名指向到本地
46+
`127.0.0.1 registry config monitor rabbitmq auth-service`
47+
或者修改各服务配置文件中的相应主机名为本地 ip
48+
3. 启动 registry、config、monitor、zipkin
49+
4. 启动 gateway、auth-service、svca-service、svcb-service
50+
51+
# 项目预览
52+
53+
## 注册中心
54+
访问 http://localhost:8761/ 默认账号 user,密码 password
55+
//TODO 图片
56+
## 监控
57+
访问 http://localhost:8040/ 默认账号 admin,密码 admin
58+
//TODO 图片
59+
## 链路跟踪
60+
访问 http://localhost:9411/ 默认账号 admin,密码 admin
61+
//TODO 图片
62+
## RabbitMQ 监控
63+
Docker 启动访问 http://localhost:15673/ 默认账号 guest,密码 guest(本地 rabbit 管理系统默认端口15672)
64+
# 接口测试
65+
1. 获取 Token
66+
```
67+
curl -X POST -vu client:secret http://localhost:8060/uaa/oauth/token -H "Accept: application/json" -d "password=password&username=anil&grant_type=password&scope=read%20write"
68+
```
69+
返回如下格式数据:
70+
```
71+
{
72+
"access_token": "eac56504-c4f0-4706-b72e-3dc3acdf45e9",
73+
"token_type": "bearer",
74+
"refresh_token": "da1007dc-683c-4309-965d-370b15aa4aeb",
75+
"expires_in": 3599,
76+
"scope": "read write"
77+
}
78+
```
79+
2. 使用 access token 访问 service a 接口
80+
```
81+
curl -i -H "Authorization: Bearer eac56504-c4f0-4706-b72e-3dc3acdf45e9" http://localhost:8060/svca
82+
```
83+
返回如下数据:
84+
```
85+
svca-service (172.18.0.8:8080)===>name:zhangxd
86+
svcb-service (172.18.0.2:8070)===>Say Hello
87+
```
88+
3. 使用 access token 访问 service b 接口
89+
```
90+
curl -i -H "Authorization: Bearer eac56504-c4f0-4706-b72e-3dc3acdf45e9" http://localhost:8060/svcb
91+
```
92+
返回如下数据:
93+
```
94+
svcb-service (172.18.0.2:8070)===>Say Hello
95+
```
96+
4. 使用 refresh token 刷新 token
97+
```
98+
curl -X POST -vu client:secret http://localhost:8060/uaa/oauth/token -H "Accept: application/json" -d "grant_type=refresh_token&refresh_token=da1007dc-683c-4309-965d-370b15aa4aeb"
99+
```
100+
返回更新后的 Token:
101+
```
102+
{
103+
"access_token": "63ff57ce-f140-482e-ba7e-b6f29df35c88",
104+
"token_type": "bearer",
105+
"refresh_token": "da1007dc-683c-4309-965d-370b15aa4aeb",
106+
"expires_in": 3599,
107+
"scope": "read write"
108+
}
109+
```

0 commit comments

Comments
 (0)