In-depth understanding of Spring Cloud and microservice construction_reading notes
- related resources
- Chapter 7 Declaratively Calling Feign
- Chapter 9 Routing Gateway Spring Cloud Zuul
- Chapter 15 Using Spring Security OAuth2 and JWT to Protect the Microservice System
- Chapter 16 Using Spring Cloud to Build a Comprehensive Case of Microservices
-
- 16.1 Case introduction
- 16.2 Detailed case
- 16.3 Start source code project
- 16.4 Project Demo
- 16.5 Summary
related resources
In-depth understanding of Spring Cloud and microservices to build book source code
Chapter 7 Declaratively Calling Feign
7.1 Write a Feign client
7.2 FeignClient detailed explanation
7.3 FeignClient configuration
7.4 Explain the working principle of Feign from the perspective of source code
7.5 Use HttpClient and OkHttp in Feign
7.6 How Feign achieves load balancing
7.7 Summary
Chapter 9 Routing Gateway Spring Cloud Zuul
9.1 Why Zuul is needed
9.2 How Zuul works
9.3 Actual case
9.3.1 Set up Zuul service
9.3.2 Configure the port number of the API interface on Zuul
9.3.3 Configure fuses on Zuul
9.3.4 Using filters on Zuul
9.3.5 Common ways to use Zuul
Chapter 15 Using Spring Security OAuth2 and JWT to Protect the Microservice System
15.1 Introduction to JWT
15.1.1 What is JWT
15.1.2 JWT structure
15.1.3 Application Scenarios of JWT
15.1.4 How to use JWT
15.2 Case Analysis
15.2.1 Case Architecture Design
15.2.2 Writing the main Maven project
15.2.3 Writing eureka-server
15.2.4 Write uaa authorization service
1. Introduce dependencies
2. Configuration file
3. Configure Spring Security
4. 配置 Authorization Server
5. Generate jks file
15.2.5 Write user-service resource service
1. Rely on management pom file
2. Configuration file application.yml
3. Configure Resource Server
4. Configure Spring Security
5. Write user registration interface
6. Write user login interface
7. Testing
15.3 Summary
Chapter 16 Using Spring Cloud to Build a Comprehensive Case of Microservices
16.1 Case introduction
16.2 Detailed case
16.2.1 Preparation
16.2.2 Build the main Maven project
16.2.3 Building eureka-server project
eureka-server-service registry
16.3 Start source code project
1. Preparation
Operating environment
- jdk1.8.0_231
- SpringBoot 1.5.3
- SpringCloud Dalston.RELEASE
- maven-3.6.3
- MySQL 5.7.31-log
- RabbitMQ 3.7.8
a. Maven association
If in IDEA, the modules under chapter16 of the project are not correctly identified by Maven and the dependencies are established, Maven must be refreshed first so that the dependencies of each module are imported normally. The specific operations are as follows:
b. Database operations
2. Start eureka-server
After compile is completed, the target directory will be generated in the eureka-server module. The target directory is the directory where the various classes and configuration files generated after eureka-server are compiled;
running the eureka-server directory, the effect is as follows:
3. Start config-server
4. Start zipkin-service
Note that the configuration file is the src/main/resources/shared/zipkin-service-pro.yml file of the config-server project.
5. Start monitoring-service
Note that the configuration file is the src/main/resources/shared/monitor-service-pro.yml file of the config-server project.
6. Start uaa-service
Note that the configuration file is the src/main/resources/shared/uaa-service-pro.yml file of the config-server project.
Note that the uaa-service project is connected to the sys-user database, pay attention to its database configuration;
7. Start gateway-service
Note that the configuration file is the src/main/resources/shared/gateway-service-pro.yml file of the config-server project.
8. Start admin-service
Note that the configuration file is the src/main/resources/shared/gateway-service-pro.yml file of the config-server project.
9. Compile and install common-service
10. Start user-service
11. Start blog-service
12. Start log-service
16.4 Project Demo
Create a user
curl -X POST --header 'Content-Type:application/json' --header 'Accept:application/json' -d '{"password":"123456","username":"gongxf"}' 'http://localhost:5000/userapi/user/registry'
{
"id":2,"username":"gongxf","password":"$2a$10$oEq9i6FWmvqqK0PXodkf5O.QtvzJkrVXoN9HENNgosK8PvX7uMT8y"}
Log in with the created user
curl -X POST --header 'Content-Type:application/json' --header 'Accept:application/json' 'http://localhost:5000/userapi/user/login?username=gongxf&password=123456'
{
"code":0,"error":"","data":{
"user":{
"id":2,"username":"gongxf","password":"$2a$10$oEq9i6FWmvqqK0PXodkf5O.QtvzJkrVXoN9HENNgosK8PvX7uMT8y"},"token":"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MDAwNjYyNDMsInVzZXJfbmFtZSI6Imdvbmd4ZiIsImp0aSI6IjhkYjVhMzRhLTRlYjctNGM1My1iODliLTU3MzQ3YmJiYzZlZiIsImNsaWVudF9pZCI6InVhYS1zZXJ2aWNlIiwic2NvcGUiOlsic2VydmljZSJdfQ.FQLWlmwui6FS5XyjzwR0TKij72taJHLbLoQiQy9_n_YaCRyKNEVwUy7TYppYF9Qn6mghSGSKUONgH1IMLsJXwsbiSH_neR_-y1SQeYbqcZaacjuMt5QRnFzCK-MvnvoNUzNVX8TG9xEwQDIdli_7OtyGNlDnwqa4x7Zy2bfBX5Rj0XLpLsRZXXb09FUgLYA_HTprJR5w--GB25Oe-L0SfOqBeb5KEcpdI-d31FUGZR0R8spi8zFFGqhvoYwnjQUrNQ1GhKLQ2QL2CcRMUqkl2IMdDNt0cxWX95Abqm3use5YWVemKKjcn2H_OcEg1DvOFh0rKY59kdbnEYb8mtfdNA"}}