├── shop-order
├── src
│ ├── main
│ │ ├── resources
│ │ │ ├── registry.conf
│ │ │ ├── META-INF
│ │ │ │ └── services
│ │ │ │ │ └── com.alibaba.csp.sentinel.init.InitFunc
│ │ │ ├── bootstrap.yml
│ │ │ └── application.yml
│ │ └── java
│ │ │ └── com
│ │ │ └── ylesb
│ │ │ ├── service
│ │ │ ├── OrderService.java
│ │ │ ├── fallback
│ │ │ │ ├── ProductServiceFallback.java
│ │ │ │ └── ProductServiceFallbackFactory.java
│ │ │ ├── ProductService.java
│ │ │ └── Impl
│ │ │ │ ├── OrderServiceImpl.java
│ │ │ │ ├── OrderServiceImpl4.java
│ │ │ │ └── OrderServiceImpl4Listener.java
│ │ │ ├── dao
│ │ │ ├── OrderDao.java
│ │ │ └── TxLogDao.java
│ │ │ ├── config
│ │ │ ├── RequestOriginParserDefinition.java
│ │ │ ├── DataSourceProxyConfig.java
│ │ │ ├── FilterContextConfig.java
│ │ │ ├── ExceptionHandlerPage.java
│ │ │ └── SentinelPerFile.java
│ │ │ ├── OrderApplication.java
│ │ │ └── controller
│ │ │ └── OrderController.java
│ └── test
│ │ └── java
│ │ └── com
│ │ └── ylesb
│ │ └── test
│ │ ├── RocketMQSendMessageTest.java
│ │ ├── RocketMQReceiveMessageTest.java
│ │ └── MessageTypeTest.java
└── pom.xml
├── shop-product
├── src
│ └── main
│ │ ├── resources
│ │ ├── registry.conf
│ │ ├── bootstrap.yml
│ │ └── application.yml
│ │ └── java
│ │ └── com
│ │ └── ylesb
│ │ ├── service
│ │ ├── ProductService.java
│ │ └── Impl
│ │ │ └── ProductServiceImpl.java
│ │ ├── dao
│ │ └── ProductDao.java
│ │ ├── ProductApplication.java
│ │ └── controller
│ │ ├── ProductController.java
│ │ └── NacosConfigController.java
└── pom.xml
├── .idea
├── sonarlint
│ └── issuestore
│ │ ├── 0
│ │ └── 9
│ │ │ └── 0928ba6e2cffe4166f5c3ab64de7bc445f4e208e
│ │ ├── 1
│ │ └── 1
│ │ │ └── 11d4ae3540bd3ee68869159f2e91fa98a53fbca4
│ │ ├── 2
│ │ ├── 1
│ │ │ └── 213ee4e238faba65620cd36d566843b51fcd751f
│ │ ├── 3
│ │ │ └── 236ef979e7572213fd643c3812f2a62c8e50b24a
│ │ ├── 4
│ │ │ └── 24f7252c088074c20f91b45090cad09e0d694c73
│ │ └── 7
│ │ │ └── 2711291225762af7a6173841dfb254d5f722b4d3
│ │ ├── 3
│ │ ├── 0
│ │ │ └── 3005242601e77842ac4e69cbb0073bdefe6d2c41
│ │ └── 6
│ │ │ └── 36aefbee7c006082cf5d703a560ce3c555feeb34
│ │ ├── 4
│ │ ├── 4
│ │ │ └── 44f102bba6fc721245bab5489c88911a94f0d9f8
│ │ ├── 7
│ │ │ └── 472bb416ca51cbc9e5a9f43ab80f0a3480921ffb
│ │ └── a
│ │ │ └── 4a0be6d6a038d77b6e8a916317c41da6ed59ab10
│ │ ├── 5
│ │ ├── 0
│ │ │ └── 505008e8e4da7ea22194e15f2f6f20d7874b64fe
│ │ └── 6
│ │ │ └── 56f98614feebc2019683e030777aaa904f568b78
│ │ ├── 6
│ │ ├── 4
│ │ │ └── 647297c66842b3761c1189cb5456840faa65ca8f
│ │ └── c
│ │ │ └── 6c5d76c25c491ea695cb2902c9cb700662375f92
│ │ ├── 7
│ │ ├── 0
│ │ │ └── 7059f0b779ea1a33af38bd0b3f8d12a65aba80ca
│ │ ├── 2
│ │ │ └── 72319cf6c40cb6df2959833e20123eeffe34d1b2
│ │ ├── 6
│ │ │ └── 76552bdff6427451d79de118d894e3b79f082b94
│ │ ├── 8
│ │ │ └── 78ddc04ca59e5d9a9bf2616d0ab76e288052194b
│ │ └── d
│ │ │ └── 7de90c31e5e90655897ede778c7d5d9ea59b74f8
│ │ ├── 8
│ │ ├── 5
│ │ │ └── 8513f321fcbbc1565b61394a71ebcc883040a432
│ │ ├── 9
│ │ │ └── 89c5fc7175670a4f44577174d35234b1a64c2768
│ │ └── d
│ │ │ └── 8dcbc6d61d26232e0f442a49e2e46de39769dd88
│ │ ├── 9
│ │ ├── 4
│ │ │ └── 949a8145879f31377e92fa7189f7355b89758bbf
│ │ ├── 6
│ │ │ └── 964333860ed7710b90af18a3617c2938c36fd048
│ │ └── 9
│ │ │ └── 99a509f41223f089f13c1a9ab4c9f1cde37b4943
│ │ ├── c
│ │ ├── 3
│ │ │ ├── c32bcbe79fab5fe711f0ac6bc0ec73560e938cb9
│ │ │ └── c3d8ddc09af2debf37c58f59732ce77011d06e33
│ │ ├── 5
│ │ │ └── c57a7b84b73a7ab7efe5f6a77bc7e35d0f75e065
│ │ ├── c
│ │ │ └── cc278e1a27309addb0393ad241c826b847ba2887
│ │ ├── b
│ │ │ └── cbc83b1ab5d14bb36447f01a5b394781db01af84
│ │ └── d
│ │ │ └── cd288a5dada90e55748e2d06ee84ec99d261e58e
│ │ ├── f
│ │ ├── 1
│ │ │ └── f1ceb92f280498c317e09d71d67f185aadb300db
│ │ ├── c
│ │ │ └── fc06f89e6644376351bb58592cb2386c11cd039b
│ │ └── d
│ │ │ └── fde9cddf8e62379d57406632ecad2295da6ad48c
│ │ ├── a
│ │ ├── 6
│ │ │ └── a603f92bc83d339cca3ff5b8808683fdfbd204da
│ │ └── c
│ │ │ └── ac20e1ce462c40999d85f23a3e3932c3a6e98682
│ │ ├── b
│ │ ├── 4
│ │ │ └── b4cc193d466ce22194f126a9e4779768cf29c0b6
│ │ ├── 7
│ │ │ └── b7b1486670ebe9b83a0134a783045cf150feeecb
│ │ └── d
│ │ │ ├── bd5dca7770f938d1891a0c35f2b240276bfc83f0
│ │ │ └── bdf2a4429bbe7a2a4b988d981a2b45515c74e94b
│ │ ├── d
│ │ └── c
│ │ │ └── dc062cabc777b78f4ae527db39c5a09d2c74a2e8
│ │ ├── e
│ │ ├── 4
│ │ │ └── e495d167eecefaf0dea74d910635af84daac615b
│ │ ├── 6
│ │ │ └── e60cb1edca3c414ebffc07aaa956a0c26f3832b0
│ │ └── b
│ │ │ └── eb97a1dfef77a812f0cabe4e1894299acf69074c
│ │ └── index.pb
├── vcs.xml
├── .gitignore
├── jpa-buddy.xml
├── setting.xml
├── misc.xml
├── git_toolbox_prj.xml
├── encodings.xml
├── jarRepositories.xml
├── compiler.xml
├── inspectionProfiles
│ └── Project_Default.xml
└── uiDesigner.xml
├── .gitignore
├── shop-user
├── src
│ └── main
│ │ ├── java
│ │ └── com
│ │ │ └── ylesb
│ │ │ ├── service
│ │ │ ├── UserService.java
│ │ │ ├── Impl
│ │ │ │ └── UserServiceImpl.java
│ │ │ └── SmsService.java
│ │ │ ├── controller
│ │ │ └── UserController.java
│ │ │ ├── dao
│ │ │ └── UserDao.java
│ │ │ └── UserApplication.java
│ │ └── resources
│ │ └── application.yml
└── pom.xml
├── shop-commom
├── src
│ └── main
│ │ └── java
│ │ └── com
│ │ └── ylesb
│ │ └── domain
│ │ ├── TxLog.java
│ │ ├── User.java
│ │ ├── Product.java
│ │ └── Order.java
└── pom.xml
├── api-gateway
├── src
│ └── main
│ │ ├── resources
│ │ └── application.yml
│ │ └── java
│ │ └── com
│ │ └── ylesb
│ │ ├── ApiGatewayApplication.java
│ │ ├── filters
│ │ ├── AuthGlobaFilter.java
│ │ └── LogGatewayFilterFactory.java
│ │ ├── predicates
│ │ └── AgeRoutePredicateFactory.java
│ │ └── config
│ │ └── GatewayConfiguration.java
└── pom.xml
├── pom.xml
└── README.md
/shop-order/src/main/resources/registry.conf:
--------------------------------------------------------------------------------
1 | #和seata中的conf目录下的一致
--------------------------------------------------------------------------------
/shop-product/src/main/resources/registry.conf:
--------------------------------------------------------------------------------
1 | #和seata中的conf目录下的一致
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/2/1/213ee4e238faba65620cd36d566843b51fcd751f:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/3/0/3005242601e77842ac4e69cbb0073bdefe6d2c41:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/4/a/4a0be6d6a038d77b6e8a916317c41da6ed59ab10:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/5/6/56f98614feebc2019683e030777aaa904f568b78:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/7/8/78ddc04ca59e5d9a9bf2616d0ab76e288052194b:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/8/5/8513f321fcbbc1565b61394a71ebcc883040a432:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/9/4/949a8145879f31377e92fa7189f7355b89758bbf:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/9/6/964333860ed7710b90af18a3617c2938c36fd048:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/c/c/cc278e1a27309addb0393ad241c826b847ba2887:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/f/1/f1ceb92f280498c317e09d71d67f185aadb300db:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/f/c/fc06f89e6644376351bb58592cb2386c11cd039b:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Project exclude paths
2 | /shop-commom/target/
3 | /shop-product/target/
--------------------------------------------------------------------------------
/shop-order/src/main/resources/META-INF/services/com.alibaba.csp.sentinel.init.InitFunc:
--------------------------------------------------------------------------------
1 | com.ylesb.config.SentinelPerFile
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/0/9/0928ba6e2cffe4166f5c3ab64de7bc445f4e208e:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/0/9/0928ba6e2cffe4166f5c3ab64de7bc445f4e208e
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/1/1/11d4ae3540bd3ee68869159f2e91fa98a53fbca4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/1/1/11d4ae3540bd3ee68869159f2e91fa98a53fbca4
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/2/3/236ef979e7572213fd643c3812f2a62c8e50b24a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/2/3/236ef979e7572213fd643c3812f2a62c8e50b24a
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/2/4/24f7252c088074c20f91b45090cad09e0d694c73:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/2/4/24f7252c088074c20f91b45090cad09e0d694c73
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/2/7/2711291225762af7a6173841dfb254d5f722b4d3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/2/7/2711291225762af7a6173841dfb254d5f722b4d3
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/3/6/36aefbee7c006082cf5d703a560ce3c555feeb34:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/3/6/36aefbee7c006082cf5d703a560ce3c555feeb34
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/4/4/44f102bba6fc721245bab5489c88911a94f0d9f8:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/4/4/44f102bba6fc721245bab5489c88911a94f0d9f8
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/4/7/472bb416ca51cbc9e5a9f43ab80f0a3480921ffb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/4/7/472bb416ca51cbc9e5a9f43ab80f0a3480921ffb
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/5/0/505008e8e4da7ea22194e15f2f6f20d7874b64fe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/5/0/505008e8e4da7ea22194e15f2f6f20d7874b64fe
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/6/4/647297c66842b3761c1189cb5456840faa65ca8f:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/6/4/647297c66842b3761c1189cb5456840faa65ca8f
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/6/c/6c5d76c25c491ea695cb2902c9cb700662375f92:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/6/c/6c5d76c25c491ea695cb2902c9cb700662375f92
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/7/0/7059f0b779ea1a33af38bd0b3f8d12a65aba80ca:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/7/0/7059f0b779ea1a33af38bd0b3f8d12a65aba80ca
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/7/2/72319cf6c40cb6df2959833e20123eeffe34d1b2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/7/2/72319cf6c40cb6df2959833e20123eeffe34d1b2
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/7/6/76552bdff6427451d79de118d894e3b79f082b94:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/7/6/76552bdff6427451d79de118d894e3b79f082b94
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/7/d/7de90c31e5e90655897ede778c7d5d9ea59b74f8:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/7/d/7de90c31e5e90655897ede778c7d5d9ea59b74f8
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/8/9/89c5fc7175670a4f44577174d35234b1a64c2768:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/8/9/89c5fc7175670a4f44577174d35234b1a64c2768
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/8/d/8dcbc6d61d26232e0f442a49e2e46de39769dd88:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/8/d/8dcbc6d61d26232e0f442a49e2e46de39769dd88
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/9/9/99a509f41223f089f13c1a9ab4c9f1cde37b4943:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/9/9/99a509f41223f089f13c1a9ab4c9f1cde37b4943
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/a/6/a603f92bc83d339cca3ff5b8808683fdfbd204da:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/a/6/a603f92bc83d339cca3ff5b8808683fdfbd204da
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/a/c/ac20e1ce462c40999d85f23a3e3932c3a6e98682:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/a/c/ac20e1ce462c40999d85f23a3e3932c3a6e98682
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/b/4/b4cc193d466ce22194f126a9e4779768cf29c0b6:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/b/4/b4cc193d466ce22194f126a9e4779768cf29c0b6
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/b/7/b7b1486670ebe9b83a0134a783045cf150feeecb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/b/7/b7b1486670ebe9b83a0134a783045cf150feeecb
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/b/d/bd5dca7770f938d1891a0c35f2b240276bfc83f0:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/b/d/bd5dca7770f938d1891a0c35f2b240276bfc83f0
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/b/d/bdf2a4429bbe7a2a4b988d981a2b45515c74e94b:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/b/d/bdf2a4429bbe7a2a4b988d981a2b45515c74e94b
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/c/3/c32bcbe79fab5fe711f0ac6bc0ec73560e938cb9:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/c/3/c32bcbe79fab5fe711f0ac6bc0ec73560e938cb9
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/c/3/c3d8ddc09af2debf37c58f59732ce77011d06e33:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/c/3/c3d8ddc09af2debf37c58f59732ce77011d06e33
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/c/5/c57a7b84b73a7ab7efe5f6a77bc7e35d0f75e065:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/c/5/c57a7b84b73a7ab7efe5f6a77bc7e35d0f75e065
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/c/b/cbc83b1ab5d14bb36447f01a5b394781db01af84:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/c/b/cbc83b1ab5d14bb36447f01a5b394781db01af84
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/c/d/cd288a5dada90e55748e2d06ee84ec99d261e58e:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/c/d/cd288a5dada90e55748e2d06ee84ec99d261e58e
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/d/c/dc062cabc777b78f4ae527db39c5a09d2c74a2e8:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/d/c/dc062cabc777b78f4ae527db39c5a09d2c74a2e8
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/e/4/e495d167eecefaf0dea74d910635af84daac615b:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/e/4/e495d167eecefaf0dea74d910635af84daac615b
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/e/6/e60cb1edca3c414ebffc07aaa956a0c26f3832b0:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/e/6/e60cb1edca3c414ebffc07aaa956a0c26f3832b0
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/e/b/eb97a1dfef77a812f0cabe4e1894299acf69074c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/e/b/eb97a1dfef77a812f0cabe4e1894299acf69074c
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/f/d/fde9cddf8e62379d57406632ecad2295da6ad48c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CoderXGC/springcloud-alibaba/HEAD/.idea/sonarlint/issuestore/f/d/fde9cddf8e62379d57406632ecad2295da6ad48c
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/.idea/jpa-buddy.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/setting.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/shop-order/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: service-order
4 | cloud:
5 | nacos:
6 | config:
7 | server-addr: 127.0.0.1:8848 #nacos服务端地址
8 | file-extension: yml #配置格式
9 | namespace: public
10 | group: SEATA_GROUP
11 | alibaba:
12 | seata:
13 | tx-service-group: ${spring.application.name}
14 | profiles:
15 | active: dev #配置环境
16 |
--------------------------------------------------------------------------------
/shop-product/src/main/resources/bootstrap.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | application:
3 | name: service-product
4 | cloud:
5 | nacos:
6 | config:
7 | server-addr: 127.0.0.1:8848 #nacos服务端地址
8 | file-extension: yml #配置格式
9 | namespace: public
10 | group: SEATA_GROUP
11 | alibaba:
12 | seata:
13 | tx-service-group: ${spring.application.name} #与seata中的配置名称一致service-product
14 | profiles:
15 | active: dev #配置环境
16 |
--------------------------------------------------------------------------------
/shop-user/src/main/java/com/ylesb/service/UserService.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.service;
2 | /**
3 | * @title: UserService
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1115:38
9 | */
10 |
11 | /**
12 | * @className : UserService
13 | * @description : [描述说明该类的功能]
14 | * @author : [XuGuangchao]
15 | * @site : [www.ylesb.com]
16 | * @version : [v1.0]
17 | * @createTime : [2022/1/11 15:38]
18 | * @updateUser : [XuGuangchao]
19 | * @updateTime : [2022/1/11 15:38]
20 | * @updateRemark : [描述说明本次修改内容]
21 | */
22 | public interface UserService {
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/shop-order/src/main/java/com/ylesb/service/OrderService.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.service;
2 | /**
3 | * @title: UserService
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1115:38
9 | */
10 |
11 | import com.ylesb.domain.Order;
12 |
13 | /**
14 | * @className : UserService
15 | * @description : [描述说明该类的功能]
16 | * @author : [XuGuangchao]
17 | * @site : [www.ylesb.com]
18 | * @version : [v1.0]
19 | * @createTime : [2022/1/11 15:38]
20 | * @updateUser : [XuGuangchao]
21 | * @updateTime : [2022/1/11 15:38]
22 | * @updateRemark : [描述说明本次修改内容]
23 | */
24 | public interface OrderService {
25 | void createOrder(Order order);
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/shop-user/src/main/java/com/ylesb/service/Impl/UserServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.service.Impl;
2 | /**
3 | * @title: UserServiceImpl
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1115:39
9 | */
10 |
11 | import com.ylesb.service.UserService;
12 |
13 | /**
14 | * @className : UserServiceImpl
15 | * @description : [描述说明该类的功能]
16 | * @author : [XuGuangchao]
17 | * @site : [www.ylesb.com]
18 | * @version : [v1.0]
19 | * @createTime : [2022/1/11 15:39]
20 | * @updateUser : [XuGuangchao]
21 | * @updateTime : [2022/1/11 15:39]
22 | * @updateRemark : [描述说明本次修改内容]
23 | */
24 |
25 | public class UserServiceImpl implements UserService {
26 | }
27 |
--------------------------------------------------------------------------------
/.idea/git_toolbox_prj.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/shop-product/src/main/java/com/ylesb/service/ProductService.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.service;
2 | /**
3 | * @title: UserService
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1115:38
9 | */
10 |
11 | import com.ylesb.domain.Product;
12 |
13 | /**
14 | * @className : UserService
15 | * @description : [描述说明该类的功能]
16 | * @author : [XuGuangchao]
17 | * @site : [www.ylesb.com]
18 | * @version : [v1.0]
19 | * @createTime : [2022/1/11 15:38]
20 | * @updateUser : [XuGuangchao]
21 | * @updateTime : [2022/1/11 15:38]
22 | * @updateRemark : [描述说明本次修改内容]
23 | */
24 | public interface ProductService {
25 |
26 | Product findByPid(Integer pid);
27 | }
28 |
29 |
--------------------------------------------------------------------------------
/shop-product/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8081
3 | spring:
4 | application:
5 | name: service-product
6 | zipkin:
7 | base-url: http://127.0.0.1:9411
8 | discovery-client-enabled: false #让nacos把它当成一个url不要做服务名
9 | sleuth:
10 | sampler:
11 | probability: 1.0 #采样的百分比
12 | datasource:
13 | driver-class-name: com.mysql.cj.jdbc.Driver
14 | url: jdbc:mysql://localhost:3306/shop?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&userSSL=true
15 | username: root
16 | password: 123456
17 | jap:
18 | hibernate:
19 | hb2ddl:
20 | auto: update
21 | dialect: org.hibernate.dialect.MySQL5InnoDBialect
22 | cloud:
23 | nacos:
24 | discovery:
25 | server-addr: localhost:8848
26 |
--------------------------------------------------------------------------------
/shop-user/src/main/java/com/ylesb/controller/UserController.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.controller;
2 | /**
3 | * @title: UserController
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1115:38
9 | */
10 |
11 | import org.springframework.web.bind.annotation.RestController;
12 |
13 | /**
14 | * @className : UserController
15 | * @description : [描述说明该类的功能]
16 | * @author : [XuGuangchao]
17 | * @site : [www.ylesb.com]
18 | * @version : [v1.0]
19 | * @createTime : [2022/1/11 15:38]
20 | * @updateUser : [XuGuangchao]
21 | * @updateTime : [2022/1/11 15:38]
22 | * @updateRemark : [描述说明本次修改内容]
23 | */
24 |
25 | @RestController
26 | public class ProductController {
27 | }
28 |
--------------------------------------------------------------------------------
/shop-user/src/main/java/com/ylesb/dao/UserDao.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.dao;
2 | /**
3 | * @title: UserDao
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1115:40
9 | */
10 |
11 | import com.ylesb.domain.User;
12 | import org.springframework.data.jpa.repository.JpaRepository;
13 |
14 | /**
15 | * @className : UserDao
16 | * @description : [描述说明该类的功能]
17 | * @author : [XuGuangchao]
18 | * @site : [www.ylesb.com]
19 | * @version : [v1.0]
20 | * @createTime : [2022/1/11 15:40]
21 | * @updateUser : [XuGuangchao]
22 | * @updateTime : [2022/1/11 15:40]
23 | * @updateRemark : [描述说明本次修改内容]
24 | */
25 | public interface UserDao extends JpaRepository {
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/shop-order/src/main/java/com/ylesb/dao/OrderDao.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.dao;
2 | /**
3 | * @title: UserDao
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1115:40
9 | */
10 |
11 | import com.ylesb.domain.Order;
12 | import com.ylesb.domain.User;
13 | import org.springframework.data.jpa.repository.JpaRepository;
14 |
15 | /**
16 | * @className : UserDao
17 | * @description : [描述说明该类的功能]
18 | * @author : [XuGuangchao]
19 | * @site : [www.ylesb.com]
20 | * @version : [v1.0]
21 | * @createTime : [2022/1/11 15:40]
22 | * @updateUser : [XuGuangchao]
23 | * @updateTime : [2022/1/11 15:40]
24 | * @updateRemark : [描述说明本次修改内容]
25 | */
26 | public interface OrderDao extends JpaRepository {
27 | }
28 |
29 |
--------------------------------------------------------------------------------
/shop-order/src/main/java/com/ylesb/dao/TxLogDao.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.dao;
2 | /**
3 | * @title: UserDao
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1115:40
9 | */
10 |
11 | import com.ylesb.domain.Order;
12 | import com.ylesb.domain.TxLog;
13 | import org.springframework.data.jpa.repository.JpaRepository;
14 |
15 | /**
16 | * @className : UserDao
17 | * @description : [描述说明该类的功能]
18 | * @author : [XuGuangchao]
19 | * @site : [www.ylesb.com]
20 | * @version : [v1.0]
21 | * @createTime : [2022/1/11 15:40]
22 | * @updateUser : [XuGuangchao]
23 | * @updateTime : [2022/1/11 15:40]
24 | * @updateRemark : [描述说明本次修改内容]
25 | */
26 | public interface TxLogDao extends JpaRepository {
27 | }
28 |
29 |
--------------------------------------------------------------------------------
/shop-product/src/main/java/com/ylesb/dao/ProductDao.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.dao;
2 | /**
3 | * @title: UserDao
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1115:40
9 | */
10 |
11 | import com.ylesb.domain.Product;
12 | import com.ylesb.domain.User;
13 | import org.springframework.data.jpa.repository.JpaRepository;
14 |
15 | /**
16 | * @className : UserDao
17 | * @description : [描述说明该类的功能]
18 | * @author : [XuGuangchao]
19 | * @site : [www.ylesb.com]
20 | * @version : [v1.0]
21 | * @createTime : [2022/1/11 15:40]
22 | * @updateUser : [XuGuangchao]
23 | * @updateTime : [2022/1/11 15:40]
24 | * @updateRemark : [描述说明本次修改内容]
25 | */
26 | public interface ProductDao extends JpaRepository {
27 | }
28 |
29 |
--------------------------------------------------------------------------------
/shop-user/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8071
3 | spring:
4 | application:
5 | name: service-user
6 | zipkin:
7 | base-url: http://127.0.0.1:9411
8 | discovery-client-enabled: false #让nacos把它当成一个url不要做服务名
9 | sleuth:
10 | sampler:
11 | probability: 1.0 #采样的百分比 正式环境要比较小,因为是100%上报
12 | datasource:
13 | driver-class-name: com.mysql.cj.jdbc.Driver
14 | url: jdbc:mysql://localhost:3306/shop?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&userSSL=true
15 | username: root
16 | password: 123456
17 | jap:
18 | hibernate:
19 | hb2ddl:
20 | auto: update
21 | dialect: org.hibernate.dialect.MySQL5InnoDBialect
22 | cloud:
23 | nacos:
24 | discovery:
25 | server-addr: localhost:8848
26 | #rocketMQ
27 | rocketmq:
28 | name-server: 192.168.109.131:9876 #rocketMQ服务地址
--------------------------------------------------------------------------------
/shop-commom/src/main/java/com/ylesb/domain/TxLog.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.domain;
2 | /**
3 | * @title: TxLog
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1317:14
9 | */
10 |
11 | import lombok.Data;
12 |
13 | import javax.persistence.Entity;
14 | import javax.persistence.Id;
15 | import java.util.Date;
16 |
17 | /**
18 | * @className : TxLog
19 | * @description : [描述说明该类的功能]
20 | * @author : [XuGuangchao]
21 | * @site : [www.ylesb.com]
22 | * @version : [v1.0]
23 | * @createTime : [2022/1/13 17:14]
24 | * @updateUser : [XuGuangchao]
25 | * @updateTime : [2022/1/13 17:14]
26 | * @updateRemark : [描述说明本次修改内容]
27 | */
28 | @Data
29 | @Entity(name = "shop_txlog")
30 | //消息事务状态记录
31 | public class TxLog {
32 | @Id
33 | private String txId;
34 | private Date date;
35 | }
36 |
--------------------------------------------------------------------------------
/api-gateway/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 7000
3 | spring:
4 | application:
5 | name: api-gateway
6 | zipkin:
7 | base-url: http://127.0.0.1:9411
8 | discovery-client-enabled: false #让nacos把它当成一个url不要做服务名
9 | sleuth:
10 | sampler:
11 | probability: 0.1 #采样的百分比
12 | cloud:
13 | nacos:
14 | discovery:
15 | server-addr: localhost:8848 #注册到nacoos
16 | gateway:
17 | discovery:
18 | locator:
19 | enabled: true #让gateway可以发现nacos中的微服务
20 | routes: #路由数组可以放多个路由。满足什么条件转发到哪个微服务上
21 | - id: product_route #当前路由标识,默认uuid
22 | # uri: http://localhost:8081 #要转发的地址
23 | uri: lb:service-prooduct #lb负载均衡 后面是具体微服务的标识
24 | order: 1 #路由越小优先级越高
25 | predicates: #断言(条件判断,返回值是bool,满足条件的)可以自定义路由配置详情看AGEROUTER
26 | - Path=/product-serv/** #当请求的规则满足
27 | filters: #过滤器 自定义过滤器Log
28 | - StripPrefix=1 #在请求转发路径去掉一层
29 | - Log=ture,false
--------------------------------------------------------------------------------
/shop-user/src/main/java/com/ylesb/UserApplication.java:
--------------------------------------------------------------------------------
1 | package com.ylesb;
2 | /**
3 | * @title: UserApplication
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1115:28
9 | */
10 |
11 | import org.springframework.boot.SpringApplication;
12 | import org.springframework.boot.autoconfigure.SpringBootApplication;
13 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
14 |
15 | /**
16 | * @className : UserApplication
17 | * @description : [描述说明该类的功能]
18 | * @author : [XuGuangchao]
19 | * @site : [www.ylesb.com]
20 | * @version : [v1.0]
21 | * @createTime : [2022/1/11 15:28]
22 | * @updateUser : [XuGuangchao]
23 | * @updateTime : [2022/1/11 15:28]
24 | * @updateRemark : [描述说明本次修改内容]
25 | */
26 | @SpringBootApplication
27 | @EnableDiscoveryClient
28 | public class UserApplication {
29 | public static void main(String[] args) {
30 | SpringApplication.run(UserApplication.class);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/shop-product/src/main/java/com/ylesb/ProductApplication.java:
--------------------------------------------------------------------------------
1 | package com.ylesb;
2 | /**
3 | * @title: UserApplication
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1115:28
9 | */
10 |
11 | import org.springframework.boot.SpringApplication;
12 | import org.springframework.boot.autoconfigure.SpringBootApplication;
13 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
14 |
15 | /**
16 | * @className : UserApplication
17 | * @description : [描述说明该类的功能]
18 | * @author : [XuGuangchao]
19 | * @site : [www.ylesb.com]
20 | * @version : [v1.0]
21 | * @createTime : [2022/1/11 15:28]
22 | * @updateUser : [XuGuangchao]
23 | * @updateTime : [2022/1/11 15:28]
24 | * @updateRemark : [描述说明本次修改内容]
25 | */
26 | @SpringBootApplication
27 | @EnableDiscoveryClient
28 | public class ProductApplication {
29 | public static void main(String[] args) {
30 | SpringApplication.run(ProductApplication.class);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/api-gateway/src/main/java/com/ylesb/ApiGatewayApplication.java:
--------------------------------------------------------------------------------
1 | package com.ylesb;
2 | /**
3 | * @title: ApiApplication
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1217:00
9 | */
10 |
11 | import org.springframework.boot.SpringApplication;
12 | import org.springframework.boot.autoconfigure.SpringBootApplication;
13 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
14 |
15 | /**
16 | * @className : ApiApplication
17 | * @description : [描述说明该类的功能]
18 | * @author : [XuGuangchao]
19 | * @site : [www.ylesb.com]
20 | * @version : [v1.0]
21 | * @createTime : [2022/1/12 17:00]
22 | * @updateUser : [XuGuangchao]
23 | * @updateTime : [2022/1/12 17:00]
24 | * @updateRemark : [描述说明本次修改内容]
25 | */
26 | @SpringBootApplication
27 | @EnableDiscoveryClient
28 | public class ApiGatewayApplication {
29 | public static void main(String[] args) {
30 | SpringApplication.run(ApiGatewayApplication.class);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/shop-commom/src/main/java/com/ylesb/domain/User.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.domain;
2 | /**
3 | * @title: User
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1115:16
9 | */
10 |
11 | import lombok.Data;
12 |
13 | import javax.persistence.Entity;
14 | import javax.persistence.GeneratedValue;
15 | import javax.persistence.GenerationType;
16 | import javax.persistence.Id;
17 |
18 | /**
19 | * @className : User
20 | * @description : [描述说明该类的功能]
21 | * @author : [XuGuangchao]
22 | * @site : [www.ylesb.com]
23 | * @version : [v1.0]
24 | * @createTime : [2022/1/11 15:16]
25 | * @updateUser : [XuGuangchao]
26 | * @updateTime : [2022/1/11 15:16]
27 | * @updateRemark : [描述说明本次修改内容]
28 | */
29 | @Data
30 | @Entity(name = "shop_user")
31 | public class User {
32 | @Id@GeneratedValue(strategy = GenerationType.IDENTITY)
33 | private Integer uid;
34 | private String username;
35 | private String password;
36 | private String telephone;
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/shop-commom/src/main/java/com/ylesb/domain/Product.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.domain;
2 | /**
3 | * @title: Product
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1115:19
9 | */
10 |
11 | import lombok.Data;
12 |
13 | import javax.persistence.Entity;
14 | import javax.persistence.GeneratedValue;
15 | import javax.persistence.GenerationType;
16 | import javax.persistence.Id;
17 |
18 | /**
19 | * @className : Product
20 | * @description : [描述说明该类的功能]
21 | * @author : [XuGuangchao]
22 | * @site : [www.ylesb.com]
23 | * @version : [v1.0]
24 | * @createTime : [2022/1/11 15:19]
25 | * @updateUser : [XuGuangchao]
26 | * @updateTime : [2022/1/11 15:19]
27 | * @updateRemark : [描述说明本次修改内容]
28 | */
29 | @Data
30 | @Entity(name = "shop_product")
31 | public class Product {
32 | @Id
33 | @GeneratedValue(strategy = GenerationType.IDENTITY)
34 | private Integer pid;
35 | private String pname;
36 | private String pprice;
37 | private Integer stock;
38 | }
39 |
--------------------------------------------------------------------------------
/shop-commom/src/main/java/com/ylesb/domain/Order.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.domain;
2 | /**
3 | * @title: Order
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1115:21
9 | */
10 |
11 | import lombok.Data;
12 |
13 | import javax.persistence.Entity;
14 | import javax.persistence.GeneratedValue;
15 | import javax.persistence.GenerationType;
16 | import javax.persistence.Id;
17 |
18 | /**
19 | * @className : Order
20 | * @description : [描述说明该类的功能]
21 | * @author : [XuGuangchao]
22 | * @site : [www.ylesb.com]
23 | * @version : [v1.0]
24 | * @createTime : [2022/1/11 15:21]
25 | * @updateUser : [XuGuangchao]
26 | * @updateTime : [2022/1/11 15:21]
27 | * @updateRemark : [描述说明本次修改内容]
28 | */
29 | @Data
30 | @Entity(name = "shop_order")
31 | public class Order {
32 | @Id
33 | @GeneratedValue(strategy = GenerationType.IDENTITY)
34 | private Long oid;
35 | private Integer uid;
36 | private Integer pid;
37 | private String pname;
38 | private Double pprice;
39 | private Integer number;
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/shop-order/src/main/java/com/ylesb/service/fallback/ProductServiceFallback.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.service.fallback;
2 | /**
3 | * @title: ProductServiceFallBack
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1216:26
9 | */
10 |
11 | import com.ylesb.domain.Product;
12 | import com.ylesb.service.ProductService;
13 | import org.springframework.stereotype.Service;
14 |
15 | /**
16 | * @className : ProductServiceFallBack
17 | * @description : [描述说明该类的功能]
18 | * @author : [XuGuangchao]
19 | * @site : [www.ylesb.com]
20 | * @version : [v1.0]
21 | * @createTime : [2022/1/12 16:26]
22 | * @updateUser : [XuGuangchao]
23 | * @updateTime : [2022/1/12 16:26]
24 | * @updateRemark : [描述说明本次修改内容]
25 | */
26 | //实现feign容错逻辑
27 | @Service
28 | public class ProductServiceFallback implements ProductService{
29 | @Override
30 | public Product findByPid(Integer pid) {
31 | Product product = new Product();
32 | product.setPid(pid);
33 | product.setPname("出现异常进入容错逻辑");
34 | return product;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/shop-product/src/main/java/com/ylesb/service/Impl/ProductServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.service.Impl;
2 | /**
3 | * @title: UserServiceImpl
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1115:39
9 | */
10 |
11 | import com.ylesb.dao.ProductDao;
12 | import com.ylesb.domain.Product;
13 | import com.ylesb.service.ProductService;
14 | import org.springframework.beans.factory.annotation.Autowired;
15 | import org.springframework.stereotype.Service;
16 | import org.springframework.web.bind.annotation.RestController;
17 |
18 | /**
19 | * @className : UserServiceImpl
20 | * @description : [描述说明该类的功能]
21 | * @author : [XuGuangchao]
22 | * @site : [www.ylesb.com]
23 | * @version : [v1.0]
24 | * @createTime : [2022/1/11 15:39]
25 | * @updateUser : [XuGuangchao]
26 | * @updateTime : [2022/1/11 15:39]
27 | * @updateRemark : [描述说明本次修改内容]
28 | */
29 | @Service
30 | public class ProductServiceImpl implements ProductService {
31 | @Autowired
32 | private ProductDao productDao;
33 | @Override
34 | public Product findByPid(Integer pid) {
35 | return productDao.findById(pid).get();
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/shop-order/src/main/java/com/ylesb/service/ProductService.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.service;
2 | /**
3 | * @title: ProductService
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/129:02
9 | */
10 |
11 | import com.ylesb.domain.Product;
12 | import com.ylesb.service.fallback.ProductServiceFallback;
13 | import com.ylesb.service.fallback.ProductServiceFallbackFactory;
14 | import org.springframework.cloud.openfeign.FeignClient;
15 | import org.springframework.web.bind.annotation.PathVariable;
16 | import org.springframework.web.bind.annotation.RequestMapping;
17 |
18 | /**
19 | * @className : ProductService
20 | * @description : [描述说明该类的功能]
21 | * @author : [XuGuangchao]
22 | * @site : [www.ylesb.com]
23 | * @version : [v1.0]
24 | * @createTime : [2022/1/12 9:02]
25 | * @updateUser : [XuGuangchao]
26 | * @updateTime : [2022/1/12 9:02]
27 | * @updateRemark : [描述说明本次修改内容]
28 | */
29 | @FeignClient(value = "service-product",fallbackFactory = ProductServiceFallbackFactory.class)//value用于指定nacos指定服务
30 | public interface ProductService {
31 | @RequestMapping("/product/{pid}")//指定请求url部分
32 | Product findByPid(@PathVariable Integer pid);
33 | }
34 |
35 |
--------------------------------------------------------------------------------
/shop-order/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8091
3 | spring:
4 | application:
5 | name: service-order
6 | zipkin:
7 | base-url: http://127.0.0.1:9411
8 | discovery-client-enabled: false #让nacos把它当成一个url不要做服务名
9 | sleuth:
10 | sampler:
11 | probability: 1.0 #采样的百分比
12 | datasource:
13 | driver-class-name: com.mysql.cj.jdbc.Driver
14 | url: jdbc:mysql://localhost:3306/shop?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&userSSL=true
15 | username: root
16 | password: 123456
17 | jap:
18 | hibernate:
19 | hb2ddl:
20 | auto: update
21 | dialect: org.hibernate.dialect.MySQL5InnoDBialect
22 | cloud:
23 | nacos:
24 | discovery:
25 | server-addr: localhost:8848
26 | sentinel:
27 | transport:
28 | port: 9999 #跟控制台交流端口,随意一个未使用的端口
29 | dashboard: localhost:8080 #指定控制台的服务地址
30 | # filter:
31 | # enabled: false#之前版本需要这样这是加上Filetercontext
32 | web-context-unify: false # 关闭context整合链路控制
33 | service-product: #服务提供者的名称
34 | ribbon:
35 | NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule
36 | #开启fegin对sentinel支持
37 | feign:
38 | sentinel:
39 | enabled: true
40 | #rocketMQ
41 | rocketmq:
42 | name-server: 192.168.109.131:9876 #rocketMQ服务地址
43 | producer:
44 | group: shop-order #生产者组
--------------------------------------------------------------------------------
/shop-commom/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | springcloud-alibaba
7 | com.ylesb
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | shop-commom
13 |
14 |
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-starter-data-jpa
19 |
20 |
21 | org.projectlombok
22 | lombok
23 |
24 |
25 | com.alibaba
26 | fastjson
27 | 1.2.79
28 |
29 |
30 | mysql
31 | mysql-connector-java
32 | 8.0.27
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/shop-product/src/main/java/com/ylesb/controller/ProductController.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.controller;
2 | /**
3 | * @title: UserController
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1115:38
9 | */
10 |
11 | import com.ylesb.domain.Product;
12 | import com.ylesb.service.ProductService;
13 | import org.springframework.beans.factory.annotation.Autowired;
14 | import org.springframework.web.bind.annotation.PathVariable;
15 | import org.springframework.web.bind.annotation.RequestMapping;
16 | import org.springframework.web.bind.annotation.RestController;
17 |
18 | /**
19 | * @className : UserController
20 | * @description : [描述说明该类的功能]
21 | * @author : [XuGuangchao]
22 | * @site : [www.ylesb.com]
23 | * @version : [v1.0]
24 | * @createTime : [2022/1/11 15:38]
25 | * @updateUser : [XuGuangchao]
26 | * @updateTime : [2022/1/11 15:38]
27 | * @updateRemark : [描述说明本次修改内容]
28 | */
29 |
30 | @RestController
31 | public class ProductController {
32 | @Autowired
33 | private ProductService productService;
34 |
35 | @RequestMapping("/product/{pid}")
36 | public Product product(@PathVariable("pid") Integer pid){
37 | Product product =productService.findByPid(pid);
38 |
39 | return product;
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/shop-order/src/main/java/com/ylesb/service/Impl/OrderServiceImpl.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.service.Impl;
2 | /**
3 | * @title: UserServiceImpl
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1115:39
9 | */
10 |
11 | import com.ylesb.domain.Order;
12 | import io.seata.spring.annotation.GlobalTransactional;
13 | import org.apache.rocketmq.spring.core.RocketMQTemplate;
14 | import org.springframework.beans.factory.annotation.Autowired;
15 | import org.springframework.messaging.support.MessageBuilder;
16 | import org.springframework.stereotype.Service;
17 | import com.ylesb.dao.OrderDao;
18 | import com.ylesb.service.OrderService;
19 |
20 | /**
21 | * @className : UserServiceImpl
22 | * @description : [描述说明该类的功能]
23 | * @author : [XuGuangchao]
24 | * @site : [www.ylesb.com]
25 | * @version : [v1.0]
26 | * @createTime : [2022/1/11 15:39]
27 | * @updateUser : [XuGuangchao]
28 | * @updateTime : [2022/1/11 15:39]
29 | * @updateRemark : [描述说明本次修改内容]
30 | */
31 | @Service
32 | public class OrderServiceImpl implements OrderService {
33 | @Autowired
34 | OrderDao orderDao;
35 |
36 | @Override
37 | @GlobalTransactional//开启全局事务seata无代码侵入性
38 | public void createOrder(Order order) {
39 | orderDao.save(order);
40 | }
41 |
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/api-gateway/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | springcloud-alibaba
7 | com.ylesb
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | api-getway
13 |
14 |
15 |
16 |
17 | org.springframework.cloud
18 | spring-cloud-starter-gateway
19 |
20 |
21 |
22 | com.alibaba.cloud
23 | spring-cloud-starter-alibaba-nacos-discovery
24 |
25 |
26 | org.projectlombok
27 | lombok
28 |
29 |
30 |
31 | com.alibaba.csp
32 | sentinel-spring-cloud-gateway-adapter
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/shop-order/src/main/java/com/ylesb/config/RequestOriginParserDefinition.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.config;
2 | /**
3 | * @title: RequestOriginParserDefinition
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1215:38
9 | */
10 |
11 |
12 | import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser;
13 | import org.apache.commons.lang3.StringUtils;
14 | import org.springframework.stereotype.Component;
15 |
16 | import javax.servlet.http.HttpServletRequest;
17 |
18 | /**
19 | * @className : RequestOriginParserDefinition
20 | * @description : [描述说明该类的功能]
21 | * @author : [XuGuangchao]
22 | * @site : [www.ylesb.com]
23 | * @version : [v1.0]
24 | * @createTime : [2022/1/12 15:38]
25 | * @updateUser : [XuGuangchao]
26 | * @updateTime : [2022/1/12 15:38]
27 | * @updateRemark : [描述说明本次修改内容]
28 | */
29 | @Component
30 | public class RequestOriginParserDefinition implements RequestOriginParser {
31 | //授权规则本质通过request域获取来源标识
32 | @Override
33 | public String parseOrigin(HttpServletRequest httpServletRequest) {
34 | String serviceName = httpServletRequest.getParameter("serviceName");
35 | if(StringUtils.isEmpty(serviceName)){
36 | throw new RuntimeException("服 务为空");
37 | }
38 | return serviceName;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/shop-order/src/main/java/com/ylesb/service/fallback/ProductServiceFallbackFactory.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.service.fallback;
2 | /**
3 | * @title: ProductServiceFallbackFactory
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1216:41
9 | */
10 |
11 | import com.ylesb.domain.Product;
12 | import com.ylesb.service.ProductService;
13 | import feign.hystrix.FallbackFactory;
14 |
15 | /**
16 | * @className : ProductServiceFallbackFactory
17 | * @description : [描述说明该类的功能]
18 | * @author : [XuGuangchao]
19 | * @site : [www.ylesb.com]
20 | * @version : [v1.0]
21 | * @createTime : [2022/1/12 16:41]
22 | * @updateUser : [XuGuangchao]
23 | * @updateTime : [2022/1/12 16:41]
24 | * @updateRemark : [描述说明本次修改内容]
25 | */
26 | //容错工厂类实现接口传递接口调用哪个接口产生的容错类
27 | public class ProductServiceFallbackFactory implements FallbackFactory {
28 | @Override
29 | public ProductService create(Throwable throwable) {
30 | //匿名内部类
31 | return new ProductService() {
32 | @Override
33 | public Product findByPid(Integer pid) {
34 | Product product = new Product();
35 | product.setPid(pid);
36 | product.setPname("出现异常进入容错逻辑");
37 | return product;
38 | }
39 | };
40 | }
41 | }
42 |
43 |
--------------------------------------------------------------------------------
/shop-order/src/main/java/com/ylesb/config/DataSourceProxyConfig.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.config;
2 | /**
3 | * @title: DataSourceProxyConfig
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1411:33
9 | */
10 |
11 | import com.alibaba.druid.pool.DruidDataSource;
12 | import io.seata.rm.datasource.DataSourceProxy;
13 | import org.springframework.boot.context.properties.ConfigurationProperties;
14 | import org.springframework.context.annotation.Bean;
15 | import org.springframework.context.annotation.Configuration;
16 | import org.springframework.context.annotation.Primary;
17 |
18 | /**
19 | * @className : DataSourceProxyConfig
20 | * @description : [描述说明该类的功能]
21 | * @author : [XuGuangchao]
22 | * @site : [www.ylesb.com]
23 | * @version : [v1.0]
24 | * @createTime : [2022/1/14 11:33]
25 | * @updateUser : [XuGuangchao]
26 | * @updateTime : [2022/1/14 11:33]
27 | * @updateRemark : [描述说明本次修改内容]
28 | */
29 | @Configuration
30 | public class DataSourceProxyConfig {
31 |
32 | @Bean
33 | @ConfigurationProperties(prefix = "spring.datasource")
34 | public DruidDataSource druidDataSource() {
35 | return new DruidDataSource();
36 | }
37 | @Primary
38 | @Bean
39 | public DataSourceProxy datasource (DruidDataSource druidDataSource){
40 | return new DataSourceProxy(druidDataSource);
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/shop-order/src/main/java/com/ylesb/OrderApplication.java:
--------------------------------------------------------------------------------
1 | package com.ylesb;
2 | /**
3 | * @title: UserApplication
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1115:28
9 | */
10 |
11 | import org.springframework.boot.SpringApplication;
12 | import org.springframework.boot.autoconfigure.SpringBootApplication;
13 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
14 | import org.springframework.cloud.client.loadbalancer.LoadBalanced;
15 | import org.springframework.cloud.openfeign.EnableFeignClients;
16 | import org.springframework.context.annotation.Bean;
17 | import org.springframework.web.client.RestTemplate;
18 |
19 | /**
20 | * @className : UserApplication
21 | * @description : [描述说明该类的功能]
22 | * @author : [XuGuangchao]
23 | * @site : [www.ylesb.com]
24 | * @version : [v1.0]
25 | * @createTime : [2022/1/11 15:28]
26 | * @updateUser : [XuGuangchao]
27 | * @updateTime : [2022/1/11 15:28]
28 | * @updateRemark : [描述说明本次修改内容]
29 | */
30 | @SpringBootApplication
31 | @EnableDiscoveryClient//开启服务发现
32 | @EnableFeignClients//开启fegin客户端
33 | public class OrderApplication {
34 | public static void main(String[] args) {
35 | SpringApplication.run(OrderApplication.class);
36 | }
37 | @Bean
38 | @LoadBalanced
39 | public RestTemplate restTemplate() {
40 | return new RestTemplate();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/shop-order/src/main/java/com/ylesb/config/FilterContextConfig.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.config;
2 | /**
3 | * @title: FilterContextConfig
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1214:59
9 | */
10 | import org.springframework.boot.web.servlet.FilterRegistrationBean;
11 | import org.springframework.context.annotation.Bean;
12 | import org.springframework.context.annotation.Configuration;
13 |
14 | /**
15 | * @className : FilterContextConfig
16 | * @description : [描述说明该类的功能]
17 | * @author : [XuGuangchao]
18 | * @site : [www.ylesb.com]
19 | * @version : [v1.0]
20 | * @createTime : [2022/1/12 14:59]
21 | * @updateUser : [XuGuangchao]
22 | * @updateTime : [2022/1/12 14:59]
23 | * @updateRemark : [描述说明本次修改内容]
24 | */
25 | //import com.alibaba.csp.sentinel.adapter.servlet.CommonFilter;
26 | //@Configuration
27 | public class FilterContextConfig {
28 | //@Bean
29 | //public FilterRegistrationBean sentinelFilterRegistration() {
30 | // FilterRegistrationBean registrationBean = new FilterRegistrationBean();
31 | // registrationBean.setFilter(new CommonFilter());
32 | // registrationBean.addUrlPatterns("/*");
33 | // // 入口资源关闭聚合
34 | // registrationBean.addInitParameter(CommonFilter.WEB_CONTEXT_UNIFY, "false");
35 | // registrationBean.setName("sentinelFilter");
36 | // registrationBean.setOrder(1);
37 | // return registrationBean;
38 | //}
39 | }
--------------------------------------------------------------------------------
/shop-order/src/test/java/com/ylesb/test/RocketMQSendMessageTest.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.test;
2 | /**
3 | * @title: testRocketMQSendMessageTest
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1314:24
9 | */
10 |
11 | import org.apache.rocketmq.client.producer.DefaultMQProducer;
12 | import org.apache.rocketmq.client.producer.SendResult;
13 | import org.apache.rocketmq.common.message.Message;
14 |
15 | /**
16 | * @className : testRocketMQSendMessageTest
17 | * @description : [描述说明该类的功能]
18 | * @author : [XuGuangchao]
19 | * @site : [www.ylesb.com]
20 | * @version : [v1.0]
21 | * @createTime : [2022/1/13 14:24]
22 | * @updateUser : [XuGuangchao]
23 | * @updateTime : [2022/1/13 14:24]
24 | * @updateRemark : [描述说明本次修改内容]
25 | */
26 | //RocketMQ消息队列
27 | public class RocketMQSendMessageTest {
28 | public static void main(String[] args) throws Exception{
29 | //常见消息生产者,并设置生产者组名
30 | DefaultMQProducer defaultMQProducer = new DefaultMQProducer("myproducer-group");
31 | //为生产者nameserver
32 | defaultMQProducer.setNamesrvAddr("192.168.109.131:9876");
33 | //启动生产者
34 | defaultMQProducer.start();
35 | //构建消息对象,主要是设置消息的主题标签内容
36 | Message message=new Message("myTopic","myTag",("Test RocketMQ ,Message").getBytes());
37 | //发送消息
38 | SendResult send=defaultMQProducer.send(message,1000);
39 | //关闭生产者
40 | defaultMQProducer.shutdown();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/shop-product/src/main/java/com/ylesb/controller/NacosConfigController.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.controller;
2 | /**
3 | * @title: NacosConfigController
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/149:42
9 | */
10 |
11 | import org.springframework.beans.factory.annotation.Autowired;
12 | import org.springframework.beans.factory.annotation.Value;
13 | import org.springframework.cloud.context.config.annotation.RefreshScope;
14 | import org.springframework.context.ConfigurableApplicationContext;
15 | import org.springframework.web.bind.annotation.RequestMapping;
16 | import org.springframework.web.bind.annotation.RestController;
17 |
18 | /**
19 | * @className : NacosConfigController
20 | * @description : [描述说明该类的功能]
21 | * @author : [XuGuangchao]
22 | * @site : [www.ylesb.com]
23 | * @version : [v1.0]
24 | * @createTime : [2022/1/14 9:42]
25 | * @updateUser : [XuGuangchao]
26 | * @updateTime : [2022/1/14 9:42]
27 | * @updateRemark : [描述说明本次修改内容]
28 | */
29 | @RestController
30 | //动态刷新配置文件注解
31 | @RefreshScope
32 | public class NacosConfigController {
33 | @Autowired
34 | private ConfigurableApplicationContext context;
35 | @Value("${config.appName}")
36 | private String appName;
37 | @RequestMapping("/test-config1")
38 | public String testConfig1()
39 | {
40 | return context.getEnvironment().getProperty("config.appName");
41 | }
42 | @RequestMapping("/test-config2")
43 | public String testConfig2()
44 | {
45 | return appName;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/shop-user/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | springcloud-alibaba
7 | com.ylesb
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | shop-user
13 |
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-web
18 |
19 |
20 |
21 | com.ylesb
22 | shop-commom
23 | 1.0-SNAPSHOT
24 |
25 |
26 |
27 | com.alibaba.cloud
28 | spring-cloud-starter-alibaba-nacos-discovery
29 |
30 |
31 | org.apache.rocketmq
32 | rocketmq-spring-boot-starter
33 | 2.0.2
34 |
35 |
36 | org.apache.rocketmq
37 | rocketmq-client
38 | 4.4.0
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/shop-product/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | springcloud-alibaba
7 | com.ylesb
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | shop-product
13 |
14 |
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-starter-web
19 |
20 |
21 |
22 | com.ylesb
23 | shop-commom
24 | 1.0-SNAPSHOT
25 |
26 |
27 |
28 | com.alibaba.cloud
29 | spring-cloud-starter-alibaba-nacos-discovery
30 |
31 |
32 |
33 | com.alibaba.cloud
34 | spring-cloud-starter-alibaba-nacos-config
35 |
36 |
37 |
38 | com.alibaba.cloud
39 | spring-cloud-starter-alibaba-seata
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/api-gateway/src/main/java/com/ylesb/filters/AuthGlobaFilter.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.filters;
2 | /**
3 | * @title: AuthGlobaFilter
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/139:59
9 | */
10 |
11 | import org.apache.commons.lang3.StringUtils;
12 | import org.springframework.cloud.gateway.filter.GatewayFilterChain;
13 | import org.springframework.cloud.gateway.filter.GlobalFilter;
14 | import org.springframework.core.Ordered;
15 | import org.springframework.http.HttpStatus;
16 | import org.springframework.stereotype.Component;
17 | import org.springframework.web.server.ServerWebExchange;
18 | import reactor.core.publisher.Mono;
19 |
20 | /**
21 | * @className : AuthGlobaFilter
22 | * @description : [描述说明该类的功能]
23 | * @author : [XuGuangchao]
24 | * @site : [www.ylesb.com]
25 | * @version : [v1.0]
26 | * @createTime : [2022/1/13 9:59]
27 | * @updateUser : [XuGuangchao]
28 | * @updateTime : [2022/1/13 9:59]
29 | * @updateRemark : [描述说明本次修改内容]
30 | */
31 | @Component
32 | public class AuthGlobaFilter implements GlobalFilter, Ordered {
33 | //统一鉴权
34 | @Override
35 | public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) {
36 | String token=exchange.getRequest().getQueryParams().getFirst("token");
37 | if(StringUtils.equals("admin",token))
38 | {
39 | //鉴权失败
40 | exchange.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED);
41 | return exchange.getResponse().setComplete();
42 | }
43 |
44 | //放行逻辑
45 | return chain.filter(exchange);
46 | }
47 | //标识当前过滤器的优先级,返回值越小,优先级越高
48 | @Override
49 | public int getOrder() {
50 | return 0;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/shop-order/src/main/java/com/ylesb/service/Impl/OrderServiceImpl4.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.service.Impl;
2 | /**
3 | * @title: OrderServiceImpl4
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1316:59
9 | */
10 |
11 | import com.ylesb.dao.OrderDao;
12 | import com.ylesb.dao.TxLogDao;
13 | import com.ylesb.domain.Order;
14 | import com.ylesb.domain.TxLog;
15 | import org.apache.rocketmq.spring.core.RocketMQTemplate;
16 | import org.springframework.beans.factory.annotation.Autowired;
17 | import org.springframework.messaging.support.MessageBuilder;
18 | import org.springframework.stereotype.Service;
19 | import org.springframework.transaction.annotation.Transactional;
20 |
21 | import java.util.Date;
22 | import java.util.UUID;
23 |
24 | /**
25 | * @className : OrderServiceImpl4
26 | * @description : [描述说明该类的功能]
27 | * @author : [XuGuangchao]
28 | * @site : [www.ylesb.com]
29 | * @version : [v1.0]
30 | * @createTime : [2022/1/13 16:59]
31 | * @updateUser : [XuGuangchao]
32 | * @updateTime : [2022/1/13 16:59]
33 | * @updateRemark : [描述说明本次修改内容]
34 | */
35 | @Service
36 | public class OrderServiceImpl4 {
37 | @Autowired
38 | OrderDao orderDao;
39 | @Autowired
40 | TxLogDao txLogDao;
41 | @Autowired
42 | private RocketMQTemplate rocketMQTemplate;
43 | public void createOrderBefore(Order order) {
44 | String txId= UUID.randomUUID().toString();
45 | //发送半事务消息
46 | rocketMQTemplate.sendMessageInTransaction("tx_producer_group","tx", MessageBuilder.withPayload(order).
47 | setHeader("txId",txId).build(), order
48 | );
49 | }
50 | @Transactional
51 | public void createOrder(String txId,Order order) {
52 | orderDao.save(order);
53 | TxLog txLog=new TxLog();
54 | txLog.setTxId(txId);
55 | txLog.setDate(new Date());
56 | txLogDao.save(txLog);
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/shop-order/src/test/java/com/ylesb/test/RocketMQReceiveMessageTest.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.test;
2 | /**
3 | * @title: RocketMQReceiveMessageTest
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1314:36
9 | */
10 |
11 | import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
12 | import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
13 | import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
14 | import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
15 | import org.apache.rocketmq.common.message.MessageExt;
16 |
17 | import java.util.List;
18 |
19 | /**
20 | * @className : RocketMQReceiveMessageTest
21 | * @description : [描述说明该类的功能]
22 | * @author : [XuGuangchao]
23 | * @site : [www.ylesb.com]
24 | * @version : [v1.0]
25 | * @createTime : [2022/1/13 14:36]
26 | * @updateUser : [XuGuangchao]
27 | * @updateTime : [2022/1/13 14:36]
28 | * @updateRemark : [描述说明本次修改内容]
29 | */
30 |
31 | public class RocketMQReceiveMessageTest {
32 | public static void main(String[] args) throws Exception{
33 | //创建消费者并且指定消费者组的名称
34 | DefaultMQPushConsumer defaultMQPushConsumer = new DefaultMQPushConsumer("myconsumer-group");
35 | //为消费者设置nameserver地址
36 | defaultMQPushConsumer.setNamesrvAddr("192.168.109.131.9876");
37 | //指定消费者订阅的主题和标签
38 | defaultMQPushConsumer.subscribe("myTopic","*");
39 | //设置回调函数,设置接收消息的处理方法
40 | defaultMQPushConsumer.registerMessageListener(new MessageListenerConcurrently() {
41 | //处理获取的消息
42 | @Override
43 | public ConsumeConcurrentlyStatus consumeMessage(List list, ConsumeConcurrentlyContext consumeConcurrentlyContext) {
44 |
45 | //返回消费成功状态
46 | return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
47 | }
48 | });
49 | //启动消费者
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/shop-user/src/main/java/com/ylesb/service/SmsService.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.service;
2 | /**
3 | * @title: SmsService
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1315:39
9 | */
10 |
11 | import com.ylesb.dao.UserDao;
12 | import com.ylesb.domain.Order;
13 | import com.ylesb.domain.User;
14 | import lombok.val;
15 | import org.apache.rocketmq.spring.annotation.ConsumeMode;
16 | import org.apache.rocketmq.spring.annotation.MessageModel;
17 | import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
18 | import org.apache.rocketmq.spring.core.RocketMQListener;
19 | import org.springframework.beans.factory.annotation.Autowired;
20 | import org.springframework.stereotype.Service;
21 |
22 | import java.util.Random;
23 |
24 | /**
25 | * @className : SmsService
26 | * @description : [描述说明该类的功能]
27 | * @author : [XuGuangchao]
28 | * @site : [www.ylesb.com]
29 | * @version : [v1.0]
30 | * @createTime : [2022/1/13 15:39]
31 | * @updateUser : [XuGuangchao]
32 | * @updateTime : [2022/1/13 15:39]
33 | * @updateRemark : [描述说明本次修改内容]
34 | */
35 | @Service
36 | //消费者组名consumerGroup topic消费的组名
37 | @RocketMQMessageListener(consumerGroup = "shop-user",//消费者组名
38 | topic = "order-topic",//消费主题
39 | consumeMode= ConsumeMode.CONCURRENTLY,//消费模式,是否是定顺序消费CONCURRENTLY同步,orderly顺序
40 | messageModel = MessageModel.CLUSTERING//消息模式 BROADCASTING(广播)
41 | )
42 | public class SmsService implements RocketMQListener{
43 | @Autowired
44 | UserDao userDao;
45 | @Override
46 | public void onMessage(Order order) {
47 | //接收到了订单信息,就可以发短信了
48 | //根据uid获取手机号
49 | User user = userDao.findById(order.getUid()).get();
50 | //生成验证码
51 | StringBuilder builder = new StringBuilder();
52 | for (int i = 0;i<6;i++){
53 | builder.append(new Random().nextInt(9)+1);
54 | }
55 | String code=builder.toString();
56 | //发送短信
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/api-gateway/src/main/java/com/ylesb/filters/LogGatewayFilterFactory.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.filters;
2 | /**
3 | * @title: LogGatewayFilterFactory
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/139:43
9 | */
10 |
11 | import lombok.Data;
12 | import lombok.NoArgsConstructor;
13 | import org.springframework.cloud.gateway.filter.GatewayFilter;
14 | import org.springframework.cloud.gateway.filter.GatewayFilterChain;
15 | import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory;
16 | import org.springframework.web.server.ServerWebExchange;
17 | import reactor.core.publisher.Mono;
18 |
19 | import java.util.Arrays;
20 | import java.util.List;
21 |
22 | /**
23 | * @className : LogGatewayFilterFactory
24 | * @description : [描述说明该类的功能]
25 | * @author : [XuGuangchao]
26 | * @site : [www.ylesb.com]
27 | * @version : [v1.0]
28 | * @createTime : [2022/1/13 9:43]
29 | * @updateUser : [XuGuangchao]
30 | * @updateTime : [2022/1/13 9:43]
31 | * @updateRemark : [描述说明本次修改内容]
32 | */
33 | //自定义局部过滤器
34 | public class LogGatewayFilterFactory extends AbstractGatewayFilterFactory{
35 | //构造函数
36 | public LogGatewayFilterFactory(){
37 | super(LogGatewayFilterFactory.Config.class);
38 | }
39 | //读取配置文件中的参数 赋值带配置类中
40 | @Override
41 | public List shortcutFieldOrder() {
42 | return Arrays.asList("consoleLog","cacheLog");
43 | }
44 | //过滤器配置
45 | @Override
46 | public GatewayFilter apply(Config config) {
47 | return new GatewayFilter() {
48 | @Override
49 | public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) {
50 | if (config.isCacheLog()) {
51 | //缓存日志开启
52 | }
53 | if (config.isConsoleLog()) {
54 | //控制台日志开启
55 | }
56 |
57 | return null;
58 | }
59 | };
60 | }
61 |
62 | @Data
63 | @NoArgsConstructor
64 | public static class Config{
65 | private boolean consoleLog;
66 | private boolean cacheLog;
67 |
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/shop-order/src/main/java/com/ylesb/controller/OrderController.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.controller;
2 | /**
3 | * @title: UserController
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1115:38
9 | */
10 |
11 | import com.ylesb.domain.Order;
12 | import com.ylesb.domain.Product;
13 | import com.ylesb.service.OrderService;
14 | import com.ylesb.service.ProductService;
15 | import org.apache.rocketmq.spring.core.RocketMQTemplate;
16 | import org.springframework.beans.factory.annotation.Autowired;
17 | import org.springframework.cloud.client.discovery.DiscoveryClient;
18 | import org.springframework.web.bind.annotation.PathVariable;
19 | import org.springframework.web.bind.annotation.RequestMapping;
20 | import org.springframework.web.bind.annotation.RestController;
21 | import org.springframework.web.client.RestTemplate;
22 |
23 | /**
24 | * @className : UserController
25 | * @description : [描述说明该类的功能]
26 | * @author : [XuGuangchao]
27 | * @site : [www.ylesb.com]
28 | * @version : [v1.0]
29 | * @createTime : [2022/1/11 15:38]
30 | * @updateUser : [XuGuangchao]
31 | * @updateTime : [2022/1/11 15:38]
32 | * @updateRemark : [描述说明本次修改内容]
33 | */
34 |
35 | @RestController
36 | public class OrderController {
37 | @Autowired
38 | private RestTemplate restTemplate;
39 | @Autowired
40 | private OrderService orderService;
41 | @Autowired
42 | private DiscoveryClient discoveryClient;
43 | @Autowired
44 | private ProductService productService;
45 | @Autowired
46 | private RocketMQTemplate rocketMQTemplate;
47 | @RequestMapping("/order/prod/{pid}")
48 | public Order oder(@PathVariable("pid") Integer pid){
49 | //List instances=discoveryClient.getInstances("service-product");
50 | //ServiceInstance serviceInstance = instances.get(0);
51 | //
52 | //Product product = restTemplate.getForObject("http://service-product/product/"+pid,Product.class);
53 | Product product = productService.findByPid(pid);
54 | Order order = new Order();
55 | order.setUid(1);
56 | orderService.createOrder(order);
57 | //参数1指定topic
58 | //指定消息体
59 | rocketMQTemplate.convertAndSend("order-topic",order);
60 |
61 |
62 | return order;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/shop-order/src/test/java/com/ylesb/test/MessageTypeTest.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.test;
2 | /**
3 | * @title: MessageTypeTest
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1315:55
9 | */
10 |
11 | import com.ylesb.OrderApplication;
12 | import org.apache.rocketmq.client.producer.SendCallback;
13 | import org.apache.rocketmq.client.producer.SendResult;
14 | import org.apache.rocketmq.spring.core.RocketMQTemplate;
15 | import org.junit.Test;
16 | import org.junit.runner.RunWith;
17 | import org.springframework.beans.factory.annotation.Autowired;
18 | import org.springframework.boot.test.context.SpringBootTest;
19 | import org.springframework.test.context.junit4.SpringRunner;
20 |
21 | /**
22 | * @className : MessageTypeTest
23 | * @description : [描述说明该类的功能]
24 | * @author : [XuGuangchao]
25 | * @site : [www.ylesb.com]
26 | * @version : [v1.0]
27 | * @createTime : [2022/1/13 15:55]
28 | * @updateUser : [XuGuangchao]
29 | * @updateTime : [2022/1/13 15:55]
30 | * @updateRemark : [描述说明本次修改内容]
31 | */
32 | @RunWith(SpringRunner.class)
33 | @SpringBootTest(classes = OrderApplication.class)
34 | public class MessageTypeTest {
35 | @Autowired
36 | private RocketMQTemplate rocketMQTemplate;
37 | //可靠同步发送 用于重要邮件通知 报名短信,营销短信
38 | @Test
39 | public void testSyncSend(){
40 | //:tag 是标签
41 | SendResult result=rocketMQTemplate.syncSend("test-topic-1:tag","这是一个同步消息",10000);
42 |
43 | }
44 | //可靠异步发送 用于链路耗时较长,对RT响应时间较为敏感业务场景,例如用户视频上传后转码服务,转码完成后对响应结果推送等。
45 | @Test
46 | public void testAsyncSend() {
47 | //:tag 是标签
48 | rocketMQTemplate.asyncSend("test-topic-1:tag", "这是一条异步消息", new SendCallback() {
49 | @Override
50 | public void onSuccess(SendResult sendResult) {
51 | //成功回调
52 | }
53 |
54 | //异常的回调
55 | @Override
56 | public void onException(Throwable throwable) {
57 |
58 | }
59 | });
60 | }
61 | //单向发送 用于不可靠等例如日志收集。
62 | @Test
63 | public void testOneSend() {
64 | //:tag 是标签
65 | rocketMQTemplate.sendOneWay("test-topic-1:tag", "这是一个单向消息" );
66 | }
67 | //单向顺序发送 用于不可靠等例如日志收集。
68 | @Test
69 | public void testOneOrderlySend() {
70 | //:tag 是标签第三个参数是决定消息队列发送到哪个队列上
71 | rocketMQTemplate.sendOneWayOrderly("test-topic-1:tag", "这是一个单向消息","xx");
72 | }
73 |
74 | }
--------------------------------------------------------------------------------
/shop-order/src/main/java/com/ylesb/service/Impl/OrderServiceImpl4Listener.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.service.Impl;
2 | /**
3 | * @title: OrderServiceImpl4Listener
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1317:05
9 | */
10 |
11 | import com.ylesb.dao.TxLogDao;
12 | import com.ylesb.domain.Order;
13 | import com.ylesb.domain.TxLog;
14 | import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
15 | import org.apache.rocketmq.spring.annotation.RocketMQTransactionListener;
16 | import org.apache.rocketmq.spring.core.RocketMQLocalTransactionListener;
17 | import org.apache.rocketmq.spring.core.RocketMQLocalTransactionState;
18 | import org.springframework.beans.factory.annotation.Autowired;
19 | import org.springframework.messaging.Message;
20 | import org.springframework.stereotype.Service;
21 |
22 | /**
23 | * @className : OrderServiceImpl4Listener
24 | * @description : [描述说明该类的功能]
25 | * @author : [XuGuangchao]
26 | * @site : [www.ylesb.com]
27 | * @version : [v1.0]
28 | * @createTime : [2022/1/13 17:05]
29 | * @updateUser : [XuGuangchao]
30 | * @updateTime : [2022/1/13 17:05]
31 | * @updateRemark : [描述说明本次修改内容]
32 | */
33 | @Service
34 | @RocketMQTransactionListener(txProducerGroup = "tx_producer_group")
35 | public class OrderServiceImpl4Listener implements RocketMQLocalTransactionListener {
36 | @Autowired
37 | private OrderServiceImpl4 orderServiceImpl4;
38 | @Autowired
39 | private TxLogDao txLogDao;
40 | //执行本地事务
41 | @Override
42 | public RocketMQLocalTransactionState executeLocalTransaction(Message message, Object o) {
43 | String txId =(String) message.getHeaders().get("txId");
44 | try {
45 | Order order =(Order) o;
46 | orderServiceImpl4.createOrder( txId,order);
47 | return RocketMQLocalTransactionState.COMMIT;
48 | }catch (Exception e) {
49 | //实行失败回滚rollback
50 | return RocketMQLocalTransactionState.ROLLBACK;
51 | }
52 |
53 |
54 | }
55 | //用于消息回查
56 | @Override
57 | public RocketMQLocalTransactionState checkLocalTransaction(Message message) {
58 | String txId =(String) message.getHeaders().get("txId");
59 | TxLog txLog=txLogDao.findById(txId).get();
60 | if (txLog == null) {
61 | //执行本地事务成功了
62 | return RocketMQLocalTransactionState.COMMIT;
63 | }else{
64 | return RocketMQLocalTransactionState.ROLLBACK;
65 | }
66 |
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/shop-order/src/main/java/com/ylesb/config/ExceptionHandlerPage.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.config;
2 | /**
3 | * @title: ExceptionHandlerPage
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1215:48
9 | */
10 |
11 | import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.BlockExceptionHandler;
12 | import com.alibaba.csp.sentinel.slots.block.BlockException;
13 | import com.alibaba.csp.sentinel.slots.block.authority.AuthorityException;
14 | import com.alibaba.csp.sentinel.slots.block.degrade.DegradeException;
15 | import com.alibaba.csp.sentinel.slots.block.flow.FlowException;
16 | import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowException;
17 | import com.alibaba.csp.sentinel.slots.system.SystemBlockException;
18 | import com.alibaba.fastjson.JSON;
19 | import lombok.AllArgsConstructor;
20 | import lombok.Data;
21 | import lombok.NoArgsConstructor;
22 |
23 | import javax.servlet.http.HttpServletRequest;
24 | import javax.servlet.http.HttpServletResponse;
25 |
26 | /**
27 | * @className : ExceptionHandlerPage
28 | * @description : [描述说明该类的功能]
29 | * @author : [XuGuangchao]
30 | * @site : [www.ylesb.com]
31 | * @version : [v1.0]
32 | * @createTime : [2022/1/12 15:48]
33 | * @updateUser : [XuGuangchao]
34 | * @updateTime : [2022/1/12 15:48]
35 | * @updateRemark : [描述说明本次修改内容]
36 | */
37 |
38 | public class ExceptionHandlerPage implements BlockExceptionHandler {
39 |
40 | @Override
41 | public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, BlockException e) throws Exception {
42 | //解决中文乱码
43 | httpServletResponse.setContentType("application/json;charset=utf-8");
44 | ResponseData data = null;
45 | if (e instanceof FlowException) {
46 | data = new ResponseData(-1, "限流了");
47 | } else if (e instanceof DegradeException) {
48 | data = new ResponseData(-2, "降级了");
49 | } else if (e instanceof ParamFlowException) {
50 | data = new ResponseData(-3, "参数限流了");
51 | } else if (e instanceof SystemBlockException) {
52 | data = new ResponseData(-4, "系统负载异常了");
53 | } else if (e instanceof AuthorityException) {
54 | data = new ResponseData(-5, "授权异常");
55 | }
56 | httpServletResponse.getWriter().write(JSON.toJSONString(data));
57 |
58 | }
59 | }
60 | @Data
61 | @AllArgsConstructor//全参构造
62 | @NoArgsConstructor//无参构造
63 | class ResponseData{
64 | private int code;
65 | private String message;
66 | }
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.ylesb
8 | springcloud-alibaba
9 | pom
10 | 1.0-SNAPSHOT
11 |
12 | shop-commom
13 | shop-user
14 | shop-product
15 | shop-order
16 | api-gateway
17 |
18 |
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-parent
23 | 2.1.7.RELEASE
24 |
25 |
26 |
27 | 1.8
28 | UTF-8
29 | UTF-8
30 | Greenwich.RELEASE
31 | 2.1.2.RELEASE
32 |
33 |
34 |
35 |
36 | org.springframework.cloud
37 | spring-cloud-dependencies
38 | ${spring-cloud.version}
39 | pom
40 | import
41 |
42 |
43 | com.alibaba.cloud
44 | spring-cloud-alibaba-dependencies
45 | ${spring-cloud-alibaba.version}
46 | pom
47 | import
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 | org.springframework.cloud
56 | spring-cloud-starter-sleuth
57 |
58 |
59 |
60 | org.springframework.cloud
61 | spring-cloud-starter-zipkin
62 |
63 |
64 |
--------------------------------------------------------------------------------
/shop-order/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | springcloud-alibaba
7 | com.ylesb
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | shop-order
13 |
14 |
15 |
16 |
17 | org.springframework.boot
18 | spring-boot-starter-web
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-test
23 | test
24 |
25 |
26 |
27 | com.ylesb
28 | shop-commom
29 | 1.0-SNAPSHOT
30 |
31 |
32 |
33 | com.alibaba.cloud
34 | spring-cloud-starter-alibaba-nacos-discovery
35 |
36 |
37 |
38 | org.springframework.cloud
39 | spring-cloud-starter-openfeign
40 |
41 |
42 |
43 | com.alibaba.cloud
44 | spring-cloud-starter-alibaba-sentinel
45 |
46 |
47 | org.apache.rocketmq
48 | rocketmq-spring-boot-starter
49 | 2.0.2
50 |
51 |
52 | org.apache.rocketmq
53 | rocketmq-client
54 | 4.4.0
55 |
56 |
57 |
58 | com.alibaba.cloud
59 | spring-cloud-starter-alibaba-nacos-config
60 |
61 |
62 |
63 | com.alibaba.cloud
64 | spring-cloud-starter-alibaba-seata
65 |
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 | ## Spring Cloud Alibaba x XGC
3 | ## 介绍
4 | 本项目是根据Spring Cloud Alibaba技术栈进行整体项目学习的教程、不断更新。
5 | 食用方法:首先根据下面学习链接,按照顺序下载安装相关依赖,然后根据下面的学习链接,按照顺序进行学习。
6 | 欢迎 Star 🌟 关注[本项目](https://github.com/CoderXGC/springcloud-alibaba/),获取项目最新动态。
7 |
8 | ## 分支介绍
9 | 可以拉去相关分支,如下图:
10 | 
11 | 220118_xgc_initProject环境搭建以及注意事项: [学习链接:https://developer.aliyun.com/article/857900](https://developer.aliyun.com/article/857900)
12 | 220121_xgc_buildFramework搭建微服务模块: [学习链接:https://developer.aliyun.com/article/859868](https://developer.aliyun.com/article/859868)
13 | 220124_xgc_createTable微服务调用: [学习链接:https://developer.aliyun.com/article/860936](https://developer.aliyun.com/article/860936)
14 | 220126_xgc_useNacos使用注册中心: [学习链接:https://developer.aliyun.com/article/861536](https://developer.aliyun.com/article/861536)
15 | 220127_xgc_loadBalance负载均衡: [学习链接:https://developer.aliyun.com/article/862087](https://developer.aliyun.com/article/862087)
16 | 220128_xgc_useFegin使用Fegin: [学习链接:https://developer.aliyun.com/article/863225](https://developer.aliyun.com/article/863225)
17 | 220131_xgc_highConcurrency高并发问题: [学习链接:https://developer.aliyun.com/article/865100](https://developer.aliyun.com/article/865100)
18 | 220212_xgc_useSentinel使用sentinel: [学习链接:https://developer.aliyun.com/article/868693](https://developer.aliyun.com/article/868693)
19 | 220216_xgc_FeginAndSentinel优雅使用sentinelAndFegin: [学习链接:https://developer.aliyun.com/article/869702](https://developer.aliyun.com/article/869702)
20 | 220217_xgc_gateway使用网关: [学习链接: https://developer.aliyun.com/article/872251](https://developer.aliyun.com/article/872251)
21 | 220226_xgc_gatewayAndSentinel组合:[学习链接: https://developer.aliyun.com/article/872605](https://developer.aliyun.com/article/872605)
22 | 220301_xgc_Sleuth日志链路追踪:[学习链接: https://developer.aliyun.com/article/873463](https://developer.aliyun.com/article/873463)
23 | 220303_xgc_gatewayAndSatoken网关结合Sa-token进行登录鉴权:[学习链接: https://developer.aliyun.com/article/873849]( https://developer.aliyun.com/article/873849)
24 | 220310_xgc_useRocketMQ一文教你入门RocketMQ:[学习链接: https://developer.aliyun.com/article/875411](https://developer.aliyun.com/article/875411)
25 | 220311_xgc_rocketMQRocketMQ消息:[学习链接: https://developer.aliyun.com/article/876944](https://developer.aliyun.com/article/876944)
26 | 220321_xgc_seata分布式事务:[学习链接: https://developer.aliyun.com/article/879308](https://developer.aliyun.com/article/879308)
27 | 等待添加...
28 |
29 | ## Stars 趋势
30 |
31 |
32 | ## 交流
33 | 
34 | ### 捐助
35 | 
36 |
--------------------------------------------------------------------------------
/.idea/sonarlint/issuestore/index.pb:
--------------------------------------------------------------------------------
1 |
2 | v
3 | Fshop-product/src/main/java/com/ylesb/controller/ProductController.java,9\6\964333860ed7710b90af18a3617c2938c36fd048
4 | h
5 | 8shop-product/src/main/java/com/ylesb/dao/ProductDao.java,c\3\c32bcbe79fab5fe711f0ac6bc0ec73560e938cb9
6 | y
7 | Ishop-product/src/main/java/com/ylesb/service/Impl/ProductServiceImpl.java,f\1\f1ceb92f280498c317e09d71d67f185aadb300db
8 | d
9 | 4shop-commom/src/main/java/com/ylesb/domain/User.java,b\d\bd5dca7770f938d1891a0c35f2b240276bfc83f0
10 | p
11 | @shop-user/src/main/java/com/ylesb/controller/UserController.java,0\9\0928ba6e2cffe4166f5c3ab64de7bc445f4e208e
12 | b
13 | 2shop-user/src/main/java/com/ylesb/dao/UserDao.java,4\4\44f102bba6fc721245bab5489c88911a94f0d9f8
14 | j
15 | :shop-user/src/main/java/com/ylesb/service/UserService.java,f\d\fde9cddf8e62379d57406632ecad2295da6ad48c
16 | s
17 | Cshop-user/src/main/java/com/ylesb/service/Impl/UserServiceImpl.java,a\6\a603f92bc83d339cca3ff5b8808683fdfbd204da
18 | p
19 | @shop-product/src/main/java/com/ylesb/service/ProductService.java,3\0\3005242601e77842ac4e69cbb0073bdefe6d2c41
20 | s
21 | Cshop-order/src/main/java/com/ylesb/config/ExceptionHandlerPage.java,c\5\c57a7b84b73a7ab7efe5f6a77bc7e35d0f75e065
22 | r
23 | Bshop-order/src/main/java/com/ylesb/config/FilterContextConfig.java,1\1\11d4ae3540bd3ee68869159f2e91fa98a53fbca4
24 | d
25 | 4shop-order/src/main/java/com/ylesb/dao/OrderDao.java,2\1\213ee4e238faba65620cd36d566843b51fcd751f
26 | |
27 | Lshop-order/src/main/java/com/ylesb/config/RequestOriginParserDefinition.java,8\d\8dcbc6d61d26232e0f442a49e2e46de39769dd88
28 | n
29 | >shop-order/src/main/java/com/ylesb/config/SentinelPerFile.java,b\4\b4cc193d466ce22194f126a9e4779768cf29c0b6
30 |
31 | Oshop-order/src/main/java/com/ylesb/service/fallback/ProductServiceFallback.java,b\7\b7b1486670ebe9b83a0134a783045cf150feeecb
32 | D
33 | shop-product/pom.xml,7\8\78ddc04ca59e5d9a9bf2616d0ab76e288052194b
34 | h
35 | 8shop-order/src/main/java/com/ylesb/OrderApplication.java,9\4\949a8145879f31377e92fa7189f7355b89758bbf
36 | l
37 | shop-order/src/main/java/com/ylesb/service/ProductService.java,5\0\505008e8e4da7ea22194e15f2f6f20d7874b64fe
40 | r
41 | Bshop-order/src/main/java/com/ylesb/controller/OrderController.java,f\c\fc06f89e6644376351bb58592cb2386c11cd039b
42 | i
43 | 9shop-user/src/main/java/com/ylesb/service/SmsService.java,7\6\76552bdff6427451d79de118d894e3b79f082b94
44 | f
45 | 6shop-user/src/main/java/com/ylesb/UserApplication.java,2\7\2711291225762af7a6173841dfb254d5f722b4d3
46 | :
47 |
48 | .gitignore,a\5\a5cc2925ca8258af241be7e5b0381edf30266302
49 | t
50 | Dshop-order/src/main/java/com/ylesb/config/DataSourceProxyConfig.java,d\4\d4593357d8d309a987548bd0cd800b2446179a31
51 | l
52 | {
39 |
40 | //构造函数
41 | public AgeRoutePredicateFactory() {
42 | super(AgeRoutePredicateFactory.Config.class);
43 | }
44 | //读取配置文件参数,复制到哦配置类中
45 | @Override
46 | public List shortcutFieldOrder() {
47 | return Arrays.asList("minAge","maxAge");
48 | }
49 |
50 | @Override
51 | public Predicate apply(AgeRoutePredicateFactory.Config config) {
52 | return new Predicate() {
53 | /**
54 | * Evaluates this predicate on the given argument.
55 | *
56 | * @param serverWebExchange the input argument
57 | * @return {@code true} if the input argument matches the predicate,
58 | * otherwise {@code false}
59 | */
60 | @Override
61 | public boolean test(ServerWebExchange serverWebExchange) {
62 |
63 | //接收配置参数
64 | String ageStr = serverWebExchange.getRequest().getQueryParams().getFirst("age");
65 | //先判断是否为空
66 | if (StringUtils.isNotEmpty(ageStr)) {
67 | int age = Integer.parseInt(ageStr);
68 | if (age < config.getMaxAge() && age > config.getMinAge()) {
69 | return true;
70 | } else {
71 | return false;
72 | }
73 | }
74 | //在进行逻辑判断
75 | return false;
76 | }
77 | };
78 | }
79 |
80 | //配置类用于接收配置文件对应参数
81 | @Data
82 | //无参构造
83 | @NoArgsConstructor
84 | public static class Config {
85 | private int minAge;
86 | private int maxAge;
87 | }
88 | }
--------------------------------------------------------------------------------
/api-gateway/src/main/java/com/ylesb/config/GatewayConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.config;
2 | /**
3 | * @title: GatewayConfiguration
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1310:10
9 | */
10 |
11 | /**
12 | * @className : GatewayConfiguration
13 | * @description : [描述说明该类的功能]
14 | * @author : [XuGuangchao]
15 | * @site : [www.ylesb.com]
16 | * @version : [v1.0]
17 | * @createTime : [2022/1/13 10:10]
18 | * @updateUser : [XuGuangchao]
19 | * @updateTime : [2022/1/13 10:10]
20 | * @updateRemark : [描述说明本次修改内容]
21 | */
22 |
23 | import com.alibaba.csp.sentinel.adapter.gateway.common.SentinelGatewayConstants;
24 | import com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiDefinition;
25 | import com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiPathPredicateItem;
26 | import com.alibaba.csp.sentinel.adapter.gateway.common.api.ApiPredicateItem;
27 | import com.alibaba.csp.sentinel.adapter.gateway.common.api.GatewayApiDefinitionManager;
28 | import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayFlowRule;
29 | import com.alibaba.csp.sentinel.adapter.gateway.common.rule.GatewayRuleManager;
30 | import com.alibaba.csp.sentinel.adapter.gateway.sc.SentinelGatewayFilter;
31 | import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.BlockRequestHandler;
32 | import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.GatewayCallbackManager;
33 | import com.alibaba.csp.sentinel.adapter.gateway.sc.exception.SentinelGatewayBlockExceptionHandler;
34 | import org.springframework.beans.factory.ObjectProvider;
35 | import org.springframework.cloud.gateway.filter.GlobalFilter;
36 | import org.springframework.context.annotation.Bean;
37 | import org.springframework.context.annotation.Configuration;
38 | import org.springframework.core.Ordered;
39 | import org.springframework.core.annotation.Order;
40 | import org.springframework.http.HttpStatus;
41 | import org.springframework.http.MediaType;
42 | import org.springframework.http.codec.ServerCodecConfigurer;
43 | import org.springframework.web.reactive.function.BodyInserters;
44 | import org.springframework.web.reactive.function.server.ServerResponse;
45 | import org.springframework.web.reactive.result.view.ViewResolver;
46 | import org.springframework.web.server.ServerWebExchange;
47 | import reactor.core.publisher.Mono;
48 |
49 | import javax.annotation.PostConstruct;
50 | import java.util.*;
51 |
52 | @Configuration
53 | public class GatewayConfiguration {
54 |
55 | private final List viewResolvers;
56 | private final ServerCodecConfigurer serverCodecConfigurer;
57 |
58 | public GatewayConfiguration(ObjectProvider> viewResolversProvider,
59 | ServerCodecConfigurer serverCodecConfigurer) {
60 | this.viewResolvers = viewResolversProvider.getIfAvailable(Collections::emptyList);
61 | this.serverCodecConfigurer = serverCodecConfigurer;
62 | }
63 | //初始化限流过滤器
64 | @Bean
65 | @Order(Ordered.HIGHEST_PRECEDENCE)
66 | public GlobalFilter sentinelGatewayFilter() {
67 | return new SentinelGatewayFilter();
68 | }
69 | /**
70 | * 配置限流规则
71 | */
72 | @PostConstruct
73 | private void initGatewayRules() {
74 | //Set rules = new HashSet<>();
75 | //rules.add(new GatewayFlowRule("product_route")//资源名称对应的路由id
76 | // .setCount(1) // 限流阈值
77 | // .setIntervalSec(1) // 统计时间窗口,单位是秒,默认是 1 秒
78 | //);
79 | //GatewayRuleManager.loadRules(rules);
80 | Set rules = new HashSet<>();
81 | rules.add(new GatewayFlowRule("product_api1").setCount(1).setIntervalSec(1));
82 | rules.add(new GatewayFlowRule("product_api2").setCount(1).setIntervalSec(1));
83 | GatewayRuleManager.loadRules(rules);
84 | }
85 | //配置限流的异常处理器
86 | @Bean
87 | @Order(Ordered.HIGHEST_PRECEDENCE)
88 | public SentinelGatewayBlockExceptionHandler sentinelGatewayBlockExceptionHandler() {
89 | // Register the block exception handler for Spring Cloud Gateway.
90 | return new SentinelGatewayBlockExceptionHandler(viewResolvers, serverCodecConfigurer);
91 | }
92 | //自定义限流异常页面
93 | @PostConstruct
94 | public void initBlockHandlers() {
95 | BlockRequestHandler blockRequestHandler = new BlockRequestHandler(){
96 | @Override
97 | public Mono handleRequest(ServerWebExchange serverWebExchange, Throwable throwable) {
98 | Map map = new HashMap();
99 | map.put("code",0);
100 | map.put("messgae","接口被限流了...");
101 | return ServerResponse.status(HttpStatus.OK).contentType(MediaType.APPLICATION_JSON_UTF8).
102 | body(BodyInserters.fromObject(map));
103 | }
104 | };
105 | GatewayCallbackManager.setBlockHandler(blockRequestHandler);
106 | }
107 | //自定义API分组
108 | @PostConstruct
109 | private void initCustomizedApis() {
110 | Set definitions = new HashSet<>();
111 | ApiDefinition api1 = new ApiDefinition("product_api1")
112 | .setPredicateItems(new HashSet() {{
113 | ///product-serv/product/api1开头的请求
114 | add(new ApiPathPredicateItem().setPattern("/product-serv/product/api1/**")
115 | .setMatchStrategy(SentinelGatewayConstants.URL_MATCH_STRATEGY_PREFIX));
116 | }});
117 | ApiDefinition api2 = new ApiDefinition("product_api2")
118 | .setPredicateItems(new HashSet() {{
119 | ///product-serv/product/api2
120 | add(new ApiPathPredicateItem().setPattern("/product-serv/product/api2/demo1"));
121 | }});
122 | definitions.add(api1);
123 | definitions.add(api2);
124 | GatewayApiDefinitionManager.loadApiDefinitions(definitions);
125 | }
126 |
127 | }
128 |
--------------------------------------------------------------------------------
/shop-order/src/main/java/com/ylesb/config/SentinelPerFile.java:
--------------------------------------------------------------------------------
1 | package com.ylesb.config;
2 | /**
3 | * @title: SentinelPerFile
4 | * @projectName springcloud-alibaba
5 | * @description: TODO
6 | * @author White
7 | * @site : [www.ylesb.com]
8 | * @date 2022/1/1216:15
9 | */
10 |
11 | import com.alibaba.csp.sentinel.command.handler.ModifyParamFlowRulesCommandHandler;
12 | import com.alibaba.csp.sentinel.datasource.*;
13 | import com.alibaba.csp.sentinel.init.InitFunc;
14 | import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRule;
15 | import com.alibaba.csp.sentinel.slots.block.authority.AuthorityRuleManager;
16 | import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
17 | import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager;
18 | import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
19 | import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
20 | import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRule;
21 | import com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowRuleManager;
22 | import com.alibaba.csp.sentinel.slots.system.SystemRule;
23 | import com.alibaba.csp.sentinel.slots.system.SystemRuleManager;
24 | import com.alibaba.csp.sentinel.transport.util.WritableDataSourceRegistry;
25 | import com.alibaba.fastjson.JSON;
26 | import com.alibaba.fastjson.TypeReference;
27 | import org.springframework.beans.factory.annotation.Value;
28 |
29 | import java.io.File;
30 | import java.io.IOException;
31 | import java.util.List;
32 |
33 | /**
34 | * @className : SentinelPerFile
35 | * @description : [描述说明该类的功能]
36 | * @author : [XuGuangchao]
37 | * @site : [www.ylesb.com]
38 | * @version : [v1.0]
39 | * @createTime : [2022/1/12 16:15]
40 | * @updateUser : [XuGuangchao]
41 | * @updateTime : [2022/1/12 16:15]
42 | * @updateRemark : [描述说明本次修改内容]
43 | */
44 | //持久化到本地
45 | public class SentinelPerFile implements InitFunc {
46 |
47 | @Value("spring.application.name")
48 | private String applicationName;
49 | @Override
50 | public void init() throws Exception {
51 | String ruleDir = System.getProperty("user.home") + "/sentinel/rules/"+applicationName;
52 | String flowRulePath = ruleDir + "/flow-rule.json";
53 | String degradeRulePath = ruleDir + "/degrade-rule.json";
54 | String systemRulePath = ruleDir + "/system-rule.json";
55 | String authorityRulePath = ruleDir + "/authority-rule.json";
56 | String paramFlowRulePath = ruleDir + "/param-flow-rule.json";
57 |
58 | this.mkdirIfNotExits(ruleDir);
59 | this.createFileIfNotExits(flowRulePath);
60 | this.createFileIfNotExits(degradeRulePath);
61 | this.createFileIfNotExits(systemRulePath);
62 | this.createFileIfNotExits(authorityRulePath);
63 | this.createFileIfNotExits(paramFlowRulePath);
64 |
65 | // 注册一个可读数据源,用来定时读取本地的json文件,更新到规则缓存中
66 | // 流控规则
67 | ReadableDataSource> flowRuleRDS =
68 | new FileRefreshableDataSource<>(flowRulePath, flowRuleListParser);
69 | // 将可读数据源注册至FlowRuleManager
70 | // 这样当规则文件发生变化时,就会更新规则到内存
71 | FlowRuleManager.register2Property(flowRuleRDS.getProperty());
72 | WritableDataSource> flowRuleWDS = new FileWritableDataSource<>(
73 | flowRulePath,
74 | this::encodeJson
75 | );
76 | // 将可写数据源注册至transport模块的WritableDataSourceRegistry中
77 | // 这样收到控制台推送的规则时,Sentinel会先更新到内存,然后将规则写入到文件中
78 | WritableDataSourceRegistry.registerFlowDataSource(flowRuleWDS);
79 |
80 | // 降级规则
81 | ReadableDataSource> degradeRuleRDS = new FileRefreshableDataSource<>(
82 | degradeRulePath,
83 | degradeRuleListParser
84 | );
85 | DegradeRuleManager.register2Property(degradeRuleRDS.getProperty());
86 | WritableDataSource> degradeRuleWDS = new FileWritableDataSource<>(
87 | degradeRulePath,
88 | this::encodeJson
89 | );
90 | WritableDataSourceRegistry.registerDegradeDataSource(degradeRuleWDS);
91 |
92 | // 系统规则
93 | ReadableDataSource> systemRuleRDS = new FileRefreshableDataSource<>(
94 | systemRulePath,
95 | systemRuleListParser
96 | );
97 | SystemRuleManager.register2Property(systemRuleRDS.getProperty());
98 | WritableDataSource> systemRuleWDS = new FileWritableDataSource<>(
99 | systemRulePath,
100 | this::encodeJson
101 | );
102 | WritableDataSourceRegistry.registerSystemDataSource(systemRuleWDS);
103 |
104 | // 授权规则
105 | ReadableDataSource> authorityRuleRDS = new FileRefreshableDataSource<>(
106 | authorityRulePath,
107 | authorityRuleListParser
108 | );
109 | AuthorityRuleManager.register2Property(authorityRuleRDS.getProperty());
110 | WritableDataSource> authorityRuleWDS = new FileWritableDataSource<>(
111 | authorityRulePath,
112 | this::encodeJson
113 | );
114 | WritableDataSourceRegistry.registerAuthorityDataSource(authorityRuleWDS);
115 |
116 | // 热点参数规则
117 | ReadableDataSource> paramFlowRuleRDS = new FileRefreshableDataSource<>(
118 | paramFlowRulePath,
119 | paramFlowRuleListParser
120 | );
121 | ParamFlowRuleManager.register2Property(paramFlowRuleRDS.getProperty());
122 | WritableDataSource> paramFlowRuleWDS = new FileWritableDataSource<>(
123 | paramFlowRulePath,
124 | this::encodeJson
125 | );
126 | ModifyParamFlowRulesCommandHandler.setWritableDataSource(paramFlowRuleWDS);
127 | }
128 |
129 | private Converter> flowRuleListParser = source -> JSON.parseObject(
130 | source,
131 | new TypeReference>() {
132 | }
133 | );
134 | private Converter> degradeRuleListParser = source -> JSON.parseObject(
135 | source,
136 | new TypeReference>() {
137 | }
138 | );
139 | private Converter> systemRuleListParser = source -> JSON.parseObject(
140 | source,
141 | new TypeReference>() {
142 | }
143 | );
144 |
145 | private Converter> authorityRuleListParser = source -> JSON.parseObject(
146 | source,
147 | new TypeReference>() {
148 | }
149 | );
150 |
151 | private Converter> paramFlowRuleListParser = source -> JSON.parseObject(
152 | source,
153 | new TypeReference>() {
154 | }
155 | );
156 |
157 | private void mkdirIfNotExits(String filePath) throws IOException {
158 | File file = new File(filePath);
159 | if (!file.exists()) {
160 | file.mkdirs();
161 | }
162 | }
163 |
164 | private void createFileIfNotExits(String filePath) throws IOException {
165 | File file = new File(filePath);
166 | if (!file.exists()) {
167 | file.createNewFile();
168 | }
169 | }
170 |
171 | private String encodeJson(T t) {
172 | return JSON.toJSONString(t);
173 | }
174 |
175 | }
--------------------------------------------------------------------------------
/.idea/uiDesigner.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | -
6 |
7 |
8 | -
9 |
10 |
11 | -
12 |
13 |
14 | -
15 |
16 |
17 | -
18 |
19 |
20 |
21 |
22 |
23 | -
24 |
25 |
26 |
27 |
28 |
29 | -
30 |
31 |
32 |
33 |
34 |
35 | -
36 |
37 |
38 |
39 |
40 |
41 | -
42 |
43 |
44 |
45 |
46 | -
47 |
48 |
49 |
50 |
51 | -
52 |
53 |
54 |
55 |
56 | -
57 |
58 |
59 |
60 |
61 | -
62 |
63 |
64 |
65 |
66 | -
67 |
68 |
69 |
70 |
71 | -
72 |
73 |
74 | -
75 |
76 |
77 |
78 |
79 | -
80 |
81 |
82 |
83 |
84 | -
85 |
86 |
87 |
88 |
89 | -
90 |
91 |
92 |
93 |
94 | -
95 |
96 |
97 |
98 |
99 | -
100 |
101 |
102 | -
103 |
104 |
105 | -
106 |
107 |
108 | -
109 |
110 |
111 | -
112 |
113 |
114 |
115 |
116 | -
117 |
118 |
119 | -
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------