当前位置:网站首页>Gateway-88
Gateway-88
2022-07-01 08:19:00 【Butterfly clothes_ crazy】
Dynamic up and down line : To send a request, you need to know the address of the goods and services , If the product server has 1,2,3 Number server ,1 Number
After dropping the line , It has to be changed, So we need toGateway dynamically manages, He can sense whether a service is online or offline in real time from the registry . The gateway can always help us route requests to the specified location correctly 【 Go through the gateway first , The gateway routes to the service provider 】
The second demand :
authentication 、 monitor; If every service does , There will be a lot of repeated development

The client requests the gateway first , And then the gateway transfers it to other services


Performance comparison
Intercept : The request should also be added with query permission , See if the user has access to the request , You also need gateways .
So we use spring cloud Of gateway Components do gateway functions .
The gateway is the gateway to request traffic , Common functions include Routing and forwarding , Permission to check , Current limiting control etc. .springcloud gateway To replace the zuul gateway .
https://spring.io/projects/spring-cloud-gateway
Reference manual :https://cloud.spring.io/spring-cloud-gateway/2.2.x/reference/html/
Three core concepts :
Route: The basic building block of the gateway. It is defined by an ID, a destination URI, a collection of predicates Assertion , and a collection of filters. A route is matched if the aggregate predicate is true. Send a request to the gateway , The gateway routes the request to the specified service . Routing has id, Destination uri, A collection of assertions , Match the assertion to reach the specified location ,( The route has an identifier id, Between routes by id To distinguish between . A collection of assertions :, A collection of filters :, As long as the route matches the assertion , The assertion is true , The route matches , Can reach the designated position , Request for issue API gateway , Whether to route to one place or not , We have to have a conditional judgment , This conditional judgment is assertion )
Predicate Assertion : This is a Java 8 Function Predicate. The input type is a Spring Framework ServerWebExchange. This lets you match on anything from the HTTP request, such as headers or parameters. Namely java8 Assertion function in , Match any information in the current request , Including requesting first class . Which service is routed according to the request header
Filter: These are instances of Spring Framework GatewayFilter that have been constructed with a specific factory. Here, you can modify requests and responses before or after sending the downstream request. Filter requests and responses can be modified .
The client sends the request to the server . There is a gateway in the middle . Give it to the mapper first , If you can handle it, give it to handler Handle , Then give it to a series of filer, Then give it to the specified service , Then return to the client .

To sum up : Request arrival
gateway,Gateway assertion, Whether the request conforms to aThe rules, If meet , Just follow this routing rule , Route to the specified place , The journey to the designated place requires a series ofFilter. All the difficulties : How do we define routing rules , How do assertions determine success or failure , How to configure , What to use filter I have to be clear in my heart
The function of assertion : Satisfy the assertion condition 3, Just assign to the route 2
There are many assertions .
spring:
cloud:
gateway:
routes:
- id: after_route
uri: https://example.org
predicates:
- Cookie=mycookie,mycookievalue
- Representative array , You can set Cookie The content such as . Only the assertion succeeds , To the specified address .
spring:
cloud:
gateway:
routes:
- id: after_route
uri: https://example.org
predicates:
- name: Cookie
args:
name: mycookie
regexp: mycookievalue
Create microservices , Use initilizer,Group:com.atguigu.gulimall,Artifact: gulimall-gateway,package:com.atguigu.gulimall.gateway. Search for
gatewayChoose .
pom.xml Riga common rely on , modify jdk edition ,
stay
gatewayStart the registration service discovery in the service@EnableDiscoveryClient, To configurenacosAddress of Registration Centerapplicaion.properties. such gateway Also registered to nacos in , Other services can be found nacos, The gateway can also pass through nacos Find other services
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
spring.application.name=gulimall-gateway
server.port=88
bootstrap.properties Fill in nacos Configure center address
spring.application.name=gulimall-gateway
spring.cloud.nacos.config.server-addr=127.0.0.1:8848
spring.cloud.nacos.config.namespace=bfa85f10-1a9a-460c-a7dc-efa961b45cc1
This project is in nacos Service name in
spring:
application:
name: gulimall-gateway
Go again nacos Create a namespace in gateway( Projects are separated from projects by namespaces ), Then create a file in the namespace guilmall-gateway.yml
Create... In the project application.yml, Forward to uri etc.
spring:
cloud:
gateway:
routes:
- id: test_route
uri: https://www.baidu.com
predicates:
- Query=url,baidu
- id: qq_route
uri: https://www.qq.com
predicates:
- Query=url,qq
- id: product_route
uri: lb://gulimall-product
predicates:
- Path=/api/product/**
filters:
- RewritePath=/api/(?<segment>.*),/$\{
segment}
- id: third_party_route
uri: lb://gulimall-third-party
predicates:
- Path=/api/thirdparty/**
filters:
- RewritePath=/api/thirdparty/(?<segment>.*),/$\{
segment}
- id: member_route
uri: lb://gulimall-member
predicates:
- Path=/api/member/**
filters:
- RewritePath=/api/(?<segment>.*),/$\{
segment}
- id: ware_route
uri: lb://gulimall-ware
predicates:
- Path=/api/ware/**
filters:
- RewritePath=/api/(?<segment>.*),/$\{
segment}
- id: admin_route
uri: lb://renren-fast
predicates:
- Path=/api/**
filters: # This filter is related to the verification code ,api Content Cache /renren-fast, And pay attention to /renren-fast Also registered to nacos in
- RewritePath=/api/(?<segment>.*),/renren-fast/$\{
segment}
## The front-end project ,/api Prefix . First come to the gateway and then assert to match , Filter modification url, Like jump to renren Microservices , So pay attention to renren Back end projects are also registered to nacos in
## http://localhost:88/api/captcha.jpg http://localhost:8080/renren-fast/captcha.jpg
## http://localhost:88/api/product/category/list/tree http://localhost:10000/product/category/list/tree
test localhost:8080/hello?url=baidu
The gateway uses Netty,Netty Than Tomcat High performance
2021-12-31 16:20:37.276 INFO 19364 --- [ main] o.s.b.web.embedded.netty.NettyWebServer : Netty started on port(s): 88
predicates:
- Query=url(key),baidu(value)
边栏推荐
- Chinese font Gan: zi2zi
- 軟鍵盤高度報錯
- Erreur de hauteur du clavier souple
- 【入门】输入整型数组和排序标识,对其元素按照升序或降序进行排序
- Luogu p1088 [noip2004 popularization group] Martians
- OJ input and output exercise
- 【Redis】一气呵成,带你了解Redis安装与连接
- 如何招到适合自己店铺的淘宝主播
- Learn reptiles for a month and earn 6000 a month? Tell you the truth about the reptile, netizen: I wish I had known it earlier
- 5大组合拳,解决校园6大难题,护航教育信息化建设
猜你喜欢

Conception et mise en service du processeur - chapitre 4 tâches pratiques

Burpsuite -- brute force cracking of intruder

SharePoint - modify web application authentication using PowerShell
![[website architecture] solve 90% of distributed transactions in one move, and introduce the working principles and application scenarios of database transactions and distributed transactions](/img/2c/07d729d49b1d74553decac4588074e.png)
[website architecture] solve 90% of distributed transactions in one move, and introduce the working principles and application scenarios of database transactions and distributed transactions

5大组合拳,解决校园6大难题,护航教育信息化建设
![[question brushing] character statistics [0]](/img/cc/f5aaecd920c502180303d92447e54f.png)
[question brushing] character statistics [0]

The Windows C disk is full

web254

使用 setoolkit 伪造站点窃取用户信息

Adding color blocks to Seaborn clustermap matrix
随机推荐
Using settoolkit to forge sites to steal user information
Thread safety analysis of [concurrent programming JUC] variables
The Windows C disk is full
Gdip - hatchbrush pattern table
The difference between interceptors and filters
How can beginners correctly understand Google's official suggested architectural principles (questions?)
使用 setoolkit 伪造站点窃取用户信息
Practice and Thinking on the architecture of a set of 100000 TPS im integrated message system
Data analysis notes 11
empirical study and case study
How to troubleshoot SharePoint online map network drive failure?
Contenttype comparison of all types
Leetcode T34: 在排序数组中查找元素的第一个和最后一个位置
Insufficient executors to build thread pool
Luogu p3799 demon dream stick
Provincial election + noi part I dynamic planning DP
一套十万级TPS的IM综合消息系统的架构实践与思考
Connect timed out of database connection
Day5: scanner object, next() and nextline(), sequential structure, selection structure, circular structure
初学者如何正确理解google官方建议架构原则(疑问?)

