项目作者: zest-bridge

项目描述 :
For learning Spring Cloud
高级语言: Java
项目地址: git://github.com/zest-bridge/Spring-Cloud-Learn.git
创建时间: 2018-12-17T09:45:13Z
项目社区:https://github.com/zest-bridge/Spring-Cloud-Learn

开源协议:Apache License 2.0

下载


Spring-Cloud-Learn

学习 Spring Cloud 搭的架子,在 README.md 文件和 commit 日志中做一些笔记。

推荐一些在线查看代码的 google 插件:TODO

Spring Cloud Config

Config Server

弃用,待删除(替换成 Nacos)

  1. spring:
  2. cloud:
  3. config:
  4. server:
  5. git:
  6. # 可以通过 HTTP 调用获取(直接在地址栏中写),/{application}/{profile}[/{label}] 或者 /{application}-{profile}.yml 等,https://cloud.spring.io/spring-cloud-static/Edgware.SR5/single/spring-cloud.html#_quick_start
  7. zuulconfig
  8. zuulconfig
  9. # {label} --- commit id, branch name or tag
  10. # 如直接访问 http://localhost:8888/eureka-client/dev 获取此 Git 仓库 的 eureka-client 目录下的 eureka-client-dev.yml 文件
  11. uri: zuulconfig # Git 仓库地址
  12. search-paths: /{application} # 仓库下的搜索目录(前面的 / 不能省略)
  13. force-pull: true
  14. username: Pliza
  15. password: 4fdsfs18@qqfdsfsafasdh111

config-server 仓库中新增默认的配置文件(eureka-server.yml)后,仓库中的文件如下图所示:

yml文件

再次在浏览器中访问,http://localhost:8888/eureka-client/test 或者 http://localhost:8888/eureka-client/dev ,都会显示默认的 eureka-client.yml 文件

Config Client

弃用,待删除(替换成 Nacos)

  1. # 多环境通用配置
  2. spring:
  3. application:
  4. name: eureka-server #first-cloud-server
  5. cloud:
  6. # 参考 http://localhost:xxxx/eureka-client/dev(格式 /{application}/{profile})
  7. zuulconfig
  8. config:
  9. uri: http://localhost:7777 #指定 Spring Cloud Config 配置服务器
  10. label: master #拉取内容的分支名,默认为 master
  11. profile: dev
  12. name: eureka-client
  13. profiles:
  14. active: ${profiles.active} #指定生效的配置,可以通过 java -jar xxx.jar --spring.profiles.active=x 指定.
  15. management:
  16. security:
  17. enabled: false
  18. ---
  19. server:
  20. port: 8761
  21. spring:
  22. profiles: dev
  23. # 服务在启动时,会把自己当做一个 Eureka 客户端去注册到 Eureka 服务器上,且从服务器上拉取信息
  24. # 而该服务本身就是一个 Eureka 服务器(现在是配置 Eureka 集群,需要彼此相互注册)
  25. eureka:
  26. instance:
  27. hostname: localhost
  28. client:
  29. # 声明是否将自己的信息注册到 Eureka 服务器上
  30. register-with-eureka: false
  31. # 是否到 Eureka 服务器中抓取注册信息
  32. fetch-registry: false
  33. # serviceUrl:
  34. # defaultZone: http://localhost:8762/eureka/
  35. ---
  36. server:
  37. port: 8762
  38. spring:
  39. profiles: test
  40. eureka:
  41. instance:
  42. hostname: Zhoust
  43. client:
  44. serviceUrl:
  45. defaultZone: http://localhost:8761/eureka/

启动 Config Client 后,查看 env 端点,得到以下关于 ConfigService 的信息:

  1. "configService:configClient": {
  2. "config.client.version": "f2fc68892a49902d4a10f7e3eb486f3d46a717cb"
  3. },
  4. "configService:https://github.com/Pliza/config-server/eureka-client/eureka-client-dev.yml": {
  5. "info.name": "Pliza666",
  6. "info.gender": "girl",
  7. "info.age": 22
  8. },
  9. "configService:https://github.com/Pliza/config-server/eureka-client/eureka-client.yml": {
  10. "info.name": "default-name",
  11. "info.gender": "default-boy"
  12. },

可以看到即使在 bootstrap.yml 文件中指定了 spring.cloud.config.profile=dev(如果要是不配置的话,会使用 ${spring.application.name},观察控制台输出「Located environment」),仍旧会显示默认的 eureka-client.yml,但实际起作用的还是 eureka-client-dev.yml 中的配置信息,通过 /env/xxx 可查看具体某属性的值是多少。

  1. #访问 Config Client 的 http://localhost:8761/env/info.*
  2. {
  3. "info.name": "Pliza666",
  4. "info.gender": "girl",
  5. "info.age": 22
  6. }

Hystrix

Whether or not your command has a fallback, all of the usual Hystrix state and circuit-breaker state/metrics are updated to indicate the command failure.

计划和 TODO

  1. 弃用 config-server module
  2. common-starter:测试包添加 java 基础回炉内容
  3. 使用阿里 Nacos
  4. Reactor 学习 demo(待完善)
  5. Spring Cloud Gateway 深入理解