# spring-cloud **Repository Path**: dormi/spring-cloud ## Basic Information - **Project Name**: spring-cloud - **Description**: spring-cloud技术堆栈 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-11-10 - **Last Updated**: 2020-12-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # branch - master - jaeger - sleuth的发送方式 web - zuul stripPrefix=false - zuul 添加 x-request-id - 异常捕获时, 如果有x-request-id, 则上报(实现TODO) - sentry - 异常时, 实现上报sentry # spring-cloud - spring boot版本 2.0.3 - spring cloud Finchely - 使用 properties , yml更不好看 # 用到的域名 - 基础设施 - dns服务 使用dns服务 53/udp 减少配置ip地址带来的繁琐和易错 - mysql.ms.io 3306 (192.168.31.102) - redis.ms.io 6379 (192.168.31.102) - rabbitmq.ms.io 5672, web端口 15672 (192.168.31.102) - 基础服务 - eureka.ms.io 8761, web端口 8761 (192.168.31.101) - gateway.ms.io 9000 (192.168.31.101) - zipkin.ms.io 9411 (192.168.31.101) - config.ms.io 8910 # 启动顺序 ### 基础服务 - mysql - rabbitmq ### spring cloud的 基础服务 - eureka - zipkin - gateway - config-server - 可选: spring-boot-admin ### demo 服务 - shop-center @ 9010 (实例2 @ 9011) - ruok接口 ``` curl -H "x-request-id: abcdefg" http://localhost:9010/shop/ruok?name=abc hi abc ,i am from port:9010 ``` - 异常接口 ``` curl -H "x-request-id: 123" http://localhost:9010/shop/wrong ``` - 测试对外的一个接口 ``` curl http://localhost:9010/shop/shops [ {"shopId":"id_001","name":"shop_001","sellerId":"seller_001"}, {"shopId":"id_002","name":"shop_002","sellerId":"seller_001"}, {"shopId":"id_003","name":"shop_003","sellerId":"seller_002"} ] ``` - trade-center @ 9020 - ruok接口 ``` curl http://localhost:9020/trade/ruok imok ``` - 调用 shop-center的测试 ``` curl -H "x-request-id: ffffff" http://localhost:9020/trade/hi-shop?name=aaa hi aaa ,i am from port:9010 ``` - 配置中心测试 ``` curl http://localhost:9020/trade/hi-config author=dormi330-v2, tradeName=sales-dev ``` - trade-center-feign @ 9030 - ruok接口 ``` curl http://localhost:9030/trade-feign/ruok imok ``` - 通过trade 访问shop ruok接口 ``` curl http://localhost:9030/trade-feign/hi-shop?name=11 hi 11 ,i am from port:9010 ``` - loadBalancerClient 检测 ``` curl http://localhost:9030/trade-feign/hi2 shop-service:172.17.0.5:9010 ``` - 配置中心检测 ``` curl http://localhost:9030/trade-feign/hi3 jdbc:mysql://foobar?a=1 ``` - 通过 FeignClient调用 shop的服务 ``` curl http://localhost:9030/trade-feign/shops [ {"shopId":"id_001","name":"shop_001","sellerId":"seller_001"}, {"shopId":"id_002","name":"shop_002","sellerId":"seller_001"}, {"shopId":"id_003","name":"shop_003","sellerId":"seller_002"} ] ``` - 通过 FeignClient调用 shop的服务 POST ``` curl -XPOST -H "content-type: application/json" -d '{"name":"shop_001","sellerId":"seller_001"}' http://localhost:9030/trade-feign/shops/id007 {"shopId":"id007","name":"from port9010","sellerId":"seller_001"} ``` - gateway - 调用shop ```bash # 正常接口 curl -i http://localhost:9000/shop/ruok?name=aaa http://111.230.140.238:9000/shop/ruok?name=aaa # 异常接口 curl -i http://localhost:9000/shop/wrong http://111.230.140.238:9000/shop/wrong ``` - 调用 trade -> shop ```bash # 正常接口 curl http://localhost:9000/trade/hi-shop?name=aaa http://111.230.140.238:9000/trade/hi-shop?name=aaa # 异常接口 curl http://localhost:9000/trade/shop-wrong http://111.230.140.238:9000/trade/shop-wrong ``` - 调用 trade-feign -> shop ```bash # 正常接口1 curl http://localhost:9000/trade-feign/ruok http://111.230.140.238:9000/trade-feign/ruok # 正常接口2 curl http://localhost:9000/trade-feign/shops http://111.230.140.238:9000/trade-feign/shops # 正常接口3 curl http://localhost:9000/trade-feign/thread?mock=1 http://111.230.140.238:9000/trade-feign/thread http://111.230.140.238:9000/trade-feign/thread?mock=1 ``` ### 注意事项 - zipkin的send模式 web/rabbit/kafka - http://cloud.spring.io/spring-cloud-static/Finchley.SR1/multi/multi__sending_spans_to_zipkin.html ``` If you have web, rabbit, or kafka together on the classpath, you might need to pick the means by which you would like to send spans to zipkin. To do so, set web, rabbit, or kafka to the spring.zipkin.sender.type property. The following example shows setting the sender type for web: spring.zipkin.sender.type: web ```