zhangxd1989 / spring-boot-cloud

基于 Spring Boot、Spring Cloud、Spring Oauth2 和 Spring Cloud Netflix 等框架构建的微服务项目
2.12k stars 1.17k forks source link
consul eureka feign hystrix oauth ribbon spring-boot-admin spring-cloud spring-cloud-sleuth turbine zipkin zuul

基于 Spring Cloud 的微服务架构

本项目是一个基于 Spring Boot、Spring Cloud、Spring Oauth2 和 Spring Cloud Netflix 等框架构建的微服务项目。

技术栈

应用架构

该项目包含 8 个服务

体系架构

architecture

应用组件

components

启动项目

项目预览

注册中心

访问 http://localhost:8761/ 默认账号 user,密码 password

registry

监控

访问 http://localhost:8040/ 默认账号 admin,密码 admin

控制面板

monitor

应用注册历史

monitor

Turbine Hystrix面板

monitor

应用信息、健康状况、垃圾回收等详情

monitor

计数器

monitor

查看和修改环境变量

monitor

管理 Logback 日志级别

monitor

查看并使用 JMX

monitor

查看线程

monitor

认证历史

monitor

查看 Http 请求轨迹

monitor

Hystrix 面板

monitor

链路跟踪

访问 http://localhost:9411/ 默认账号 admin,密码 admin

控制面板

zipkin

链路跟踪明细

zipkin

服务依赖关系

zipkin

RabbitMQ 监控

Docker 启动访问 http://localhost:15673/ 默认账号 guest,密码 guest(本地 rabbit 管理系统默认端口15672)

rabbit

接口测试

  1. 获取 Token
    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"

    返回如下格式数据:

    {
    "access_token": "eac56504-c4f0-4706-b72e-3dc3acdf45e9",
    "token_type": "bearer",
    "refresh_token": "da1007dc-683c-4309-965d-370b15aa4aeb",
    "expires_in": 3599,
    "scope": "read write"
    }
  2. 使用 access token 访问 service a 接口
    curl -i -H "Authorization: Bearer eac56504-c4f0-4706-b72e-3dc3acdf45e9" http://localhost:8060/svca

    返回如下数据:

    svca-service (172.18.0.8:8080)===>name:zhangxd
    svcb-service (172.18.0.2:8070)===>Say Hello
  3. 使用 access token 访问 service b 接口
    curl -i -H "Authorization: Bearer eac56504-c4f0-4706-b72e-3dc3acdf45e9" http://localhost:8060/svcb

    返回如下数据:

    svcb-service (172.18.0.2:8070)===>Say Hello
  4. 使用 refresh token 刷新 token
    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"

    返回更新后的 Token:

    {
    "access_token": "63ff57ce-f140-482e-ba7e-b6f29df35c88",
    "token_type": "bearer",
    "refresh_token": "da1007dc-683c-4309-965d-370b15aa4aeb",
    "expires_in": 3599,
    "scope": "read write"
    }
  5. 刷新配置
    curl -X POST -vu user:password http://localhost:8888/bus/refresh