1 Star 1 Fork 4

小鑫。 / spring-cloud-alibaba-sample

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Without author's permission, this code is only for learning and cannot be used for other purposes.
Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

Spring Cloud Alibaba 例子

参照大雨将至的博客实现。


1、工程结构如下

  • account-service,账号服务,分别调用address-service(Dubbo),payment-service(Fegin)
  • address-service,地址服务
  • payment-service,支付服务
  • sample-gateway,服务网关,代理account-service和payment-service,支持全局日志、鉴权
  • nacos,同github下载、编译结果,github下载较慢
  • sentinel-dashboard.jar,同github下载、编译结果,github下载较慢

2、启动服务

1)启动nacos

cd alibaba-sample/nacos/bin/
sh startup.sh -m standalone

访问地址:http://localhost:8848/nacos
账号:nacos
密码:nacos

增加配置 nacos -> 配置管理 -> 配置列表 -> +

payment-service-dev.properties

Data ID:payment-service-dev.properties
Group:DEFAULT_GROUP
配置格式:Properties
配置内容:

sleep: 0

payment-service-flow-rules

Data ID:payment-service-flow-rules
Group:DEFAULT_GROUP
配置格式:JSON
配置内容:

[
  {
    "resource": "protected-resource",
    "controlBehavior": 0,
    "maxQueueingTimeMs": 20000,
    "count": 1,
    "grade": 1,
    "limitApp": "default",
    "strategy": 0
  }
]

account-service-degrade-rules

Data ID:account-service-degrade-rules
Group:DEFAULT_GROUP
配置格式:JSON
配置内容:

[
  {
    "resource": "GET:http://payment-service/pay/balance",
    "count": 500,
    "grade": 0,
    "timeWindow": 10
  }
]

gateway-router

Data ID:gateway-router
Group:DEFAULT_GROUP
配置格式:JSON
配置内容:

[{
    "id": "account-router",
    "order": 0,
    "predicates": [{
        "args": {
            "pattern": "/account/**"
        }, 
        "name": "Path"
    }],
    "uri": "lb://account-service"
}, 
{
    "id": "payment-router",
    "order": 0,
    "predicates": [{
        "args": {
            "pattern": "/pay/**"
        }, 
        "name": "Path"
    }],
    "uri": "lb://payment-service"
}]

2)启动sentinel

cd alibaba-sample/
java -Dserver.port=8080 -Dcsp.sentinel.dashboard.server=localhost:8080 -Dproject.name=sentinel-dashboard -jar sentinel-dashboard.jar

访问地址:http://localhost:8080/
账号:sentinel
密码:sentinel

3)启动payment-service

cd alibaba-sample/payment-service/
mvn clean package
cd target/

java -jar payment-service-1.0.0-SNAPSHOT.jar --server.port=8082
java -jar payment-service-1.0.0-SNAPSHOT.jar --server.port=8083

查看 nacos -> 服务管理 -> 服务列表,payment-service已经注册上

测试连通性:
http://localhost:8082/pay/balance?id=1
http://localhost:8083/pay/balance?id=1

4)启动address-service

cd alibaba-sample/address-service/
mvn clean package
cd target/

java -jar address-service-1.0.0-SNAPSHOT.jar

查看 nacos -> 服务管理 -> 服务列表,address-service已经注册上

5)启动account-service

cd alibaba-sample/account-service/
mvn clean package
cd target/

java -jar account-service-1.0.0-SNAPSHOT.jar --server.port=8081

查看 nacos -> 服务管理 -> 服务列表,account-service已经注册上

测试连通性:
http://localhost:8081/account/user?id=1

6)启动sample-gateway

cd alibaba-sample/sample-gateway/
mvn clean package
cd target/

java -jar sample-gateway-1.0.0-SNAPSHOT.jar --server.port=8084

测试连通性:
http://localhost:8084/account/user?id=1

Repository Comments ( 0 )

Sign in for post a comment

About

Spring Cloud Alibaba 例子 expand collapse
Cancel

Releases

No release

Contributors

All

Activities

load more
can not load any more
Java
1
https://gitee.com/renxin-327666062/spring-cloud-alibaba-sample.git
git@gitee.com:renxin-327666062/spring-cloud-alibaba-sample.git
renxin-327666062
spring-cloud-alibaba-sample
spring-cloud-alibaba-sample
master

Search

181749 a2d7925e 1850385 181749 9f8568a7 1850385