├── spring-cloud-greenwich ├── config-repo │ ├── microservice-config-client.properties │ ├── microservice-config-client-dev.properties │ ├── microservice-config-client-production.properties │ └── microservice-config-client-eureka-dev.properties ├── pay │ ├── alipay.jpeg │ └── wechat.jpeg ├── microservice-api-gateway │ ├── README.md │ ├── src │ │ └── main │ │ │ ├── docker │ │ │ └── Dockerfile │ │ │ ├── java │ │ │ └── com │ │ │ │ └── minbo │ │ │ │ └── cloud │ │ │ │ └── study │ │ │ │ ├── ZuulApiGatewayApplication.java │ │ │ │ ├── TokenVerifyFilter.java │ │ │ │ └── MyFallbackProvider.java │ │ │ └── resources │ │ │ └── application.yml │ └── pom.xml ├── microservice-hystrix-dashboard │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.yml │ │ │ └── java │ │ │ └── com │ │ │ └── minbo │ │ │ └── cloud │ │ │ └── study │ │ │ └── hystrixdashboard │ │ │ └── HystrixDashboardApplication.java │ └── pom.xml ├── microservice-consumer-zipkin-hi │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.yml │ │ │ └── java │ │ │ └── com │ │ │ └── minbo │ │ │ └── cloud │ │ │ └── study │ │ │ ├── ZipkinStartHiApplication.java │ │ │ └── controller │ │ │ └── HiRestController.java │ └── pom.xml ├── microservice-consumer-zipkin-greet │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.yml │ │ │ └── java │ │ │ └── com │ │ │ └── minbo │ │ │ └── cloud │ │ │ └── study │ │ │ ├── ZipkinStartGreetApplication.java │ │ │ └── controller │ │ │ └── GreetRestController.java │ └── pom.xml ├── microservice-config-client │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ ├── application.yml │ │ │ └── bootstrap.yml │ │ │ └── java │ │ │ └── com │ │ │ └── minbo │ │ │ └── cloud │ │ │ └── study │ │ │ ├── ConfigClientApplication.java │ │ │ └── controller │ │ │ └── ConfigClientController.java │ └── pom.xml ├── microservice-config-client-eureka │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ ├── application.yml │ │ │ └── bootstrap.yml │ │ │ └── java │ │ │ └── com │ │ │ └── minbo │ │ │ └── cloud │ │ │ └── study │ │ │ ├── ConfigClientEurekaApplication.java │ │ │ └── controller │ │ │ └── ConfigClientController.java │ └── pom.xml ├── microservice-consumer-movie-feign │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.yml │ │ │ └── java │ │ │ └── com │ │ │ └── minbo │ │ │ └── cloud │ │ │ └── study │ │ │ ├── feign │ │ │ ├── MyFeignClient.java │ │ │ └── MyFeignClient2.java │ │ │ ├── controller │ │ │ └── FeignController.java │ │ │ └── MovieFeignApplication.java │ └── pom.xml ├── microservice-consumer-movie-ribbon │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.yml │ │ │ └── java │ │ │ └── com │ │ │ └── minbo │ │ │ └── cloud │ │ │ └── study │ │ │ ├── service │ │ │ └── RibbonService.java │ │ │ ├── controller │ │ │ └── RibbonController.java │ │ │ └── MovieRibbonApplication.java │ └── pom.xml ├── microservice-consumer-movie-feign-with-hystrix │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.yml │ │ │ └── java │ │ │ └── com │ │ │ └── minbo │ │ │ └── cloud │ │ │ └── study │ │ │ ├── MovieFeignHystrixApplication.java │ │ │ ├── controller │ │ │ └── FeignHystrixController.java │ │ │ └── feign │ │ │ └── MyFeignHystrixClient.java │ └── pom.xml ├── microservice-config-server │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.yml │ │ │ └── java │ │ │ └── com │ │ │ └── minbo │ │ │ └── cloud │ │ │ └── study │ │ │ └── ConfigServerApplication.java │ └── pom.xml ├── microservice-consumer-movie-feign-with-hystrix-stream │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.yml │ │ │ └── java │ │ │ └── com │ │ │ └── minbo │ │ │ └── cloud │ │ │ └── study │ │ │ ├── controller │ │ │ └── FeignHystrixController.java │ │ │ ├── MovieFeignHystrixApplication.java │ │ │ └── feign │ │ │ └── MyFeignClient.java │ └── pom.xml ├── microservice-config-server-eureka │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.yml │ │ │ └── java │ │ │ └── com │ │ │ └── minbo │ │ │ └── cloud │ │ │ └── study │ │ │ └── ConfigServerEurekaApplication.java │ └── pom.xml ├── microservice-provider-user │ ├── src │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── minbo │ │ │ │ └── cloud │ │ │ │ └── study │ │ │ │ ├── UserApplication.java │ │ │ │ └── controller │ │ │ │ └── HiController.java │ │ │ └── resources │ │ │ └── application.yml │ └── pom.xml ├── microservice-discovery-eureka │ ├── src │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── minbo │ │ │ │ └── cloud │ │ │ │ └── study │ │ │ │ └── EurekaApplication.java │ │ │ └── resources │ │ │ ├── application-ha.yml │ │ │ └── application.yml │ └── pom.xml ├── microservice-consumer-movie-ribbon-with-hystrix │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ └── application.yml │ │ │ └── java │ │ │ └── com │ │ │ └── minbo │ │ │ └── cloud │ │ │ └── study │ │ │ ├── controller │ │ │ └── RibbonHystrixController.java │ │ │ ├── service │ │ │ └── RibbonHystrixService.java │ │ │ └── MovieRibbonHystrixApplication.java │ └── pom.xml ├── microservice-hystrix-turbine │ ├── src │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── minbo │ │ │ │ └── cloud │ │ │ │ └── study │ │ │ │ └── turbine │ │ │ │ └── TurbineApplication.java │ │ │ └── resources │ │ │ └── application.yml │ └── pom.xml ├── pom.xml └── README.md ├── pay ├── alipay.jpeg └── wechat.jpeg ├── spring-cloud-hoxton ├── pay │ ├── alipay.jpeg │ └── wechat.jpeg └── README.md ├── .gitignore ├── spring-cloud-alibaba ├── microservice-alibaba-nacos-discovery │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ ├── bootstrap.yaml │ │ │ ├── bootstrap.yaml.bak │ │ │ └── logback.xml │ │ │ └── java │ │ │ └── com │ │ │ └── minbo │ │ │ └── cloud │ │ │ └── alibaba │ │ │ ├── Application.java │ │ │ ├── controller │ │ │ └── InitController.java │ │ │ └── web │ │ │ ├── WebConfig.java │ │ │ ├── CustomHttpInterceptor.java │ │ │ └── SwaggerConfig.java │ ├── README.md │ └── pom.xml ├── microservice-alibaba-sentinel │ ├── README.md │ ├── src │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── minbo │ │ │ │ └── cloud │ │ │ │ └── alibaba │ │ │ │ ├── Application.java │ │ │ │ ├── util │ │ │ │ ├── ResultCode.java │ │ │ │ └── JsonResult.java │ │ │ │ ├── controller │ │ │ │ └── InitController.java │ │ │ │ └── web │ │ │ │ ├── WebConfig.java │ │ │ │ ├── CustomHttpInterceptor.java │ │ │ │ └── SwaggerConfig.java │ │ │ └── resources │ │ │ ├── bootstrap.yaml │ │ │ └── logback.xml │ └── pom.xml ├── microservice-alibaba-nacos-config │ ├── src │ │ └── main │ │ │ ├── resources │ │ │ ├── bootstrap.yaml │ │ │ ├── logback.xml │ │ │ ├── bootstrap.yaml.bak │ │ │ └── bootstrap.yaml2.bak │ │ │ └── java │ │ │ └── com │ │ │ └── minbo │ │ │ └── cloud │ │ │ └── alibaba │ │ │ ├── Application.java │ │ │ ├── util │ │ │ ├── ResultCode.java │ │ │ └── JsonResult.java │ │ │ ├── controller │ │ │ └── InitController.java │ │ │ └── web │ │ │ ├── WebConfig.java │ │ │ ├── CustomHttpInterceptor.java │ │ │ └── SwaggerConfig.java │ ├── README.md │ └── pom.xml ├── README.md └── pom.xml └── README.md /spring-cloud-greenwich/config-repo/microservice-config-client.properties: -------------------------------------------------------------------------------- 1 | profile=default -------------------------------------------------------------------------------- /pay/alipay.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hemin1003/spring-cloud-study/HEAD/pay/alipay.jpeg -------------------------------------------------------------------------------- /pay/wechat.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hemin1003/spring-cloud-study/HEAD/pay/wechat.jpeg -------------------------------------------------------------------------------- /spring-cloud-greenwich/config-repo/microservice-config-client-dev.properties: -------------------------------------------------------------------------------- 1 | profile=abcd123 2 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/config-repo/microservice-config-client-production.properties: -------------------------------------------------------------------------------- 1 | profile=production -------------------------------------------------------------------------------- /spring-cloud-greenwich/config-repo/microservice-config-client-eureka-dev.properties: -------------------------------------------------------------------------------- 1 | profile=abcd999123 2 | -------------------------------------------------------------------------------- /spring-cloud-hoxton/pay/alipay.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hemin1003/spring-cloud-study/HEAD/spring-cloud-hoxton/pay/alipay.jpeg -------------------------------------------------------------------------------- /spring-cloud-hoxton/pay/wechat.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hemin1003/spring-cloud-study/HEAD/spring-cloud-hoxton/pay/wechat.jpeg -------------------------------------------------------------------------------- /spring-cloud-greenwich/pay/alipay.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hemin1003/spring-cloud-study/HEAD/spring-cloud-greenwich/pay/alipay.jpeg -------------------------------------------------------------------------------- /spring-cloud-greenwich/pay/wechat.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hemin1003/spring-cloud-study/HEAD/spring-cloud-greenwich/pay/wechat.jpeg -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-api-gateway/README.md: -------------------------------------------------------------------------------- 1 | 资料参考: 2 | 3 | [网关服务限流/API限流(Zuul+RateLimiter)](https://my.oschina.net/wuweixiang/blog/3011756) -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-hystrix-dashboard/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: hystrix-dashboard 4 | server: 5 | port: 8030 -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-zipkin-hi/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8988 3 | spring: 4 | application: 5 | name: microservice-consumer-zipkin-hi 6 | zipkin: 7 | base-url: http://localhost:9411 -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-zipkin-greet/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8989 3 | spring: 4 | application: 5 | name: microservice-consumer-zipkin-greet 6 | zipkin: 7 | base-url: http://localhost:9411 -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-api-gateway/src/main/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM java:8 2 | VOLUME /tmp 3 | ADD api-gateway-microservice-0.1.0.jar app.jar 4 | RUN bash -c 'touch /app.jar' 5 | ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"] 6 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-config-client/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8041 3 | management: 4 | endpoint: 5 | refresh: 6 | enabled: true 7 | endpoints: 8 | web: 9 | exposure: 10 | include: 11 | - info 12 | - health 13 | - refresh -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-config-client-eureka/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8051 3 | management: 4 | endpoint: 5 | refresh: 6 | enabled: true 7 | endpoints: 8 | web: 9 | exposure: 10 | include: 11 | - info 12 | - health 13 | - refresh -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-movie-feign/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8020 3 | spring: 4 | application: 5 | name: microservice-consumer-movie-feign 6 | eureka: 7 | client: 8 | serviceUrl: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | preferIpAddress: true -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-movie-ribbon/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8010 3 | spring: 4 | application: 5 | name: microservice-consumer-movie-ribbon 6 | eureka: 7 | client: 8 | serviceUrl: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | preferIpAddress: true -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # maven ignore 2 | target/ 3 | *.jar 4 | *.war 5 | *.zip 6 | *.tar 7 | *.tar.gz 8 | 9 | # eclipse ignore 10 | .settings/ 11 | .project 12 | .classpath 13 | 14 | # idea ignore 15 | .idea/ 16 | *.ipr 17 | *.iml 18 | *.iws 19 | 20 | # temp ignore 21 | *.log 22 | *.cache 23 | *.diff 24 | *.patch 25 | *.tmp 26 | 27 | # system ignore 28 | .DS_Store 29 | Thumbs.db 30 | 31 | # else 32 | .springBeans 33 | -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-nacos-discovery/src/main/resources/bootstrap.yaml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: microservice-alibaba-nacos-discovery 4 | profiles: 5 | active: dev 6 | cloud: 7 | nacos: 8 | discovery: 9 | server-addr: 127.0.0.1:8848 10 | namespace: 2bc5565f-453f-4b1c-bde4-eafe23bdb2f0 11 | # server 12 | server: 13 | port: 9090 -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-movie-feign-with-hystrix/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8021 3 | spring: 4 | application: 5 | name: microservice-consumer-movie-feign-with-hystrix 6 | eureka: 7 | client: 8 | serviceUrl: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | preferIpAddress: true 12 | feign: 13 | hystrix: 14 | enabled: true -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-config-client/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: microservice-config-client # 对应microservice-config-server所获取的配置文件的{application} 4 | cloud: 5 | config: 6 | uri: http://localhost:8040/ 7 | profile: dev # 指定profile,对应microservice-config-server所获取的配置文件中的{profile} 8 | label: master # 指定git仓库的分支,对应microservice-config-server所获取的配置文件的{label} -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-config-client/src/main/java/com/minbo/cloud/study/ConfigClientApplication.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ConfigClientApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ConfigClientApplication.class, args); 11 | } 12 | 13 | } -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-zipkin-hi/src/main/java/com/minbo/cloud/study/ZipkinStartHiApplication.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ZipkinStartHiApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ZipkinStartHiApplication.class, args); 11 | } 12 | } -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-zipkin-greet/src/main/java/com/minbo/cloud/study/ZipkinStartGreetApplication.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ZipkinStartGreetApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ZipkinStartGreetApplication.class, args); 11 | } 12 | } -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-config-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8040 3 | spring: 4 | application: 5 | name: microservice-config-server 6 | cloud: 7 | config: 8 | server: 9 | git: 10 | # 如果是公开仓库,可以不用填写账号和密码 11 | uri: https://github.com/hemin1003/spring-cloud-study # 配置git仓库的地址 12 | search-paths: config-repo # git仓库地址下的相对地址,可以配置多个,用,分割。 13 | username: # git仓库的账号 14 | password: # git仓库的密码 -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-movie-feign-with-hystrix-stream/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8022 3 | spring: 4 | application: 5 | name: microservice-consumer-movie-feign-with-hystrix-stream 6 | eureka: 7 | client: 8 | serviceUrl: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | preferIpAddress: true 12 | feign: 13 | hystrix: 14 | enabled: true 15 | management: 16 | endpoints: 17 | web: 18 | exposure: 19 | include: '*' -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-config-server-eureka/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8050 3 | spring: 4 | application: 5 | name: microservice-config-server-eureka 6 | cloud: 7 | config: 8 | server: 9 | git: 10 | uri: https://github.com/hemin1003/spring-cloud-study 11 | search-paths: config-repo 12 | username: 13 | password: 14 | eureka: 15 | client: 16 | serviceUrl: 17 | defaultZone: http://localhost:8761/eureka/ -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-provider-user/src/main/java/com/minbo/cloud/study/UserApplication.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaClient 9 | public class UserApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(UserApplication.class, args); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-provider-user/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8000 3 | spring: 4 | application: 5 | name: microservice-provider-user # 项目名称尽量用小写 6 | eureka: 7 | # 配置开启健康检查 8 | client: 9 | healthcheck: 10 | enabled: true 11 | serviceUrl: 12 | defaultZone: http://localhost:8761/eureka/ # 指定注册中心的地址 13 | instance: 14 | # IP地址优先 15 | preferIpAddress: true 16 | # 按需配置续约更新时间和到期时间 17 | lease-expiration-duration-in-seconds: 30 18 | lease-renewal-interval-in-seconds: 10 -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-config-client-eureka/src/main/java/com/minbo/cloud/study/ConfigClientEurekaApplication.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | @SpringBootApplication 8 | @EnableDiscoveryClient 9 | public class ConfigClientEurekaApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(ConfigClientEurekaApplication.class, args); 13 | } 14 | 15 | } -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-discovery-eureka/src/main/java/com/minbo/cloud/study/EurekaApplication.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | /** 8 | * 使用Eureka做服务发现. 9 | */ 10 | @SpringBootApplication 11 | @EnableEurekaServer 12 | public class EurekaApplication { 13 | 14 | public static void main(String[] args) { 15 | SpringApplication.run(EurekaApplication.class, args); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-movie-ribbon-with-hystrix/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8011 3 | spring: 4 | application: 5 | name: microservice-consumer-movie-ribbon-with-hystrix 6 | eureka: 7 | client: 8 | serviceUrl: 9 | defaultZone: http://localhost:8761/eureka/ 10 | instance: 11 | preferIpAddress: true 12 | #instance: 13 | # hostname: ribbon # 此处,preferIpAddress不设置或者设为false,不能设为true,否则影响turbine的测试。turbine存在的问题:eureka.instance.hostname一致时只能检测到一个节点,会造成turbine数据不完整 14 | management: 15 | endpoints: 16 | web: 17 | exposure: 18 | include: '*' -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-movie-ribbon/src/main/java/com/minbo/cloud/study/service/RibbonService.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study.service; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Service; 5 | import org.springframework.web.client.RestTemplate; 6 | 7 | @Service 8 | public class RibbonService { 9 | 10 | @Autowired 11 | private RestTemplate restTemplate; 12 | 13 | public String hiService(String name) { 14 | String result = restTemplate.getForObject("http://microservice-provider-user/hi?name=" + name, String.class); 15 | System.out.println(result); 16 | return result; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-config-server-eureka/src/main/java/com/minbo/cloud/study/ConfigServerEurekaApplication.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.cloud.config.server.EnableConfigServer; 7 | 8 | @SpringBootApplication 9 | @EnableConfigServer 10 | @EnableDiscoveryClient 11 | public class ConfigServerEurekaApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(ConfigServerEurekaApplication.class, args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-discovery-eureka/src/main/resources/application-ha.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | profiles: 3 | active: peer1 4 | --- 5 | spring: 6 | profiles: peer1 # 指定profile=peer1 7 | server: 8 | port: 8761 9 | eureka: 10 | instance: 11 | hostname: peer1 # 指定当profile=peer1时,主机名 12 | preferIpAddress: true 13 | client: 14 | serviceUrl: 15 | defaultZone: http://localhost:8762/eureka/ # 将自己注册到peer2这个Eureka上面去 16 | --- 17 | spring: 18 | profiles: peer2 19 | server: 20 | port: 8762 21 | eureka: 22 | instance: 23 | hostname: peer2 24 | preferIpAddress: true 25 | client: 26 | serviceUrl: 27 | defaultZone: http://localhost:8761/eureka/ -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-sentinel/README.md: -------------------------------------------------------------------------------- 1 | # microservice-alibaba-sentinel 2 | 3 | 【项目中快速集成·限流组件Sentinel】技术点 4 | 5 | 功能介绍 6 | 7 | 1. 项目中快速集成·限流组件Sentinel 8 | 9 | ## 本项目教程 10 | 11 | [项目中快速集成·限流组件Sentinel](https://hemin.blog.csdn.net/article/details/105517973) 12 | 13 | ## 该系列教程 14 | 15 | [SpringCloud Alibaba从入门到精通教程](https://blog.csdn.net/hemin1003/article/details/82043611) 16 | 17 | ## 个人说明 18 | 19 | 期望和大家”一起学习,一起成长“,共勉,O(∩_∩)O谢谢 20 | 21 | 不讲虚的,只做实干家 22 | 23 | Talk is cheap,show me the code 24 | 25 |
26 | 27 | 28 | ## [关于我](http://heminit.com/about/) 29 | 30 | 欢迎交流问题,可加我的个人QQ 469580884,或Q群号 751925591,一起探讨交流问题 31 | 32 | [我的博客地址](http://blog.csdn.net/hemin1003) 33 | 34 | [个人域名](http://heminit.com) -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-nacos-config/src/main/resources/bootstrap.yaml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: microservice-alibaba-nacos-config 4 | profiles: 5 | active: dev 6 | cloud: 7 | nacos: 8 | discovery: 9 | server-addr: 127.0.0.1:8848 10 | namespace: 2bc5565f-453f-4b1c-bde4-eafe23bdb2f0 11 | config: 12 | server-addr: 127.0.0.1:8848 13 | namespace: 2bc5565f-453f-4b1c-bde4-eafe23bdb2f0 14 | file-extension: properties 15 | shared-dataids: microservice-alibaba-nacos-config.properties 16 | refreshable-dataids: microservice-alibaba-nacos-config.properties 17 | # server 18 | server: 19 | port: 9091 -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-config-client-eureka/src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: microservice-config-client-eureka 4 | cloud: 5 | config: 6 | profile: dev 7 | label: master 8 | discovery: 9 | enabled: true # 默认false,设为true表示使用注册中心中的configserver配置而不自己配置configserver的uri 10 | serviceId: microservice-config-server-eureka # 指定config server在服务发现中的serviceId,默认为:configserver 11 | eureka: 12 | client: 13 | serviceUrl: 14 | defaultZone: http://localhost:8761/eureka/ 15 | 16 | # 参考文档:https://github.com/spring-cloud/spring-cloud-config/blob/master/docs/src/main/asciidoc/spring-cloud-config.adoc#discovery-first-bootstrap -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-sentinel/src/main/java/com/minbo/cloud/alibaba/Application.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.alibaba; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI; 8 | 9 | /** 10 | * 程序主入口 11 | * 12 | * @author Minbo 13 | * 14 | */ 15 | @SpringBootApplication 16 | @EnableSwaggerBootstrapUI 17 | @EnableDiscoveryClient 18 | public class Application { 19 | 20 | public static void main(String[] args) { 21 | SpringApplication.run(Application.class, args); 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-nacos-config/README.md: -------------------------------------------------------------------------------- 1 | # microservice-alibaba-nacos-config 2 | 3 | 【项目中快速集成配置中心Nacos-配置中心管理功能】技术点 4 | 5 | 功能介绍 6 | 7 | 1. 项目中快速集成配置中心Nacos-配置中心管理功能 8 | 9 | ## 本项目教程 10 | 11 | [项目中快速集成配置中心Nacos-配置中心管理功能](https://hemin.blog.csdn.net/article/details/105517950) 12 | 13 | ## 该系列教程 14 | 15 | [SpringCloud Alibaba从入门到精通教程](https://blog.csdn.net/hemin1003/article/details/82043611) 16 | 17 | ## 个人说明 18 | 19 | 期望和大家”一起学习,一起成长“,共勉,O(∩_∩)O谢谢 20 | 21 | 不讲虚的,只做实干家 22 | 23 | Talk is cheap,show me the code 24 | 25 |
26 | 27 | 28 | ## [关于我](http://heminit.com/about/) 29 | 30 | 欢迎交流问题,可加我的个人QQ 469580884,或Q群号 751925591,一起探讨交流问题 31 | 32 | [我的博客地址](http://blog.csdn.net/hemin1003) 33 | 34 | [个人域名](http://heminit.com) -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-nacos-config/src/main/java/com/minbo/cloud/alibaba/Application.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.alibaba; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI; 8 | 9 | /** 10 | * 程序主入口 11 | * 12 | * @author Minbo 13 | * 14 | */ 15 | @SpringBootApplication 16 | @EnableSwaggerBootstrapUI 17 | @EnableDiscoveryClient 18 | public class Application { 19 | 20 | public static void main(String[] args) { 21 | SpringApplication.run(Application.class, args); 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-nacos-discovery/README.md: -------------------------------------------------------------------------------- 1 | # microservice-alibaba-nacos-discovery 2 | 3 | 【项目中快速集成配置中心Nacos-服务注册发现功能】技术点 4 | 5 | 功能介绍 6 | 7 | 1. 项目中快速集成配置中心Nacos-服务注册发现功能 8 | 9 | ## 本项目教程 10 | 11 | [项目中快速集成配置中心Nacos-服务注册发现功能](https://hemin.blog.csdn.net/article/details/105517927) 12 | 13 | ## 该系列教程 14 | 15 | [SpringCloud Alibaba从入门到精通教程](https://blog.csdn.net/hemin1003/article/details/82043611) 16 | 17 | ## 个人说明 18 | 19 | 期望和大家”一起学习,一起成长“,共勉,O(∩_∩)O谢谢 20 | 21 | 不讲虚的,只做实干家 22 | 23 | Talk is cheap,show me the code 24 | 25 |
26 | 27 | 28 | ## [关于我](http://heminit.com/about/) 29 | 30 | 欢迎交流问题,可加我的个人QQ 469580884,或Q群号 751925591,一起探讨交流问题 31 | 32 | [我的博客地址](http://blog.csdn.net/hemin1003) 33 | 34 | [个人域名](http://heminit.com) -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-nacos-discovery/src/main/java/com/minbo/cloud/alibaba/Application.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.alibaba; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | 7 | import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI; 8 | 9 | /** 10 | * 程序主入口 11 | * 12 | * @author Minbo 13 | * 14 | */ 15 | @SpringBootApplication 16 | @EnableSwaggerBootstrapUI 17 | @EnableDiscoveryClient 18 | public class Application { 19 | 20 | public static void main(String[] args) { 21 | SpringApplication.run(Application.class, args); 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-movie-ribbon/src/main/java/com/minbo/cloud/study/controller/RibbonController.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RequestParam; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | import com.minbo.cloud.study.service.RibbonService; 9 | 10 | @RestController 11 | public class RibbonController { 12 | 13 | @Autowired 14 | private RibbonService ribbonService; 15 | 16 | @GetMapping(value = "/hi") 17 | public String hi(@RequestParam String name) { 18 | return this.ribbonService.hiService(name); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-sentinel/src/main/java/com/minbo/cloud/alibaba/util/ResultCode.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.alibaba.util; 2 | 3 | public enum ResultCode { 4 | 5 | /** 成功 */ 6 | SUCCESS("200", "成功"), 7 | 8 | /** 数据为空 */ 9 | SUCCESS_NO_DATA("201", "数据为空"), 10 | 11 | /** 用户不存在 */ 12 | SUCCESS_NO_USER("202", "用户不存在"), 13 | 14 | /** 今天的量已经跑光了 */ 15 | SUCCESS_ALL_GONE("203", "今天的量已经跑光了"), 16 | 17 | /** 失败,请重试 */ 18 | SUCCESS_FAIL("204", "失败,请重试"); 19 | 20 | private ResultCode(String val, String msg) { 21 | this.val = val; 22 | this.msg = msg; 23 | } 24 | 25 | public String val() { 26 | return val; 27 | } 28 | 29 | public String msg() { 30 | return msg; 31 | } 32 | 33 | private String val; 34 | private String msg; 35 | 36 | } 37 | -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-nacos-config/src/main/java/com/minbo/cloud/alibaba/util/ResultCode.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.alibaba.util; 2 | 3 | public enum ResultCode { 4 | 5 | /** 成功 */ 6 | SUCCESS("200", "成功"), 7 | 8 | /** 数据为空 */ 9 | SUCCESS_NO_DATA("201", "数据为空"), 10 | 11 | /** 用户不存在 */ 12 | SUCCESS_NO_USER("202", "用户不存在"), 13 | 14 | /** 今天的量已经跑光了 */ 15 | SUCCESS_ALL_GONE("203", "今天的量已经跑光了"), 16 | 17 | /** 失败,请重试 */ 18 | SUCCESS_FAIL("204", "失败,请重试"); 19 | 20 | private ResultCode(String val, String msg) { 21 | this.val = val; 22 | this.msg = msg; 23 | } 24 | 25 | public String val() { 26 | return val; 27 | } 28 | 29 | public String msg() { 30 | return msg; 31 | } 32 | 33 | private String val; 34 | private String msg; 35 | 36 | } 37 | -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-sentinel/src/main/java/com/minbo/cloud/alibaba/controller/InitController.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.alibaba.controller; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | import io.swagger.annotations.Api; 7 | import io.swagger.annotations.ApiOperation; 8 | import lombok.extern.slf4j.Slf4j; 9 | 10 | /** 11 | * @author Minbo 12 | */ 13 | @RestController 14 | @Slf4j 15 | @Api(tags = { "init" }) 16 | public class InitController { 17 | 18 | @ApiOperation(value = "欢迎入口", httpMethod = "GET") 19 | @GetMapping("/hello") 20 | public String hello() { 21 | log.info("microservice-alibaba-sentinel"); 22 | return "Hello, greetings from microservice-alibaba-sentinel"; 23 | } 24 | } -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-movie-feign/src/main/java/com/minbo/cloud/study/feign/MyFeignClient.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study.feign; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RequestMethod; 6 | import org.springframework.web.bind.annotation.RequestParam; 7 | 8 | /** 9 | * 使用@FeignClient("microservice-provider-user")注解绑定microservice-provider-user服务,还可以使用url参数指定一个URL。 10 | */ 11 | @FeignClient(name = "microservice-provider-user") 12 | public interface MyFeignClient { 13 | 14 | //定义代码调用对方服务的"/hi"接口 15 | @RequestMapping(value = "/hi", method = RequestMethod.GET) 16 | String sayHiFromClientOne(@RequestParam(value = "name") String name); 17 | 18 | } -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-provider-user/src/main/java/com/minbo/cloud/study/controller/HiController.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RequestParam; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | @RestController 9 | public class HiController { 10 | 11 | @Value("${server.port}") 12 | String port; 13 | 14 | // 提供的方法 15 | @RequestMapping("/hi") 16 | public String hi(@RequestParam(value = "name", defaultValue = "minbo") String name) { 17 | String result = "hi " + name + " , i am from port:" + port; 18 | System.out.println(result); 19 | return result; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-config-client-eureka/src/main/java/com/minbo/cloud/study/controller/ConfigClientController.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.cloud.context.config.annotation.RefreshScope; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * 这边的@RefreshScope注解不能少,否则即使调用/refresh,配置也不会刷新 10 | * 刷新接口:http://localhost:8051/actuator/refresh 11 | */ 12 | @RestController 13 | @RefreshScope 14 | public class ConfigClientController { 15 | 16 | @Value("${profile}") 17 | private String profile; 18 | 19 | @GetMapping("/hello") 20 | public String hello() { 21 | return this.profile; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-config-client/src/main/java/com/minbo/cloud/study/controller/ConfigClientController.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.cloud.context.config.annotation.RefreshScope; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * 这边的@RefreshScope注解不能少,否则即使调用/refresh,配置也不会刷新 10 | * 11 | * 刷新接口:http://localhost:8041/actuator/refresh 12 | */ 13 | @RestController 14 | @RefreshScope 15 | public class ConfigClientController { 16 | 17 | @Value("${profile}") 18 | private String profile; 19 | 20 | @GetMapping("/hello") 21 | public String hello() { 22 | return this.profile; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-movie-ribbon-with-hystrix/src/main/java/com/minbo/cloud/study/controller/RibbonHystrixController.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RequestParam; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | import com.minbo.cloud.study.service.RibbonHystrixService; 9 | 10 | @RestController 11 | public class RibbonHystrixController { 12 | 13 | @Autowired 14 | private RibbonHystrixService ribbonHystrixService; 15 | 16 | @GetMapping(value = "/hi") 17 | public String hi(@RequestParam String name) { 18 | return this.ribbonHystrixService.hiService(name); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-api-gateway/src/main/java/com/minbo/cloud/study/ZuulApiGatewayApplication.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 7 | import org.springframework.cloud.netflix.zuul.EnableZuulProxy; 8 | 9 | /** 10 | * 使用@EnableZuulProxy注解激活zuul。 11 | */ 12 | @SpringBootApplication 13 | @EnableZuulProxy 14 | @EnableEurekaClient 15 | @EnableDiscoveryClient 16 | public class ZuulApiGatewayApplication { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(ZuulApiGatewayApplication.class, args); 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-movie-feign-with-hystrix-stream/src/main/java/com/minbo/cloud/study/controller/FeignHystrixController.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RequestParam; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | import com.minbo.cloud.study.feign.MyFeignClient; 9 | 10 | @RestController 11 | public class FeignHystrixController { 12 | 13 | @Autowired 14 | private MyFeignClient feignClient; 15 | 16 | @GetMapping(value = "/hi") 17 | public String sayHi(@RequestParam String name) { 18 | String result = this.feignClient.sayHiFromClientOne(name); 19 | return result; 20 | } 21 | } -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-config-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | microservice-config-server 8 | jar 9 | 10 | 11 | com.minbo.cloud 12 | spring-cloud-microservice-study 13 | 0.0.1-SNAPSHOT 14 | 15 | 16 | 17 | 18 | org.springframework.cloud 19 | spring-cloud-config-server 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-sentinel/src/main/resources/bootstrap.yaml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: microservice-alibaba-sentinel 4 | profiles: 5 | active: dev 6 | cloud: 7 | nacos: 8 | discovery: 9 | server-addr: 127.0.0.1:8848 10 | namespace: 2bc5565f-453f-4b1c-bde4-eafe23bdb2f0 11 | config: 12 | server-addr: 127.0.0.1:8848 13 | namespace: 2bc5565f-453f-4b1c-bde4-eafe23bdb2f0 14 | file-extension: properties 15 | shared-dataids: microservice-alibaba-sentinel.properties 16 | refreshable-dataids: microservice-alibaba-sentinel.properties 17 | sentinel: 18 | transport: 19 | port: 8719 # 默认数据端口 20 | dashboard: 127.0.0.1:9191 21 | # server 22 | server: 23 | port: 9092 -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-discovery-eureka/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8761 # 指定该Eureka实例的端口 3 | eureka: 4 | instance: 5 | hostname: localhost # 指定该Eureka实例的主机名 6 | # 配置关闭自我保护,并按需配置Eureka Server清理无效节点的时间间隔 7 | server: 8 | enable-self-preservation: false 9 | eviction-interval-timer-in-ms: 4000 10 | # 通过eureka.client.registerWithEureka:false和fetchRegistry:false,来表明自己是一个eureka server 11 | client: 12 | registerWithEureka: false 13 | fetchRegistry: false 14 | serviceUrl: 15 | defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ 16 | 17 | # 参考文档:http://projects.spring.io/spring-cloud/docs/1.0.3/spring-cloud.html#_standalone_mode 18 | # 参考文档:http://my.oschina.net/buwei/blog/618756 19 | # 参考文档:https://blog.csdn.net/forezp/article/details/81040925 -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-discovery-eureka/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | microservice-discovery-eureka 8 | jar 9 | 10 | 11 | com.minbo.cloud 12 | spring-cloud-microservice-study 13 | 0.0.1-SNAPSHOT 14 | 15 | 16 | 17 | 18 | org.springframework.cloud 19 | spring-cloud-starter-netflix-eureka-server 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-movie-feign-with-hystrix/src/main/java/com/minbo/cloud/study/MovieFeignHystrixApplication.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 7 | import org.springframework.cloud.openfeign.EnableFeignClients; 8 | 9 | /** 10 | * 使用@EnableFeignClients开启Feign 11 | */ 12 | @SpringBootApplication 13 | @EnableEurekaClient 14 | @EnableDiscoveryClient 15 | @EnableFeignClients 16 | public class MovieFeignHystrixApplication { 17 | 18 | public static void main(String[] args) { 19 | SpringApplication.run(MovieFeignHystrixApplication.class, args); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-hystrix-dashboard/src/main/java/com/minbo/cloud/study/hystrixdashboard/HystrixDashboardApplication.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study.hystrixdashboard; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 5 | import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; 6 | 7 | /** 8 | * 测试步骤: 9 | * 1. 访问:http://localhost:8030/hystrix 可以查看Dashboard 10 | * 2. 在上面的输入框填入: http://想监控的服务:端口/hystrix.stream进行测试 11 | * 12 | * 注意:首先要先调用一下想监控的服务的API,否则将会显示一个空的图表. 13 | */ 14 | @SpringBootApplication 15 | @EnableHystrixDashboard 16 | public class HystrixDashboardApplication { 17 | public static void main(String[] args) { 18 | new SpringApplicationBuilder(HystrixDashboardApplication.class).run(args); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-movie-feign/src/main/java/com/minbo/cloud/study/feign/MyFeignClient2.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study.feign; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.web.bind.annotation.RequestMapping; 5 | import org.springframework.web.bind.annotation.RequestMethod; 6 | import org.springframework.web.bind.annotation.RequestParam; 7 | 8 | /** 9 | * 使用@FeignClient("microservice-consumer-movie-feign-with-hystrix")注解绑定microservice-consumer-movie-feign-with-hystrix服务,还可以使用url参数指定一个URL。 10 | */ 11 | @FeignClient(name = "microservice-consumer-movie-feign-with-hystrix") 12 | public interface MyFeignClient2 { 13 | 14 | // 定义代码调用对方服务的"/city"接口 15 | @RequestMapping(value = "/city", method = RequestMethod.GET) 16 | String fromCityFromClientOne(@RequestParam(value = "city") String city); 17 | 18 | } -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-hystrix-turbine/src/main/java/com/minbo/cloud/study/turbine/TurbineApplication.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study.turbine; 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication; 4 | import org.springframework.boot.builder.SpringApplicationBuilder; 5 | import org.springframework.cloud.netflix.turbine.EnableTurbine; 6 | 7 | /** 8 | * 在复杂的分布式系统中,相同服务的节点经常需要部署上百甚至上千个,很多时候,运维人员希望能够把相同服务的节点状态以一个整体集群的形式展现出来, 9 | * 这样可以更好的把握整个系统的状态。为此,Netflix提供了一个开源项目(Turbine)来提供把多个hystrix.stream的内容聚合为一个数据源供Dashboard展示。 10 | * 11 | * 通过@EnableTurbine接口,激活对Turbine的支持。 12 | * 13 | * 查看:http://localhost:8031/turbine.stream 14 | */ 15 | @SpringBootApplication 16 | @EnableTurbine 17 | public class TurbineApplication { 18 | public static void main(String[] args) { 19 | new SpringApplicationBuilder(TurbineApplication.class).run(args); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-nacos-discovery/src/main/java/com/minbo/cloud/alibaba/controller/InitController.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.alibaba.controller; 2 | 3 | import org.springframework.web.bind.annotation.GetMapping; 4 | import org.springframework.web.bind.annotation.RestController; 5 | 6 | import io.swagger.annotations.Api; 7 | import io.swagger.annotations.ApiOperation; 8 | import lombok.extern.slf4j.Slf4j; 9 | 10 | /** 11 | * @author Minbo 12 | */ 13 | @RestController 14 | @Slf4j 15 | @Api(tags = { "init" }) 16 | public class InitController { 17 | 18 | /** 19 | * http://localhost:9090/hello 20 | * 21 | * @return 22 | */ 23 | @ApiOperation(value = "欢迎入口", httpMethod = "GET") 24 | @GetMapping("/hello") 25 | public String hello() { 26 | log.info("microservice-alibaba-nacos-discovery"); 27 | return "Hello, greetings from microservice-alibaba-nacos-discovery"; 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /spring-cloud-hoxton/README.md: -------------------------------------------------------------------------------- 1 | # 项目简介 2 | 3 | 1. spring-cloud-hoxton(基于Hoxton版本,SpringBoot2.2.x版本实现) 4 | 5 | 待更新(规划中...) 6 | 7 | ## 其他 8 | 9 | 1. [SpringCloud从入门到精通教程](https://blog.csdn.net/hemin1003/article/details/82043611) 10 | 11 | 2. [SpringBoot从入门到精通教程](https://blog.csdn.net/hemin1003/article/details/82038244) 12 | 13 | 3. [SpringCloud Alibaba从入门到精通教程](https://blog.csdn.net/hemin1003/article/details/82043611) 14 | 15 | ## [关于我](http://heminit.com/about/) 16 | 17 | 欢迎交流问题,可加我的个人QQ 469580884,或群号 751925591,一起探讨交流问题 18 | 19 | 期望和大家 一起学习,一起成长,共勉,O(∩_∩)O谢谢 20 | 21 | [我的博客地址-博客专家](http://blog.csdn.net/hemin1003) 22 | 23 | [个人域名](http://heminit.com) 24 | 25 | ## 感谢 26 | 如果觉得内容赞,您可以请我喝一杯咖啡: 27 |
28 |      29 | 30 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-movie-feign-with-hystrix-stream/src/main/java/com/minbo/cloud/study/MovieFeignHystrixApplication.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 6 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 7 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 8 | import org.springframework.cloud.openfeign.EnableFeignClients; 9 | 10 | /** 11 | * 使用@EnableFeignClients开启Feign 12 | */ 13 | @SpringBootApplication 14 | @EnableEurekaClient 15 | @EnableDiscoveryClient 16 | @EnableFeignClients 17 | @EnableCircuitBreaker 18 | public class MovieFeignHystrixApplication { 19 | 20 | public static void main(String[] args) { 21 | SpringApplication.run(MovieFeignHystrixApplication.class, args); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-hystrix-turbine/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | microservice-hystrix-turbine 8 | jar 9 | 10 | 11 | com.minbo.cloud 12 | spring-cloud-microservice-study 13 | 0.0.1-SNAPSHOT 14 | 15 | 16 | 17 | 18 | org.springframework.cloud 19 | spring-cloud-starter-netflix-turbine 20 | 21 | 22 | org.springframework.boot 23 | spring-boot-starter-actuator 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-hystrix-dashboard/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | microservice-hystrix-dashboard 8 | jar 9 | 10 | 11 | com.minbo.cloud 12 | spring-cloud-microservice-study 13 | 0.0.1-SNAPSHOT 14 | 15 | 16 | 17 | 18 | org.springframework.cloud 19 | spring-cloud-starter-netflix-hystrix-dashboard 20 | 21 | 22 | org.springframework.boot 23 | spring-boot-starter-actuator 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-nacos-discovery/src/main/resources/bootstrap.yaml.bak: -------------------------------------------------------------------------------- 1 | # 不同的环境使用不同的配置,通过指定启动参数使用不同的profile,比如: 2 | # 开发环境:java -jar xxx.jar --spring.profiles.active=dev 3 | # 生产环境:java -jar xxx.jar --spring.profiles.active=prod 4 | spring: 5 | application: 6 | name: microservice-alibaba-nacos-discovery 7 | profiles: 8 | active: test 9 | # server 10 | server: 11 | port: 9090 12 | 13 | #下面这一行务必不能少,区分不同环境配置,而且必须是三个字符"-" 14 | --- 15 | spring: 16 | profiles: dev 17 | cloud: 18 | nacos: 19 | discovery: 20 | server-addr: 127.0.0.1:8848 21 | namespace: 2bc5565f-453f-4b1c-bde4-eafe23bdb2f0 22 | --- 23 | spring: 24 | profiles: test 25 | cloud: 26 | nacos: 27 | discovery: 28 | server-addr: 127.0.0.1:8848 29 | namespace: 47247e4c-b018-4c63-92cd-ebbc119eef7f 30 | --- 31 | spring: 32 | profiles: prod 33 | cloud: 34 | nacos: 35 | discovery: 36 | server-addr: 127.0.0.1:8848 37 | namespace: 9d3bb62a-14c5-43aa-ac05-6576caa5be2b -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-movie-feign/src/main/java/com/minbo/cloud/study/controller/FeignController.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RequestParam; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | import com.minbo.cloud.study.feign.MyFeignClient; 9 | import com.minbo.cloud.study.feign.MyFeignClient2; 10 | 11 | @RestController 12 | public class FeignController { 13 | 14 | @Autowired 15 | private MyFeignClient feignClient; 16 | 17 | @Autowired 18 | private MyFeignClient2 feignClient2; 19 | 20 | @GetMapping(value = "/hi") 21 | public String sayHi(@RequestParam String name) { 22 | String result = this.feignClient.sayHiFromClientOne(name); 23 | return result; 24 | } 25 | 26 | @GetMapping(value = "/city") 27 | public String city(@RequestParam String city) { 28 | String result = this.feignClient2.fromCityFromClientOne(city); 29 | return result; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-zipkin-hi/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | microservice-consumer-zipkin-hi 8 | jar 9 | 10 | 11 | com.minbo.cloud 12 | spring-cloud-microservice-study 13 | 0.0.1-SNAPSHOT 14 | 15 | 16 | 17 | 18 | org.springframework.boot 19 | spring-boot-starter-web 20 | 21 | 22 | 23 | org.springframework.cloud 24 | spring-cloud-starter-zipkin 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-actuator 30 | 31 | 32 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-zipkin-greet/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | microservice-consumer-zipkin-greet 8 | jar 9 | 10 | 11 | com.minbo.cloud 12 | spring-cloud-microservice-study 13 | 0.0.1-SNAPSHOT 14 | 15 | 16 | 17 | 18 | org.springframework.boot 19 | spring-boot-starter-web 20 | 21 | 22 | 23 | org.springframework.cloud 24 | spring-cloud-starter-zipkin 25 | 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-actuator 30 | 31 | 32 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-movie-feign/src/main/java/com/minbo/cloud/study/MovieFeignApplication.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 7 | import org.springframework.cloud.openfeign.EnableFeignClients; 8 | 9 | /** 10 | * Feign是一个声明式的web service客户端,它使得编写web service客户端更为容易。 11 | * 创建接口,为接口添加注解,即可使用Feign。 12 | * Feign可以使用Feign注解或者JAX-RS注解,还支持热插拔的编码器和解码器。 13 | * Spring Cloud为Feign添加了Spring MVC的注解支持,并整合了Ribbon和Eureka来为使用Feign时提供负载均衡。 14 | * 使用@EnableFeignClients开启Feign 15 | * 16 | * 简而言之: 17 | * a. Feign 采用的是基于接口的注解 18 | * b. Feign 整合了ribbon,具有负载均衡的能力 19 | * c. 整合了Hystrix,具有熔断的能力 20 | */ 21 | @SpringBootApplication 22 | @EnableEurekaClient 23 | @EnableDiscoveryClient 24 | @EnableFeignClients 25 | public class MovieFeignApplication { 26 | 27 | public static void main(String[] args) { 28 | SpringApplication.run(MovieFeignApplication.class, args); 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-config-server-eureka/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | microservice-config-server-eureka 8 | jar 9 | 10 | 11 | com.minbo.cloud 12 | spring-cloud-microservice-study 13 | 0.0.1-SNAPSHOT 14 | 15 | 16 | 17 | 18 | org.springframework.cloud 19 | spring-cloud-config-server 20 | 21 | 22 | org.springframework.cloud 23 | spring-cloud-starter-netflix-eureka-client 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-web 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-config-server/src/main/java/com/minbo/cloud/study/ConfigServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.config.server.EnableConfigServer; 6 | 7 | /** 8 | * 通过@EnableConfigServer注解激活配置服务. 说明: 9 | * 在application.yml中有个git.uri的配置,目前配置的是https://github.com/eacdy/spring-cloud-study/ 10 | * 获取git上的资源信息遵循如下规则: 11 | * /{application}/{profile}[/{label}] 12 | * /{application}-{profile}.yml 13 | * /{label}/{application}-{profile}.yml 14 | * /{application}-{profile}.properties 15 | * /{label}/{application}-{profile}.properties 16 | * 17 | * 例如本例:可使用以下路径来访问microservice-config-client-dev.properties: 18 | * http://localhost:8040/microservice-config-client-dev.properties 19 | * http://localhost:8040/microservice-config-client/dev ... 20 | */ 21 | @SpringBootApplication 22 | @EnableConfigServer 23 | public class ConfigServerApplication { 24 | public static void main(String[] args) { 25 | SpringApplication.run(ConfigServerApplication.class, args); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-movie-ribbon-with-hystrix/src/main/java/com/minbo/cloud/study/service/RibbonHystrixService.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study.service; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.stereotype.Service; 5 | import org.springframework.web.client.RestTemplate; 6 | 7 | import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; 8 | 9 | @Service 10 | public class RibbonHystrixService { 11 | 12 | @Autowired 13 | private RestTemplate restTemplate; 14 | 15 | /** 16 | * 使用@HystrixCommand注解指定当该方法发生异常时调用的方法 17 | * 18 | */ 19 | @HystrixCommand(fallbackMethod = "fallback") 20 | public String hiService(String name) { 21 | String result = restTemplate.getForObject("http://microservice-provider-user/hi?name=" + name, String.class); 22 | System.out.println(result); 23 | return result; 24 | } 25 | 26 | /** 27 | * hystrix fallback方法 28 | * 29 | * @return 默认返回数据 30 | */ 31 | public String fallback(String name) { 32 | String result = "异常发生,进入fallback方法,接收的参数:name = " + name; 33 | System.out.println(result); 34 | return result; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-config-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | microservice-config-client 7 | jar 8 | 9 | 10 | com.minbo.cloud 11 | spring-cloud-microservice-study 12 | 0.0.1-SNAPSHOT 13 | 14 | 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter-web 19 | 20 | 21 | 22 | org.springframework.cloud 23 | spring-cloud-starter-config 24 | 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-actuator 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-zipkin-hi/src/main/java/com/minbo/cloud/study/controller/HiRestController.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | import org.springframework.web.client.RestTemplate; 8 | 9 | import brave.sampler.Sampler; 10 | 11 | @RestController 12 | public class HiRestController { 13 | 14 | @Autowired 15 | private RestTemplate restTemplate; 16 | 17 | @Bean 18 | public RestTemplate getRestTemplate() { 19 | return new RestTemplate(); 20 | } 21 | 22 | @RequestMapping("/hi") 23 | public String call() { 24 | System.out.println("calling trace zipkin-hi"); 25 | return this.restTemplate.getForObject("http://localhost:8989/info", String.class); 26 | } 27 | 28 | @RequestMapping("/info") 29 | public String info() { 30 | System.out.println("calling trace zipkin-hi"); 31 | return "i'm zipkin-hi"; 32 | } 33 | 34 | @Bean 35 | public Sampler defaultSampler() { 36 | return Sampler.ALWAYS_SAMPLE; 37 | } 38 | } -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-zipkin-greet/src/main/java/com/minbo/cloud/study/controller/GreetRestController.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.context.annotation.Bean; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | import org.springframework.web.client.RestTemplate; 8 | 9 | import brave.sampler.Sampler; 10 | 11 | @RestController 12 | public class GreetRestController { 13 | 14 | @Autowired 15 | private RestTemplate restTemplate; 16 | 17 | @Bean 18 | public RestTemplate getRestTemplate() { 19 | return new RestTemplate(); 20 | } 21 | 22 | @RequestMapping("/greet") 23 | public String call() { 24 | System.out.println("calling trace zipkin-greet"); 25 | return this.restTemplate.getForObject("http://localhost:8988/info", String.class); 26 | } 27 | 28 | @RequestMapping("/info") 29 | public String info() { 30 | System.out.println("calling trace zipkin-greet"); 31 | return "i'm zipkin-greet"; 32 | } 33 | 34 | @Bean 35 | public Sampler defaultSampler() { 36 | return Sampler.ALWAYS_SAMPLE; 37 | } 38 | } -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-movie-feign-with-hystrix/src/main/java/com/minbo/cloud/study/controller/FeignHystrixController.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.beans.factory.annotation.Value; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestParam; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import com.minbo.cloud.study.feign.MyFeignHystrixClient; 11 | 12 | @RestController 13 | public class FeignHystrixController { 14 | 15 | @Autowired 16 | private MyFeignHystrixClient feignClient; 17 | 18 | @GetMapping(value = "/hi") 19 | public String sayHi(@RequestParam String name) { 20 | String result = this.feignClient.sayHiFromClientOne(name); 21 | return result; 22 | } 23 | 24 | @Value("${server.port}") 25 | String port; 26 | 27 | @RequestMapping("/city") 28 | public String home(@RequestParam(value = "city", defaultValue = "guangzhou") String city) { 29 | String result = "hi " + city + " , i am from port:" + port; 30 | System.out.println(result); 31 | return result; 32 | } 33 | } -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-config-client-eureka/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | microservice-config-client-eureka 8 | jar 9 | 10 | 11 | com.minbo.cloud 12 | spring-cloud-microservice-study 13 | 0.0.1-SNAPSHOT 14 | 15 | 16 | 17 | 18 | org.springframework.cloud 19 | spring-cloud-starter-config 20 | 21 | 22 | org.springframework.cloud 23 | spring-cloud-starter-netflix-eureka-client 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-web 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-actuator 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-provider-user/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | microservice-provider-user 8 | jar 9 | 10 | 11 | com.minbo.cloud 12 | spring-cloud-microservice-study 13 | 0.0.1-SNAPSHOT 14 | 15 | 16 | 17 | 18 | 19 | org.springframework.cloud 20 | spring-cloud-starter-netflix-eureka-client 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter-web 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-actuator 29 | 30 | 31 | org.springframework.cloud 32 | spring-cloud-starter-zipkin 33 | 34 | 35 | -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-nacos-config/src/main/java/com/minbo/cloud/alibaba/controller/InitController.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.alibaba.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Value; 4 | import org.springframework.cloud.context.config.annotation.RefreshScope; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | import com.minbo.cloud.alibaba.util.JsonResult; 9 | import com.minbo.cloud.alibaba.util.ResultCode; 10 | 11 | import io.swagger.annotations.Api; 12 | import io.swagger.annotations.ApiOperation; 13 | import lombok.extern.slf4j.Slf4j; 14 | 15 | /** 16 | * @author Minbo 17 | */ 18 | @RestController 19 | @Slf4j 20 | @Api(tags = { "init" }) 21 | @RefreshScope 22 | public class InitController { 23 | 24 | @Value("${config.appKey}") 25 | private String appKey; 26 | 27 | @ApiOperation(value = "欢迎入口", httpMethod = "GET") 28 | @GetMapping("/hello") 29 | public String hello() { 30 | log.info("microservice-alibaba-nacos-config"); 31 | return "Hello, greetings from microservice-alibaba-nacos-config"; 32 | } 33 | 34 | @ApiOperation(value = "获得AppKey值", httpMethod = "GET") 35 | @GetMapping("/getAppKey") 36 | public JsonResult getAppKey() { 37 | return new JsonResult(ResultCode.SUCCESS, this.appKey); 38 | } 39 | } -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-movie-ribbon/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | microservice-consumer-movie-ribbon 8 | jar 9 | 10 | 11 | com.minbo.cloud 12 | spring-cloud-microservice-study 13 | 0.0.1-SNAPSHOT 14 | 15 | 16 | 17 | 18 | org.springframework.cloud 19 | spring-cloud-starter-netflix-eureka-client 20 | 21 | 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-starter-netflix-ribbon 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-actuator 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-movie-feign-with-hystrix-stream/src/main/java/com/minbo/cloud/study/feign/MyFeignClient.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study.feign; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.stereotype.Component; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RequestMethod; 7 | import org.springframework.web.bind.annotation.RequestParam; 8 | 9 | import com.minbo.cloud.study.feign.MyFeignClient.HystrixClientFallback; 10 | 11 | /** 12 | * 使用@FeignClient("microservice-provider-user")注解绑定microservice-provider-user服务,还可以使用url参数指定一个URL。 13 | */ 14 | @FeignClient(name = "microservice-provider-user", fallback = HystrixClientFallback.class) 15 | public interface MyFeignClient { 16 | 17 | // 定义代码调用对方服务的"/hi"接口 18 | @RequestMapping(value = "/hi", method = RequestMethod.GET) 19 | String sayHiFromClientOne(@RequestParam(value = "name") String name); 20 | 21 | /** 22 | * 这边采取了和Spring Cloud官方文档相同的做法,将fallback类作为内部类放入Feign的接口中,当然也可以单独写一个fallback类。 23 | */ 24 | @Component 25 | class HystrixClientFallback implements MyFeignClient { 26 | 27 | @Override 28 | public String sayHiFromClientOne(String name) { 29 | String result = "from feign,异常发生,进入fallback方法,接收的参数:name = " + name; 30 | System.out.println(result); 31 | return result; 32 | } 33 | 34 | } 35 | } -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-api-gateway/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: microservice-api-gateway 4 | server: 5 | port: 8050 6 | eureka: 7 | #instance: 8 | # hostname: gateway 9 | instance: 10 | preferIpAddress: true 11 | client: 12 | serviceUrl: 13 | defaultZone: http://localhost:8761/eureka/ 14 | zuul: 15 | # 表示启用限流策略,并且所有服务在3秒内只能有1次请求且所有请求时间总和不得超过2秒 16 | ratelimit: 17 | enabled: true 18 | default-policy: 19 | limit: 1 20 | quota: 2 21 | refresh-interval: 3 22 | ignored-services: microservice-provider-user # 需要忽视的服务(配置后将不会被路由) 23 | routes: 24 | #movie: # 可以随便写,在zuul上面唯一即可;当这里的值=service-id时,service-id可以不写。 25 | #path: /movie/** # 想要映射到的路径 26 | #service-id: microservice-consumer-movie-ribbon-with-hystrix # Eureka中的serviceId 27 | api-a: 28 | path: /api-a/** 29 | serviceId: microservice-consumer-movie-ribbon-with-hystrix 30 | api-b: 31 | path: /api-b/** 32 | serviceId: microservice-consumer-movie-feign-with-hystrix 33 | api-c: 34 | path: /api-c/** 35 | serviceId: microservice-consumer-movie-ribbon 36 | api-d: 37 | path: /api-d/** 38 | serviceId: microservice-consumer-movie-feign 39 | management: 40 | endpoints: 41 | web: 42 | exposure: 43 | include: '*' -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-movie-feign-with-hystrix/src/main/java/com/minbo/cloud/study/feign/MyFeignHystrixClient.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study.feign; 2 | 3 | import org.springframework.cloud.openfeign.FeignClient; 4 | import org.springframework.stereotype.Component; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RequestMethod; 7 | import org.springframework.web.bind.annotation.RequestParam; 8 | 9 | import com.minbo.cloud.study.feign.MyFeignHystrixClient.HystrixClientFallback; 10 | 11 | /** 12 | * 使用@FeignClient("microservice-provider-user")注解绑定microservice-provider-user服务,还可以使用url参数指定一个URL。 13 | */ 14 | @FeignClient(name = "microservice-provider-user", fallback = HystrixClientFallback.class) 15 | public interface MyFeignHystrixClient { 16 | 17 | // 定义代码调用对方服务的"/hi"接口 18 | @RequestMapping(value = "/hi", method = RequestMethod.GET) 19 | String sayHiFromClientOne(@RequestParam(value = "name") String name); 20 | 21 | /** 22 | * 这边采取了和Spring Cloud官方文档相同的做法,将fallback类作为内部类放入Feign的接口中,当然也可以单独写一个fallback类。 23 | */ 24 | @Component 25 | class HystrixClientFallback implements MyFeignHystrixClient { 26 | 27 | @Override 28 | public String sayHiFromClientOne(String name) { 29 | String result = "from feign,异常发生,进入fallback方法,接收的参数:name = " + name; 30 | System.out.println(result); 31 | return result; 32 | } 33 | 34 | } 35 | } -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-sentinel/src/main/java/com/minbo/cloud/alibaba/util/JsonResult.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.alibaba.util; 2 | 3 | import net.sf.json.JSONObject; 4 | 5 | public class JsonResult { 6 | private String code; 7 | private String message; 8 | private Object data; 9 | 10 | public JsonResult() { 11 | this.setCode(ResultCode.SUCCESS); 12 | this.setMessage(ResultCode.SUCCESS.msg()); 13 | } 14 | 15 | public JsonResult(ResultCode code) { 16 | this.setCode(code); 17 | this.setMessage(code.msg()); 18 | } 19 | 20 | public JsonResult(ResultCode code, String data) { 21 | this.setCode(code); 22 | this.setMessage(code.msg()); 23 | this.setData(data); 24 | } 25 | 26 | public JsonResult(ResultCode code, Object data) { 27 | this.setCode(code); 28 | this.setMessage(code.msg()); 29 | this.setData(data); 30 | } 31 | 32 | public String getCode() { 33 | return code; 34 | } 35 | 36 | public void setCode(ResultCode code) { 37 | this.code = code.val(); 38 | } 39 | 40 | public String getMessage() { 41 | return message; 42 | } 43 | 44 | public void setMessage(String message) { 45 | this.message = message; 46 | } 47 | 48 | public Object getData() { 49 | return data; 50 | } 51 | 52 | public void setData(Object data) { 53 | this.data = data; 54 | } 55 | 56 | public String toJsonString() { 57 | JSONObject json = JSONObject.fromObject(this); 58 | return json.toString(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-nacos-config/src/main/java/com/minbo/cloud/alibaba/util/JsonResult.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.alibaba.util; 2 | 3 | import net.sf.json.JSONObject; 4 | 5 | public class JsonResult { 6 | private String code; 7 | private String message; 8 | private Object data; 9 | 10 | public JsonResult() { 11 | this.setCode(ResultCode.SUCCESS); 12 | this.setMessage(ResultCode.SUCCESS.msg()); 13 | } 14 | 15 | public JsonResult(ResultCode code) { 16 | this.setCode(code); 17 | this.setMessage(code.msg()); 18 | } 19 | 20 | public JsonResult(ResultCode code, String data) { 21 | this.setCode(code); 22 | this.setMessage(code.msg()); 23 | this.setData(data); 24 | } 25 | 26 | public JsonResult(ResultCode code, Object data) { 27 | this.setCode(code); 28 | this.setMessage(code.msg()); 29 | this.setData(data); 30 | } 31 | 32 | public String getCode() { 33 | return code; 34 | } 35 | 36 | public void setCode(ResultCode code) { 37 | this.code = code.val(); 38 | } 39 | 40 | public String getMessage() { 41 | return message; 42 | } 43 | 44 | public void setMessage(String message) { 45 | this.message = message; 46 | } 47 | 48 | public Object getData() { 49 | return data; 50 | } 51 | 52 | public void setData(Object data) { 53 | this.data = data; 54 | } 55 | 56 | public String toJsonString() { 57 | JSONObject json = JSONObject.fromObject(this); 58 | return json.toString(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-movie-feign/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | microservice-consumer-movie-feign 8 | jar 9 | 10 | 11 | com.minbo.cloud 12 | spring-cloud-microservice-study 13 | 0.0.1-SNAPSHOT 14 | 15 | 16 | 17 | 18 | org.springframework.cloud 19 | spring-cloud-starter-netflix-eureka-client 20 | 21 | 22 | org.springframework.cloud 23 | spring-cloud-starter-openfeign 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-web 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-actuator 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-zipkin 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-hystrix-turbine/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application.name: microservice-hystrix-turbine 3 | server: 4 | port: 8031 5 | security.basic.enabled: false 6 | turbine: 7 | aggregator: 8 | clusterConfig: default # 指定聚合哪些集群,多个使用","分割,默认为default。可使用http://.../turbine.stream?cluster={clusterConfig之一}访问 9 | appConfig: microservice-api-gateway, microservice-consumer-movie-ribbon-with-hystrix, microservice-consumer-movie-feign-with-hystrix-stream ### 配置Eureka中的serviceId列表,表明监控哪些服务 10 | clusterNameExpression: new String("default") 11 | combine-host: true 12 | # 1. clusterNameExpression指定集群名称,默认表达式appName;此时:turbine.aggregator.clusterConfig需要配置想要监控的应用名称 13 | # 2. 当clusterNameExpression: default时,turbine.aggregator.clusterConfig可以不写,因为默认就是default 14 | # 3. 当clusterNameExpression: metadata['cluster']时,假设想要监控的应用配置了eureka.instance.metadata-map.cluster: ABC,则需要配置,同时turbine.aggregator.clusterConfig: ABC 15 | instanceUrlSuffix: 16 | default: actuator/hystrix.stream 17 | eureka: 18 | client: 19 | serviceUrl: 20 | defaultZone: http://localhost:8761/eureka/ 21 | management: 22 | endpoints: 23 | web: 24 | exposure: 25 | include: '*' 26 | cors: 27 | allowed-origins: '*' 28 | allowed-methods: '*' 29 | 30 | # 参考:http://blog.csdn.net/liaokailin/article/details/51344281 31 | # 参考:http://blog.csdn.net/zhuchuangang/article/details/51289593 -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-movie-feign-with-hystrix/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | microservice-consumer-movie-feign-with-hystrix 8 | jar 9 | 10 | 11 | com.minbo.cloud 12 | spring-cloud-microservice-study 13 | 0.0.1-SNAPSHOT 14 | 15 | 16 | 17 | 18 | org.springframework.cloud 19 | spring-cloud-starter-netflix-eureka-client 20 | 21 | 22 | org.springframework.cloud 23 | spring-cloud-starter-openfeign 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-web 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-actuator 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-zipkin 36 | 37 | 38 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-api-gateway/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 4.0.0 7 | 8 | microservice-api-gateway 9 | jar 10 | 11 | 12 | com.minbo.cloud 13 | spring-cloud-microservice-study 14 | 0.0.1-SNAPSHOT 15 | 16 | 17 | 18 | 19 | org.springframework.cloud 20 | spring-cloud-starter-netflix-zuul 21 | 22 | 23 | org.springframework.cloud 24 | spring-cloud-starter-netflix-eureka-client 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-web 29 | 30 | 31 | org.springframework.cloud 32 | spring-cloud-starter-zipkin 33 | 34 | 35 | com.marcosbarbero.cloud 36 | spring-cloud-zuul-ratelimit 37 | 2.0.4.RELEASE 38 | 39 | 40 | -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-sentinel/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | %d [%t] [%c] [%p] (%file:%line\)- %m%n 9 | UTF-8 10 | 11 | 12 | 13 | 15 | log/run.log 16 | 18 | log/run.log.%d.%i 19 | 21 | 22 | 64 MB 23 | 24 | 25 | 7 26 | true 27 | 28 | 29 | 30 | %d [%t] [%c] [%p] (%file:%line\)- %m%n 31 | 32 | UTF-8 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-nacos-config/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | %d [%t] [%c] [%p] (%file:%line\)- %m%n 9 | UTF-8 10 | 11 | 12 | 13 | 15 | log/run.log 16 | 18 | log/run.log.%d.%i 19 | 21 | 22 | 64 MB 23 | 24 | 25 | 7 26 | true 27 | 28 | 29 | 30 | %d [%t] [%c] [%p] (%file:%line\)- %m%n 31 | 32 | UTF-8 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-nacos-discovery/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | %d [%t] [%c] [%p] (%file:%line\)- %m%n 9 | UTF-8 10 | 11 | 12 | 13 | 15 | log/run.log 16 | 18 | log/run.log.%d.%i 19 | 21 | 22 | 64 MB 23 | 24 | 25 | 7 26 | true 27 | 28 | 29 | 30 | %d [%t] [%c] [%p] (%file:%line\)- %m%n 31 | 32 | UTF-8 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-movie-ribbon/src/main/java/com/minbo/cloud/study/MovieRibbonApplication.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 7 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 8 | import org.springframework.context.annotation.Bean; 9 | import org.springframework.web.client.RestTemplate; 10 | 11 | /** 12 | * Ribbon是Netflix发布的开源项目,主要功能是提供客户端的软件负载均衡算法,将Netflix的中间层服务连接在一起。 13 | * Ribbon客户端组件提供一系列完善的配置项如连接超时,重试等。 14 | * 简单的说,就是在配置文件中列出Load Balancer后面所有的机器,Ribbon会自动的帮助你基于某种规则(如简单轮询,随机连接等)去连接这些机器。 15 | * 我们也很容易使用Ribbon实现自定义的负载均衡算法。简单地说,Ribbon是一个客户端负载均衡器。 16 | * 17 | * Ribbon工作时分为两步: 18 | * 第一步先选择 Eureka Server,它优先选择在同一个Zone且负载较少的Server; 19 | * 第二步再根据用户指定的策略,在从Server取到的服务注册列表中选择一个地址。 20 | * 21 | * 其中Ribbon提供了多种策略,例如轮询、随机、根据响应时间加权等。 22 | */ 23 | @SpringBootApplication 24 | @EnableEurekaClient 25 | @EnableDiscoveryClient 26 | public class MovieRibbonApplication { 27 | /** 28 | * 实例化RestTemplate,通过@LoadBalanced注解开启均衡负载能力. 29 | * @return restTemplate 30 | */ 31 | @Bean 32 | @LoadBalanced 33 | public RestTemplate restTemplate() { 34 | return new RestTemplate(); 35 | } 36 | 37 | public static void main(String[] args) { 38 | SpringApplication.run(MovieRibbonApplication.class, args); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-movie-feign-with-hystrix-stream/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | microservice-consumer-movie-feign-with-hystrix-stream 8 | jar 9 | 10 | 11 | com.minbo.cloud 12 | spring-cloud-microservice-study 13 | 0.0.1-SNAPSHOT 14 | 15 | 16 | 17 | 18 | org.springframework.cloud 19 | spring-cloud-starter-netflix-eureka-client 20 | 21 | 22 | org.springframework.cloud 23 | spring-cloud-starter-openfeign 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-web 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-actuator 32 | 33 | 34 | 35 | org.springframework.cloud 36 | spring-cloud-starter-netflix-hystrix 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-sentinel/src/main/java/com/minbo/cloud/alibaba/web/WebConfig.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.alibaba.web; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.servlet.HandlerInterceptor; 6 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 7 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 8 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; 9 | 10 | /** 11 | * 拦截器定义 12 | * 13 | * @author Minbo.He 14 | */ 15 | @Configuration 16 | public class WebConfig extends WebMvcConfigurationSupport { 17 | 18 | // 让bean提前加载,让拦截器中的@Autowired生效 19 | @Bean 20 | public HandlerInterceptor getInterceptor() { 21 | return new CustomHttpInterceptor(); 22 | } 23 | 24 | @Override 25 | public void addResourceHandlers(ResourceHandlerRegistry registry) { 26 | // 解决 swagger-ui.html 404报错 27 | registry.addResourceHandler("/swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/"); 28 | registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); 29 | 30 | // 解决 doc.html 404 报错 31 | registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/"); 32 | } 33 | 34 | /** 35 | * 可定义多个拦截器 36 | */ 37 | @Override 38 | public void addInterceptors(InterceptorRegistry registry) { 39 | // 定义过滤拦截的url名称,拦截所有请求 40 | registry.addInterceptor(this.getInterceptor()).addPathPatterns("/**"); 41 | super.addInterceptors(registry); 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-nacos-config/src/main/java/com/minbo/cloud/alibaba/web/WebConfig.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.alibaba.web; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.servlet.HandlerInterceptor; 6 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 7 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 8 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; 9 | 10 | /** 11 | * 拦截器定义 12 | * 13 | * @author Minbo.He 14 | */ 15 | @Configuration 16 | public class WebConfig extends WebMvcConfigurationSupport { 17 | 18 | // 让bean提前加载,让拦截器中的@Autowired生效 19 | @Bean 20 | public HandlerInterceptor getInterceptor() { 21 | return new CustomHttpInterceptor(); 22 | } 23 | 24 | @Override 25 | public void addResourceHandlers(ResourceHandlerRegistry registry) { 26 | // 解决 swagger-ui.html 404报错 27 | registry.addResourceHandler("/swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/"); 28 | registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); 29 | 30 | // 解决 doc.html 404 报错 31 | registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/"); 32 | } 33 | 34 | /** 35 | * 可定义多个拦截器 36 | */ 37 | @Override 38 | public void addInterceptors(InterceptorRegistry registry) { 39 | // 定义过滤拦截的url名称,拦截所有请求 40 | registry.addInterceptor(this.getInterceptor()).addPathPatterns("/**"); 41 | super.addInterceptors(registry); 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-nacos-discovery/src/main/java/com/minbo/cloud/alibaba/web/WebConfig.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.alibaba.web; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.servlet.HandlerInterceptor; 6 | import org.springframework.web.servlet.config.annotation.InterceptorRegistry; 7 | import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; 8 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; 9 | 10 | /** 11 | * 拦截器定义 12 | * 13 | * @author Minbo.He 14 | */ 15 | @Configuration 16 | public class WebConfig extends WebMvcConfigurationSupport { 17 | 18 | // 让bean提前加载,让拦截器中的@Autowired生效 19 | @Bean 20 | public HandlerInterceptor getInterceptor() { 21 | return new CustomHttpInterceptor(); 22 | } 23 | 24 | @Override 25 | public void addResourceHandlers(ResourceHandlerRegistry registry) { 26 | // 解决 swagger-ui.html 404报错 27 | registry.addResourceHandler("/swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/"); 28 | registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/"); 29 | 30 | // 解决 doc.html 404 报错 31 | registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/"); 32 | } 33 | 34 | /** 35 | * 可定义多个拦截器 36 | */ 37 | @Override 38 | public void addInterceptors(InterceptorRegistry registry) { 39 | // 定义过滤拦截的url名称,拦截所有请求 40 | registry.addInterceptor(this.getInterceptor()).addPathPatterns("/**"); 41 | super.addInterceptors(registry); 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-nacos-config/src/main/java/com/minbo/cloud/alibaba/web/CustomHttpInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.alibaba.web; 2 | 3 | import java.util.Map; 4 | 5 | import javax.servlet.http.HttpServletRequest; 6 | import javax.servlet.http.HttpServletResponse; 7 | 8 | import org.springframework.cloud.context.config.annotation.RefreshScope; 9 | import org.springframework.stereotype.Component; 10 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; 11 | 12 | import lombok.extern.slf4j.Slf4j; 13 | 14 | /** 15 | * 拦截处理类 16 | * 17 | * @author Minbo 18 | */ 19 | @Component 20 | @Slf4j 21 | @RefreshScope 22 | public class CustomHttpInterceptor extends HandlerInterceptorAdapter { 23 | 24 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) 25 | throws Exception { 26 | long start = System.currentTimeMillis(); 27 | String url = request.getRequestURL().toString(); 28 | String method = request.getMethod(); 29 | String queryString = ""; 30 | // 去掉最后一个空格 31 | Map params = request.getParameterMap(); 32 | for (String key : params.keySet()) { 33 | String[] values = params.get(key); 34 | for (int i = 0; i < values.length; i++) { 35 | String value = values[i]; 36 | queryString += key + "=" + value + "&"; 37 | } 38 | } 39 | // URL 参数 40 | queryString = queryString.equals("") ? null : queryString.substring(0, queryString.length() - 1); 41 | 42 | long end = System.currentTimeMillis(); 43 | 44 | log.info(String.format("请求参数, url: %s, method: %s, query-params: %s, run-time: %s", url, method, queryString, 45 | (end - start) + "")); 46 | 47 | return true; 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-sentinel/src/main/java/com/minbo/cloud/alibaba/web/CustomHttpInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.alibaba.web; 2 | 3 | import java.util.Map; 4 | 5 | import javax.servlet.http.HttpServletRequest; 6 | import javax.servlet.http.HttpServletResponse; 7 | 8 | import org.springframework.cloud.context.config.annotation.RefreshScope; 9 | import org.springframework.stereotype.Component; 10 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; 11 | 12 | import lombok.extern.slf4j.Slf4j; 13 | 14 | /** 15 | * 拦截处理类 16 | * 17 | * @author Minbo 18 | */ 19 | @Component 20 | @Slf4j 21 | @RefreshScope 22 | public class CustomHttpInterceptor extends HandlerInterceptorAdapter { 23 | 24 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) 25 | throws Exception { 26 | long start = System.currentTimeMillis(); 27 | String url = request.getRequestURL().toString(); 28 | String method = request.getMethod(); 29 | String queryString = ""; 30 | // 去掉最后一个空格 31 | Map params = request.getParameterMap(); 32 | for (String key : params.keySet()) { 33 | String[] values = params.get(key); 34 | for (int i = 0; i < values.length; i++) { 35 | String value = values[i]; 36 | queryString += key + "=" + value + "&"; 37 | } 38 | } 39 | // URL 参数 40 | queryString = queryString.equals("") ? null : queryString.substring(0, queryString.length() - 1); 41 | 42 | long end = System.currentTimeMillis(); 43 | 44 | log.info(String.format("请求参数, url: %s, method: %s, query-params: %s, run-time: %s", url, method, queryString, 45 | (end - start) + "")); 46 | 47 | return true; 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-nacos-discovery/src/main/java/com/minbo/cloud/alibaba/web/CustomHttpInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.alibaba.web; 2 | 3 | import java.util.Map; 4 | 5 | import javax.servlet.http.HttpServletRequest; 6 | import javax.servlet.http.HttpServletResponse; 7 | 8 | import org.springframework.cloud.context.config.annotation.RefreshScope; 9 | import org.springframework.stereotype.Component; 10 | import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; 11 | 12 | import lombok.extern.slf4j.Slf4j; 13 | 14 | /** 15 | * 拦截处理类 16 | * 17 | * @author Minbo 18 | */ 19 | @Component 20 | @Slf4j 21 | @RefreshScope 22 | public class CustomHttpInterceptor extends HandlerInterceptorAdapter { 23 | 24 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) 25 | throws Exception { 26 | long start = System.currentTimeMillis(); 27 | String url = request.getRequestURL().toString(); 28 | String method = request.getMethod(); 29 | String queryString = ""; 30 | // 去掉最后一个空格 31 | Map params = request.getParameterMap(); 32 | for (String key : params.keySet()) { 33 | String[] values = params.get(key); 34 | for (int i = 0; i < values.length; i++) { 35 | String value = values[i]; 36 | queryString += key + "=" + value + "&"; 37 | } 38 | } 39 | // URL 参数 40 | queryString = queryString.equals("") ? null : queryString.substring(0, queryString.length() - 1); 41 | 42 | long end = System.currentTimeMillis(); 43 | 44 | log.info(String.format("请求参数, url: %s, method: %s, query-params: %s, run-time: %s", url, method, queryString, 45 | (end - start) + "")); 46 | 47 | return true; 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-api-gateway/src/main/java/com/minbo/cloud/study/TokenVerifyFilter.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study; 2 | 3 | import javax.servlet.http.HttpServletRequest; 4 | 5 | import org.springframework.stereotype.Component; 6 | 7 | import com.netflix.zuul.ZuulFilter; 8 | import com.netflix.zuul.context.RequestContext; 9 | import com.netflix.zuul.exception.ZuulException; 10 | 11 | /** 12 | * Token过滤验证 13 | * 14 | * @author Minbo 15 | */ 16 | @Component 17 | public class TokenVerifyFilter extends ZuulFilter { 18 | 19 | @Override 20 | public boolean shouldFilter() { 21 | // 开启过滤验证 22 | return true; 23 | } 24 | 25 | /** 26 | * 具体过滤逻辑,可以操作redis,或db,或其他验证权限等 27 | */ 28 | @Override 29 | public Object run() throws ZuulException { 30 | RequestContext ctx = RequestContext.getCurrentContext(); 31 | HttpServletRequest request = ctx.getRequest(); 32 | System.out.println(request.getMethod() + "," + request.getRequestURL().toString()); 33 | Object token = request.getParameter("token"); 34 | if (token == null) { 35 | System.out.println("token is empty"); 36 | ctx.setSendZuulResponse(false); 37 | ctx.setResponseStatusCode(401); 38 | try { 39 | ctx.getResponse().getWriter().write("token is empty"); 40 | } catch (Exception e) { 41 | } 42 | 43 | return null; 44 | } 45 | System.out.println("pass ok"); 46 | return null; 47 | } 48 | 49 | /** 50 | * filterType:返回一个字符串代表过滤器的类型,在zuul中定义了四种不同生命周期的过滤器类型,具体如下: 51 | * 1. pre:路由之前 52 | * 2. routing:路由之时 53 | * 3. post: 路由之后 54 | * 4. error:发送错误调用 55 | */ 56 | @Override 57 | public String filterType() { 58 | return "pre"; 59 | } 60 | 61 | @Override 62 | public int filterOrder() { 63 | return 0; 64 | } 65 | 66 | } -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-movie-ribbon-with-hystrix/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | microservice-consumer-movie-ribbon-with-hystrix 8 | jar 9 | 10 | 11 | com.minbo.cloud 12 | spring-cloud-microservice-study 13 | 0.0.1-SNAPSHOT 14 | 15 | 16 | 17 | 18 | org.springframework.cloud 19 | spring-cloud-starter-netflix-eureka-client 20 | 21 | 22 | 23 | 24 | org.springframework.cloud 25 | spring-cloud-starter-netflix-ribbon 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-actuator 36 | 37 | 38 | 39 | 40 | org.springframework.cloud 41 | spring-cloud-starter-netflix-hystrix 42 | 43 | 44 | 45 | org.springframework.cloud 46 | spring-cloud-starter-zipkin 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-nacos-config/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | microservice-alibaba-nacos-config 8 | jar 9 | 10 | 11 | com.minbo.cloud.alibaba 12 | spring-cloud-alibaba-study-parent 13 | 0.0.1-SNAPSHOT 14 | 15 | 16 | 17 | 18 | org.springframework.boot 19 | spring-boot-starter-web 20 | 21 | 22 | org.projectlombok 23 | lombok 24 | 25 | 26 | io.springfox 27 | springfox-swagger2 28 | 29 | 30 | io.springfox 31 | springfox-swagger-ui 32 | 33 | 34 | com.github.xiaoymin 35 | swagger-bootstrap-ui 36 | 37 | 38 | net.sf.json-lib 39 | json-lib-ext-spring 40 | 41 | 42 | org.springframework.cloud 43 | spring-cloud-starter-alibaba-nacos-discovery 44 | 45 | 46 | org.springframework.cloud 47 | spring-cloud-starter-alibaba-nacos-config 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-nacos-discovery/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | microservice-alibaba-nacos-discovery 8 | jar 9 | 10 | 11 | com.minbo.cloud.alibaba 12 | spring-cloud-alibaba-study-parent 13 | 0.0.1-SNAPSHOT 14 | 15 | 16 | 17 | 18 | org.springframework.boot 19 | spring-boot-starter-web 20 | 21 | 22 | org.projectlombok 23 | lombok 24 | 25 | 26 | io.springfox 27 | springfox-swagger2 28 | 29 | 30 | io.springfox 31 | springfox-swagger-ui 32 | 33 | 34 | com.github.xiaoymin 35 | swagger-bootstrap-ui 36 | 37 | 38 | 39 | org.springframework.cloud 40 | spring-cloud-starter-alibaba-nacos-discovery 41 | 42 | 43 | 44 | 45 | microservice-alibaba-nacos-discovery 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-maven-plugin 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-nacos-config/src/main/resources/bootstrap.yaml.bak: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: microservice-alibaba-nacos-config 4 | profiles: 5 | active: dev 6 | cloud: 7 | nacos: 8 | discovery: 9 | server-addr: 127.0.0.1:8848 10 | namespace: 2bc5565f-453f-4b1c-bde4-eafe23bdb2f0 11 | config: 12 | server-addr: 127.0.0.1:8848 13 | namespace: 2bc5565f-453f-4b1c-bde4-eafe23bdb2f0 14 | file-extension: properties 15 | shared-dataids: microservice-alibaba-nacos-config.properties 16 | refreshable-dataids: microservice-alibaba-nacos-config.properties 17 | datasource: 18 | driverClassName: ${config.datasource.driverClassName} 19 | url: ${config.datasource.url} 20 | username: ${config.datasource.username} 21 | password: ${config.datasource.password} 22 | hikari: 23 | initial-size: ${config.datasource.initialSize} 24 | minimum-idle: ${config.datasource.minIdle} 25 | maximum-pool-size: ${config.datasource.maxActive} 26 | auto-commit: true 27 | idle-timeout: 20000 28 | pool-name: MyHikarifMain 29 | max-lifetime: 1800000 30 | connection-timeout: 20000 31 | connection-test-query: SELECT 1 32 | validation-timeout: 5000 33 | redis: 34 | host: ${config.redis.host} 35 | port: ${config.redis.port} 36 | password: ${config.redis.password} 37 | pool: 38 | max-idle: ${config.redis.pool.max-idle} 39 | min-idle: ${config.redis.pool.min-idle} 40 | max-active: ${config.redis.pool.max-active} 41 | max-wait: ${config.redis.pool.max-wait} 42 | timeout: ${config.redis.timeout} 43 | commandTimeout: ${config.redis.commandTimeout} 44 | 45 | # server 46 | server: 47 | port: 9091 -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-sentinel/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | microservice-alibaba-sentinel 8 | jar 9 | 10 | 11 | com.minbo.cloud.alibaba 12 | spring-cloud-alibaba-study-parent 13 | 0.0.1-SNAPSHOT 14 | 15 | 16 | 17 | 18 | org.springframework.boot 19 | spring-boot-starter-web 20 | 21 | 22 | org.projectlombok 23 | lombok 24 | 25 | 26 | io.springfox 27 | springfox-swagger2 28 | 29 | 30 | io.springfox 31 | springfox-swagger-ui 32 | 33 | 34 | com.github.xiaoymin 35 | swagger-bootstrap-ui 36 | 37 | 38 | net.sf.json-lib 39 | json-lib-ext-spring 40 | 41 | 42 | org.springframework.cloud 43 | spring-cloud-starter-alibaba-nacos-discovery 44 | 45 | 46 | org.springframework.cloud 47 | spring-cloud-starter-alibaba-nacos-config 48 | 49 | 50 | org.springframework.cloud 51 | spring-cloud-starter-alibaba-sentinel 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-consumer-movie-ribbon-with-hystrix/src/main/java/com/minbo/cloud/study/MovieRibbonHystrixApplication.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker; 6 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 7 | import org.springframework.cloud.client.loadbalancer.LoadBalanced; 8 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 9 | import org.springframework.context.annotation.Bean; 10 | import org.springframework.web.client.RestTemplate; 11 | 12 | /** 13 | * 14 | * 在Spring Cloud中使用了Netflix开发的Hystrix来实现熔断器 15 | * 16 | * 雪崩效应 在微服务架构中通常会有多个服务层调用,基础服务的故障可能会导致级联故障,进而造成整个系统不可用的情况,这种现象被称为服务雪崩效应。 17 | * 服务雪崩效应是一种因“服务提供者”的不可用导致“服务消费者”的不可用,并将不可用逐渐放大的过程。 18 | * 19 | * 熔断器(CircuitBreaker) 20 | * 熔断器的原理很简单,如同电力过载保护器。它可以实现快速失败,如果它在一段时间内侦测到许多类似的错误,会强迫其以后的多个调用快速失败,不再访问远程服务器, 21 | * 从而防止应用程序不断地尝试执行可能会失败的操作,使得应用程序继续执行而不用等待修正错误,或者浪费CPU时间去等到长时间的超时产生。 22 | * 熔断器也可以使应用程序能够诊断错误是否已经修正,如果已经修正,应用程序会再次尝试调用操作。 23 | * 熔断器模式就像是那些容易导致错误的操作的一种代理。这种代理能够记录最近调用发生错误的次数,然后决定使用允许操作继续,或者立即返回错误。 24 | * 25 | * 除了隔离依赖服务的调用以外,Hystrix还提供了近实时的监控,Hystrix会实时、累加地记录所有关于HystrixCommand的执行信息,包括每秒执行多少请求多少成功,多少失败等。 26 | * Netflix通过hystrix-metrics-event-stream项目实现了对以上指标的监控。 27 | * 28 | * Hystrix的监控数据默认是保存在每个实例的内存中的,Spring Boot提供了多种方式,可以导入到Redis、TSDB以供日后分析使用。 29 | * 30 | * 使用@EnableCircuitBreaker注解开启断路器功能 31 | * 32 | * 查看:http://localhost:8011/actuator/hystrix.stream 33 | */ 34 | @SpringBootApplication 35 | @EnableEurekaClient 36 | @EnableDiscoveryClient 37 | @EnableCircuitBreaker 38 | public class MovieRibbonHystrixApplication { 39 | 40 | /** 41 | * 实例化RestTemplate,通过@LoadBalanced注解开启均衡负载能力. 42 | * 43 | * @return restTemplate 44 | */ 45 | @Bean 46 | @LoadBalanced 47 | public RestTemplate restTemplate() { 48 | return new RestTemplate(); 49 | } 50 | 51 | public static void main(String[] args) { 52 | SpringApplication.run(MovieRibbonHystrixApplication.class, args); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /spring-cloud-alibaba/README.md: -------------------------------------------------------------------------------- 1 | # 项目简介 2 | 3 | SpringCloud Alibaba系列(基于Greenwich版本,SpringBoot2.1.7版本实现) 4 | 5 | 教程地址有(持续更新中...): 6 | 7 | 1. [SpringCloud Alibaba从入门到精通教程(一)- 配置中心Nacos快速入门介绍·Server启动安装](https://blog.csdn.net/hemin1003/article/details/105517901) 8 | 2. [SpringCloud Alibaba从入门到精通教程(二)- 项目中快速集成配置中心·Nacos-服务注册发现功能 springcloud-alibaba-nacos-discovery](https://hemin.blog.csdn.net/article/details/105517927) 9 | 3. [SpringCloud Alibaba从入门到精通教程(三)- 项目中快速集成配置中心·Nacos-配置中心管理功能 springcloud-alibaba-nacos-config](https://hemin.blog.csdn.net/article/details/105517950) 10 | 4. [SpringCloud Alibaba从入门到精通教程(四)- 流控组件Sentinel快速入门介绍·Server启动安装](https://hemin.blog.csdn.net/article/details/105517988) 11 | 5. [SpringCloud Alibaba从入门到精通教程(五)- 项目中快速集成·限流组件Sentinel springcloud-alibaba-sentinel](https://hemin.blog.csdn.net/article/details/105517973) 12 | 6. SpringCloud Alibaba从入门到精通教程(六)- 项目中快速集成·MQ消息组件RocketMQ springcloud-alibaba-rocketmq 13 | 7. SpringCloud Alibaba从入门到精通教程(七)- 项目中快速集成·分布式事务组件Seata springcloud-alibaba-seata 14 | 8. SpringCloud Alibaba从入门到精通教程(八)- 项目中快速集成·服务治理组件Dubbo springcloud-alibaba-dubbo 15 | 9. SpringCloud Alibaba从入门到精通教程(九)- 项目中快速集成·限流组件Sentinel之限流数据源 springcloud-alibaba-sentinel-datasource 16 | 10. SpringCloud Alibaba从入门到精通教程(十)- 项目中快速集成·限流组件Sentinel之限流网关 springcloud-alibaba-sentinel-gateway 17 | 11. SpringCloud Alibaba从入门到精通教程(十一)- 项目中快速集成·限流组件Sentinel之断路器 springcloud-alibaba-circuitbreaker-sentinel 18 | 19 | ## 我的教程系列 20 | 21 | 1. [SpringCloud从入门到精通教程](https://blog.csdn.net/hemin1003/article/details/82043611) 22 | 23 | 2. [SpringBoot从入门到精通教程](https://blog.csdn.net/hemin1003/article/details/82038244) 24 | 25 | 3. [SpringCloud Alibaba从入门到精通教程](https://blog.csdn.net/hemin1003/article/details/82043611) 26 | 27 | ## [关于我](http://heminit.com/about/) 28 | 29 | 欢迎交流问题,可加我的个人QQ 469580884,或群号 751925591,一起探讨交流问题 30 | 31 | [我的博客地址-博客专家](http://blog.csdn.net/hemin1003) 32 | 33 | [个人域名](http://heminit.com) 34 | 35 | ## 感谢 36 | 如果觉得内容赞,您可以请我喝一杯咖啡: 37 |
38 |      39 | 40 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/microservice-api-gateway/src/main/java/com/minbo/cloud/study/MyFallbackProvider.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.study; 2 | 3 | import com.netflix.hystrix.exception.HystrixTimeoutException; 4 | import org.springframework.cloud.netflix.zuul.filters.route.FallbackProvider; 5 | import org.springframework.http.HttpHeaders; 6 | import org.springframework.http.HttpStatus; 7 | import org.springframework.http.MediaType; 8 | import org.springframework.http.client.ClientHttpResponse; 9 | import org.springframework.stereotype.Component; 10 | 11 | import java.io.ByteArrayInputStream; 12 | import java.io.IOException; 13 | import java.io.InputStream; 14 | import java.nio.charset.Charset; 15 | 16 | /** 17 | * 18 | * 使用zuul的fallback来实现服务降级和熔断功能 19 | * 20 | * @author Minbo 21 | */ 22 | @Component 23 | public class MyFallbackProvider implements FallbackProvider { 24 | 25 | @Override 26 | public String getRoute() { 27 | // 表明是为哪个微服务提供回退,*表示为所有微服务提供回退 28 | return "*"; 29 | } 30 | 31 | @Override 32 | public ClientHttpResponse fallbackResponse(String route, Throwable cause) { 33 | if (cause instanceof HystrixTimeoutException) { 34 | return response(HttpStatus.GATEWAY_TIMEOUT); 35 | } else { 36 | return this.fallbackResponse(); 37 | } 38 | } 39 | 40 | public ClientHttpResponse fallbackResponse() { 41 | return this.response(HttpStatus.INTERNAL_SERVER_ERROR); 42 | } 43 | 44 | private ClientHttpResponse response(final HttpStatus status) { 45 | return new ClientHttpResponse() { 46 | @Override 47 | public HttpStatus getStatusCode() throws IOException { 48 | return status; 49 | } 50 | 51 | @Override 52 | public int getRawStatusCode() throws IOException { 53 | return status.value(); 54 | } 55 | 56 | @Override 57 | public String getStatusText() throws IOException { 58 | return status.getReasonPhrase(); 59 | } 60 | 61 | @Override 62 | public void close() { 63 | } 64 | 65 | @Override 66 | public InputStream getBody() throws IOException { 67 | return new ByteArrayInputStream("服务不可用,请稍后再试。".getBytes()); 68 | } 69 | 70 | @Override 71 | public HttpHeaders getHeaders() { 72 | // headers设定 73 | HttpHeaders headers = new HttpHeaders(); 74 | MediaType mt = new MediaType("application", "json", Charset.forName("UTF-8")); 75 | headers.setContentType(mt); 76 | return headers; 77 | } 78 | }; 79 | } 80 | } -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-sentinel/src/main/java/com/minbo/cloud/alibaba/web/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.alibaba.web; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | import springfox.documentation.builders.ApiInfoBuilder; 10 | import springfox.documentation.builders.ParameterBuilder; 11 | import springfox.documentation.builders.PathSelectors; 12 | import springfox.documentation.builders.RequestHandlerSelectors; 13 | import springfox.documentation.schema.ModelRef; 14 | import springfox.documentation.service.ApiInfo; 15 | import springfox.documentation.service.Parameter; 16 | import springfox.documentation.spi.DocumentationType; 17 | import springfox.documentation.spring.web.plugins.Docket; 18 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 19 | 20 | @Configuration 21 | @EnableSwagger2 22 | public class SwaggerConfig { 23 | 24 | /** 25 | * 创建一个Docket对象 调用select()方法, 生成ApiSelectorBuilder对象实例,该对象负责定义外漏的API入口 26 | * 通过使用RequestHandlerSelectors和PathSelectors来提供Predicate,在此我们使用any()方法,将所有API都通过Swagger进行文档管理 27 | * 28 | * @return 29 | */ 30 | @Bean 31 | public Docket createRestApi() { 32 | // 定义全局header参数 33 | ParameterBuilder useridPar = new ParameterBuilder(); 34 | List pars = new ArrayList<>(); 35 | useridPar.name("access_token").defaultValue("").description("访问身份令牌").modelRef(new ModelRef("string")) 36 | .parameterType("header").required(false).build(); 37 | pars.add(useridPar.build()); 38 | 39 | return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select() 40 | // 如果不想将所有的接口都通过swagger管理的话,可以将RequestHandlerSelectors.any()修改为RequestHandlerSelectors.basePackage() 41 | // .apis(RequestHandlerSelectors.any()) 42 | .apis(RequestHandlerSelectors.basePackage("com.minbo")).paths(PathSelectors.any()).build() 43 | .globalOperationParameters(pars); 44 | } 45 | 46 | @SuppressWarnings("deprecation") 47 | private ApiInfo apiInfo() { 48 | return new ApiInfoBuilder() 49 | // 标题 50 | .title("在线接口测试平台:microservice-alibaba-sentinel服务") 51 | // 简介 52 | .description("rest接口层:接口服务") 53 | // 服务条款 54 | .termsOfServiceUrl("https://blog.csdn.net/hemin1003") 55 | // 作者个人信息 56 | .contact("Minbo.He") 57 | // 版本 58 | .version("1.0").build(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-nacos-config/src/main/java/com/minbo/cloud/alibaba/web/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.alibaba.web; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | import springfox.documentation.builders.ApiInfoBuilder; 10 | import springfox.documentation.builders.ParameterBuilder; 11 | import springfox.documentation.builders.PathSelectors; 12 | import springfox.documentation.builders.RequestHandlerSelectors; 13 | import springfox.documentation.schema.ModelRef; 14 | import springfox.documentation.service.ApiInfo; 15 | import springfox.documentation.service.Parameter; 16 | import springfox.documentation.spi.DocumentationType; 17 | import springfox.documentation.spring.web.plugins.Docket; 18 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 19 | 20 | @Configuration 21 | @EnableSwagger2 22 | public class SwaggerConfig { 23 | 24 | /** 25 | * 创建一个Docket对象 调用select()方法, 生成ApiSelectorBuilder对象实例,该对象负责定义外漏的API入口 26 | * 通过使用RequestHandlerSelectors和PathSelectors来提供Predicate,在此我们使用any()方法,将所有API都通过Swagger进行文档管理 27 | * 28 | * @return 29 | */ 30 | @Bean 31 | public Docket createRestApi() { 32 | // 定义全局header参数 33 | ParameterBuilder useridPar = new ParameterBuilder(); 34 | List pars = new ArrayList<>(); 35 | useridPar.name("access_token").defaultValue("").description("访问身份令牌").modelRef(new ModelRef("string")) 36 | .parameterType("header").required(false).build(); 37 | pars.add(useridPar.build()); 38 | 39 | return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select() 40 | // 如果不想将所有的接口都通过swagger管理的话,可以将RequestHandlerSelectors.any()修改为RequestHandlerSelectors.basePackage() 41 | // .apis(RequestHandlerSelectors.any()) 42 | .apis(RequestHandlerSelectors.basePackage("com.minbo")).paths(PathSelectors.any()).build() 43 | .globalOperationParameters(pars); 44 | } 45 | 46 | @SuppressWarnings("deprecation") 47 | private ApiInfo apiInfo() { 48 | return new ApiInfoBuilder() 49 | // 标题 50 | .title("在线接口测试平台:microservice-alibaba-nacos-config服务") 51 | // 简介 52 | .description("rest接口层:接口服务") 53 | // 服务条款 54 | .termsOfServiceUrl("https://blog.csdn.net/hemin1003") 55 | // 作者个人信息 56 | .contact("Minbo.He") 57 | // 版本 58 | .version("1.0").build(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-nacos-discovery/src/main/java/com/minbo/cloud/alibaba/web/SwaggerConfig.java: -------------------------------------------------------------------------------- 1 | package com.minbo.cloud.alibaba.web; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.springframework.context.annotation.Bean; 7 | import org.springframework.context.annotation.Configuration; 8 | 9 | import springfox.documentation.builders.ApiInfoBuilder; 10 | import springfox.documentation.builders.ParameterBuilder; 11 | import springfox.documentation.builders.PathSelectors; 12 | import springfox.documentation.builders.RequestHandlerSelectors; 13 | import springfox.documentation.schema.ModelRef; 14 | import springfox.documentation.service.ApiInfo; 15 | import springfox.documentation.service.Parameter; 16 | import springfox.documentation.spi.DocumentationType; 17 | import springfox.documentation.spring.web.plugins.Docket; 18 | import springfox.documentation.swagger2.annotations.EnableSwagger2; 19 | 20 | @Configuration 21 | @EnableSwagger2 22 | public class SwaggerConfig { 23 | 24 | /** 25 | * 创建一个Docket对象 调用select()方法, 生成ApiSelectorBuilder对象实例,该对象负责定义外漏的API入口 26 | * 通过使用RequestHandlerSelectors和PathSelectors来提供Predicate,在此我们使用any()方法,将所有API都通过Swagger进行文档管理 27 | * 28 | * @return 29 | */ 30 | @Bean 31 | public Docket createRestApi() { 32 | // 定义全局header参数 33 | ParameterBuilder useridPar = new ParameterBuilder(); 34 | List pars = new ArrayList<>(); 35 | useridPar.name("access_token").defaultValue("").description("访问身份令牌").modelRef(new ModelRef("string")) 36 | .parameterType("header").required(false).build(); 37 | pars.add(useridPar.build()); 38 | 39 | return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select() 40 | // 如果不想将所有的接口都通过swagger管理的话,可以将RequestHandlerSelectors.any()修改为RequestHandlerSelectors.basePackage() 41 | // .apis(RequestHandlerSelectors.any()) 42 | .apis(RequestHandlerSelectors.basePackage("com.minbo")).paths(PathSelectors.any()).build() 43 | .globalOperationParameters(pars); 44 | } 45 | 46 | @SuppressWarnings("deprecation") 47 | private ApiInfo apiInfo() { 48 | return new ApiInfoBuilder() 49 | // 标题 50 | .title("在线接口测试平台:microservice-alibaba-nacos-discovery服务") 51 | // 简介 52 | .description("rest接口层:接口服务") 53 | // 服务条款 54 | .termsOfServiceUrl("https://blog.csdn.net/hemin1003") 55 | // 作者个人信息 56 | .contact("Minbo.He") 57 | // 版本 58 | .version("1.0").build(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.minbo.cloud 8 | spring-cloud-microservice-study 9 | 0.0.1-SNAPSHOT 10 | pom 11 | 12 | 13 | org.springframework.boot 14 | spring-boot-starter-parent 15 | 2.1.7.RELEASE 16 | 17 | 18 | 19 | microservice-discovery-eureka 20 | microservice-provider-user 21 | 22 | microservice-consumer-movie-ribbon 23 | microservice-consumer-movie-ribbon-with-hystrix 24 | 25 | microservice-hystrix-dashboard 26 | microservice-hystrix-turbine 27 | 28 | microservice-consumer-movie-feign 29 | microservice-consumer-movie-feign-with-hystrix 30 | microservice-consumer-movie-feign-with-hystrix-stream 31 | 32 | microservice-api-gateway 33 | 34 | microservice-config-server 35 | microservice-config-client 36 | 37 | microservice-config-server-eureka 38 | microservice-config-client-eureka 39 | 40 | microservice-consumer-zipkin-hi 41 | microservice-consumer-zipkin-greet 42 | 43 | 44 | 45 | UTF-8 46 | 1.8 47 | Greenwich.RELEASE 48 | 49 | 50 | 51 | 52 | 53 | org.springframework.cloud 54 | spring-cloud-dependencies 55 | ${spring-cloud.version} 56 | pom 57 | import 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | org.springframework.boot 66 | spring-boot-maven-plugin 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /spring-cloud-alibaba/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.minbo.cloud.alibaba 8 | spring-cloud-alibaba-study-parent 9 | 0.0.1-SNAPSHOT 10 | pom 11 | 12 | 13 | org.springframework.boot 14 | spring-boot-starter-parent 15 | 2.1.7.RELEASE 16 | 17 | 18 | 19 | microservice-alibaba-nacos-discovery 20 | microservice-alibaba-nacos-config 21 | microservice-alibaba-sentinel 22 | 23 | 24 | 25 | UTF-8 26 | 1.8 27 | Greenwich.RELEASE 28 | 0.9.0.RELEASE 29 | 0.2.2.RELEASE 30 | 2.9.2 31 | 32 | 33 | 34 | 35 | 36 | org.springframework.cloud 37 | spring-cloud-dependencies 38 | ${spring-cloud.version} 39 | pom 40 | import 41 | 42 | 43 | org.springframework.cloud 44 | spring-cloud-alibaba-dependencies 45 | ${alibaba-spring-cloud.version} 46 | pom 47 | import 48 | 49 | 50 | org.springframework.cloud 51 | spring-cloud-starter-alibaba-nacos-config 52 | ${nacos.version} 53 | 54 | 55 | 56 | io.springfox 57 | springfox-swagger2 58 | ${swagger.version} 59 | 60 | 61 | 62 | io.springfox 63 | springfox-swagger-ui 64 | ${swagger.version} 65 | 66 | 67 | 68 | com.github.xiaoymin 69 | swagger-bootstrap-ui 70 | 1.9.3 71 | 72 | 73 | net.sf.json-lib 74 | json-lib-ext-spring 75 | 1.0.2 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | org.springframework.boot 84 | spring-boot-maven-plugin 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /spring-cloud-alibaba/microservice-alibaba-nacos-config/src/main/resources/bootstrap.yaml2.bak: -------------------------------------------------------------------------------- 1 | # 不同的环境使用不同的配置,通过指定启动参数使用不同的profile,比如: 2 | # 开发环境:java -jar xxx.jar --spring.profiles.active=dev 3 | # 生产环境:java -jar xxx.jar --spring.profiles.active=prod 4 | spring: 5 | application: 6 | name: microservice-alibaba-nacos-config 7 | profiles: 8 | active: dev 9 | datasource: 10 | driverClassName: ${config.datasource.driverClassName} 11 | url: ${config.datasource.url} 12 | username: ${config.datasource.username} 13 | password: ${config.datasource.password} 14 | hikari: 15 | initial-size: ${config.datasource.initialSize} 16 | minimum-idle: ${config.datasource.minIdle} 17 | maximum-pool-size: ${config.datasource.maxActive} 18 | auto-commit: true 19 | idle-timeout: 20000 20 | pool-name: MyHikarifMain 21 | max-lifetime: 1800000 22 | connection-timeout: 20000 23 | connection-test-query: SELECT 1 24 | validation-timeout: 5000 25 | redis: 26 | host: ${config.redis.host} 27 | port: ${config.redis.port} 28 | password: ${config.redis.password} 29 | pool: 30 | max-idle: ${config.redis.pool.max-idle} 31 | min-idle: ${config.redis.pool.min-idle} 32 | max-active: ${config.redis.pool.max-active} 33 | max-wait: ${config.redis.pool.max-wait} 34 | timeout: ${config.redis.timeout} 35 | commandTimeout: ${config.redis.commandTimeout} 36 | 37 | # server 38 | server: 39 | port: 9091 40 | 41 | #下面这一行务必不能少,区分不同配置,而且必须是三个字符"-" 42 | --- 43 | spring: 44 | profiles: dev 45 | cloud: 46 | nacos: 47 | discovery: 48 | server-addr: 127.0.0.1:8848 49 | namespace: 2bc5565f-453f-4b1c-bde4-eafe23bdb2f0 50 | config: 51 | server-addr: 127.0.0.1:8848 52 | namespace: 2bc5565f-453f-4b1c-bde4-eafe23bdb2f0 53 | file-extension: properties 54 | shared-dataids: microservice-alibaba-nacos-config.properties 55 | refreshable-dataids: microservice-alibaba-nacos-config.properties 56 | --- 57 | spring: 58 | profiles: test 59 | cloud: 60 | nacos: 61 | discovery: 62 | server-addr: 127.0.0.1:8848 63 | namespace: 47247e4c-b018-4c63-92cd-ebbc119eef7f 64 | config: 65 | server-addr: 127.0.0.1:8848 66 | namespace: 47247e4c-b018-4c63-92cd-ebbc119eef7f 67 | file-extension: properties 68 | shared-dataids: microservice-alibaba-nacos-config.properties 69 | refreshable-dataids: microservice-alibaba-nacos-config.properties 70 | --- 71 | spring: 72 | profiles: prod 73 | cloud: 74 | nacos: 75 | discovery: 76 | server-addr: 127.0.0.1:8848 77 | namespace: 9d3bb62a-14c5-43aa-ac05-6576caa5be2b 78 | config: 79 | server-addr: 127.0.0.1:8848 80 | namespace: 9d3bb62a-14c5-43aa-ac05-6576caa5be2b 81 | file-extension: properties 82 | shared-dataids: microservice-alibaba-nacos-config.properties 83 | refreshable-dataids: microservice-alibaba-nacos-config.properties -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 项目简介 2 | 3 | SpringCloud微服务框架实战(2020年3月更新),源自一线项目实践总结和学习分享,希望对你有用 4 | 5 | ## 1. spring-cloud-greenwich(基于Greenwich版本,SpringBoot2.1.7版本实现) 6 | 7 | 教程地址有(持续更新中...): 8 | 9 | 1. SpringCloud从入门到精通教程(一)- 服务的注册与发现(Eureka) 10 | 2. SpringCloud从入门到精通教程(二)- 高可用的服务注册中心(Eureka) 11 | 3. SpringCloud从入门到精通教程(三)- 服务提供者 12 | 4. SpringCloud从入门到精通教程(四)- 服务消费者(ribbon) 13 | 5. SpringCloud从入门到精通教程(五)- 服务消费者(feign) 14 | 6. SpringCloud从入门到精通教程(六)- 断路器/服务消费者(ribbon + hystrix) 15 | 7. SpringCloud从入门到精通教程(七)- 断路器/服务消费者(feign + hystrix) 16 | 8. SpringCloud从入门到精通教程(八)- 动态路由网关(zuul) 17 | 9. SpringCloud从入门到精通教程(九)- 动态路由网关限流(zuul+ratelimit) 18 | 10. SpringCloud从入门到精通教程(十)- 分布式配置中心 19 | 11. SpringCloud从入门到精通教程(十一)- 高可用的分布式配置中心 20 | 12. SpringCloud从入门到精通教程(十二)- 断路器监控(hystrix dashboard) 21 | 13. SpringCloud从入门到精通教程(十三)- 路器聚合监控(hystrix turbine) 22 | 14. SpringCloud从入门到精通教程(十四)- 服务链路追踪 23 | 15. SpringCloud从入门到精通教程(十五)- 消息总线bus 24 | 16. SpringCloud从入门到精通教程(十六)- 网关鉴权认证 25 | 17. SpringCloud从入门到精通教程(十七)- SpringBoot Admin监控台 26 | 18. SpringCloud从入门到精通教程(十八)- 项目实战/微服务架构设计 27 | 28 | ## 2. spring-cloud-hoxton(基于Hoxton版本,SpringBoot2.2.x版本实现) 29 | 30 | 待更新(规划中...) 31 | 32 | ## 3. spring-cloud-alibaba(基于alibaba版本) 33 | 34 | 教程地址有(持续更新中...): 35 | 36 | 1. [SpringCloud Alibaba从入门到精通教程(一)- 配置中心Nacos快速入门介绍·Server启动安装](https://blog.csdn.net/hemin1003/article/details/105517901) 37 | 2. [SpringCloud Alibaba从入门到精通教程(二)- 项目中快速集成配置中心·Nacos-服务注册发现功能 springcloud-alibaba-nacos-discovery](https://hemin.blog.csdn.net/article/details/105517927) 38 | 3. [SpringCloud Alibaba从入门到精通教程(三)- 项目中快速集成配置中心·Nacos-配置中心管理功能 springcloud-alibaba-nacos-config](https://hemin.blog.csdn.net/article/details/105517950) 39 | 4. [SpringCloud Alibaba从入门到精通教程(四)- 流控组件Sentinel快速入门介绍·Server启动安装](https://hemin.blog.csdn.net/article/details/105517988) 40 | 5. [SpringCloud Alibaba从入门到精通教程(五)- 项目中快速集成·限流组件Sentinel springcloud-alibaba-sentinel](https://hemin.blog.csdn.net/article/details/105517973) 41 | 6. [SpringCloud Alibaba从入门到精通教程(六)- 消息组件RocketMQ快速入门介绍·Server启动安装](https://blog.csdn.net/hemin1003/article/details/106555661) 42 | 7. SpringCloud Alibaba从入门到精通教程(七)- 项目中快速集成·MQ消息组件RocketMQ springcloud-alibaba-rocketmq 43 | 8. SpringCloud Alibaba从入门到精通教程(八)- 项目中快速集成·分布式事务组件Seata springcloud-alibaba-seata 44 | 9. SpringCloud Alibaba从入门到精通教程(九)- 项目中快速集成·服务治理组件Dubbo springcloud-alibaba-dubbo 45 | 10. SpringCloud Alibaba从入门到精通教程(十)- 项目中快速集成·限流组件Sentinel之限流数据源 springcloud-alibaba-sentinel-datasource 46 | 11. SpringCloud Alibaba从入门到精通教程(十一)- 项目中快速集成·限流组件Sentinel之限流网关 springcloud-alibaba-sentinel-gateway 47 | 12. SpringCloud Alibaba从入门到精通教程(十二)- 项目中快速集成·限流组件Sentinel之断路器 springcloud-alibaba-circuitbreaker-sentinel 48 | 49 | ## 其他 50 | 51 | 1. [SpringCloud从入门到精通教程](https://blog.csdn.net/hemin1003/article/details/82043611) 52 | 53 | 2. [SpringBoot从入门到精通教程](https://blog.csdn.net/hemin1003/article/details/82038244) 54 | 55 | 3. [SpringCloud Alibaba从入门到精通教程](https://blog.csdn.net/hemin1003/article/details/82043611) 56 | 57 | ## [关于我](http://heminit.com/about/) 58 | 59 | 欢迎交流问题,可加我的个人QQ 469580884,或群号 751925591,一起探讨交流问题 60 | 61 | 期望和大家 一起学习,一起成长,共勉,O(∩_∩)O谢谢 62 | 63 | [我的博客地址-博客专家](http://blog.csdn.net/hemin1003) 64 | 65 | [个人域名](http://heminit.com) 66 | 67 | ## 感谢 68 | 如果觉得内容赞,您可以请我喝一杯咖啡: 69 |
70 |      71 | -------------------------------------------------------------------------------- /spring-cloud-greenwich/README.md: -------------------------------------------------------------------------------- 1 | # 项目简介 2 | 3 | SpringCloud微服务框架实战(基于Greenwich版本,SpringBoot2.1.7版本实现) 4 | 5 | 内容主要包含: 6 | 7 | | 微服务角色 | 对应的技术选型 | 8 | | --------------------- | ------------------------------------ | 9 | | 注册中心(Register Server) | Eureka | 10 | | 服务提供者 | spring mvc、spring-data-jpa、h2等 | 11 | | 服务消费者 | Ribbon/Feign消费服务提供者的接口 | 12 | | 熔断器 | Hystrix,包括Hystrix Dashboard以及Turbine | 13 | | 配置服务 | Spring Cloud Config Server | 14 | | API Gateway | Zuul | 15 | | 服务链路追踪 | Sleuth | 16 | 17 | 教程地址有(持续更新中...): 18 | 19 | 1. [SpringCloud从入门到精通教程(一)- 服务的注册与发现(Eureka)](https://hemin.blog.csdn.net/article/details/107317235) 20 | 2. [SpringCloud从入门到精通教程(二)- 服务提供者](https://hemin.blog.csdn.net/article/details/107319172) 21 | 3. [SpringCloud从入门到精通教程(三)- 服务消费者,实现方式一(ribbon)](https://hemin.blog.csdn.net/article/details/107320219) 22 | 4. [SpringCloud从入门到精通教程(四)- 服务消费者,实现方式二(feign)](https://hemin.blog.csdn.net/article/details/107320748) 23 | 5. SpringCloud从入门到精通教程(五)- 高可用的服务注册中心(Eureka) 24 | 6. SpringCloud从入门到精通教程(六)- 断路器/服务消费者(ribbon + hystrix) 25 | 7. SpringCloud从入门到精通教程(七)- 断路器/服务消费者(feign + hystrix) 26 | 8. SpringCloud从入门到精通教程(八)- 动态路由网关(zuul) 27 | 9. SpringCloud从入门到精通教程(九)- 动态路由网关限流(zuul+ratelimit) 28 | 10. SpringCloud从入门到精通教程(十)- 分布式配置中心 29 | 11. SpringCloud从入门到精通教程(十一)- 高可用的分布式配置中心 30 | 12. SpringCloud从入门到精通教程(十二)- 断路器监控(hystrix dashboard) 31 | 13. SpringCloud从入门到精通教程(十三)- 路器聚合监控(hystrix turbine) 32 | 14. SpringCloud从入门到精通教程(十四)- 服务链路追踪 33 | 15. SpringCloud从入门到精通教程(十五)- 消息总线bus 34 | 16. SpringCloud从入门到精通教程(十六)- 网关鉴权认证 35 | 17. SpringCloud从入门到精通教程(十七)- SpringBoot Admin监控台 36 | 18. SpringCloud从入门到精通教程(十八)- 项目实战/微服务架构设计 37 | 38 | # 准备 39 | 40 | ## 环境准备: 41 | 42 | | 工具 | 版本或描述 | 43 | | ----- | -------------------- | 44 | | JDK | 1.8 | 45 | | IDE   | Eclipse 或者 IntelliJ IDEA | 46 | | Maven | 3.x | 47 | 48 | ## 主机名配置: 49 | 50 | | 主机名配置(C:\Windows\System32\drivers\etc\hosts文件) | 51 | | ---------------------------------------- | 52 | | 127.0.0.1 discovery config-server gateway movie user feign ribbon | 53 | 54 | ## 主机规划: 55 | 56 | | 项目名称 | 端口 | 描述 | URL | 57 | | ---------------------------------------- | ---- | ---------------------- | --------------- | 58 | | microservice-api-gateway | 8050 | API Gateway | 详见文章 | 59 | | microservice-config-client | 8041 | 配置服务的客户端 | 详见文章 | 60 | | microservice-config-server | 8040 | 配置服务 | 详见文章 | 61 | | microservice-consumer-movie-feign | 8020 | Feign Demo | | 62 | | microservice-consumer-movie-feign-with-hystrix | 8021 | Feign Hystrix Demo | | 63 | | microservice-consumer-movie-feign-with-hystrix-stream | 8022 | Hystrix Dashboard Demo | | 64 | | microservice-consumer-movie-ribbon | 8010 | Ribbon Demo | | 65 | | microservice-consumer-movie-ribbon-with-hystrix | 8011 | Ribbon Hystrix Demo | | 66 | | microservice-discovery-eureka | 8761 | 注册中心 | | 67 | | microservice-hystrix-dashboard | 8030 | hystrix监控 | | 68 | | microservice-hystrix-turbine | 8031 | turbine | | 69 | | microservice-provider-user | 8000 | 服务提供者 | | 70 | | microservice-consumer-zipkin-hi | 8988 | 服务链路追踪,服务1 | | 71 | | microservice-consumer-zipkin-greet | 8989 | 服务链路追踪,服务2 | | 72 | | | | | | 73 | 74 | [教程说明地址,旧版本文档](https://github.com/hemin1003/spring-cloud-book) 75 | 76 | ## 其他 77 | 78 | 1. [SpringCloud从入门到精通教程](https://blog.csdn.net/hemin1003/article/details/82043611) 79 | 80 | 2. [SpringBoot从入门到精通教程](https://blog.csdn.net/hemin1003/article/details/82038244) 81 | 82 | 3. [SpringCloud Alibaba从入门到精通教程](https://blog.csdn.net/hemin1003/article/details/82043611) 83 | 84 | ## [关于我](http://heminit.com/about/) 85 | 86 | 欢迎交流问题,可加我的个人QQ 469580884,或群号 751925591,一起探讨交流问题 87 | 88 | [我的博客地址-博客专家](http://blog.csdn.net/hemin1003) 89 | 90 | [个人域名](http://heminit.com) 91 | 92 | ## 感谢 93 | 如果觉得内容赞,您可以请我喝一杯咖啡: 94 |
95 |      96 | --------------------------------------------------------------------------------