当前位置:网站首页>Gateway routing configuration
Gateway routing configuration
2022-07-31 01:43:00 【Yangtze river snow】
Route configuration
- Basic routing configuration
- Code-based routing configuration
- Routing configuration combined with registry
Routing is the basic module of gateway configuration, similar to Zuul's routing configuration module.A Route module is defined by an ID, a target URI, a set of assertions, and a set of filters.If the assertion is true, the route matches and the target URI is accessed.
Basic routing configuration
If the target address of the request is a single URI resource path, the configuration file example is as follows.
spring:application:name: api-gatewaycloud:gateway:routes:- id: service1uri: https://blog.csdn.netpredicates:-Path=/csdn
The meaning of each field is as follows.
- id: our custom routing ID, keep it unique
- uri: target service address
- predicates: routing conditions, Predicate accepts an input parameter and returns a boolean result.The interface contains several default methods to combine Predicates into other complex logic (eg: AND, OR, NOT).
The above configuration means that a URI proxy rule with an id of url-proxy-1 is configured. The routing rule is that when the address http://localhost:8080/csdn is accessed, it will be routed to the address https://blog.csdn.net.
Code-based routing configuration
The forwarding function can also be implemented by code. We can add the method customRouteLocator() in the startup class GateWayApplication to customize the forwarding rules.
@[email protected] class GatewayApplication {public static void main(String[] args) {SpringApplication.run(GatewayApplication.class, args);}@Beanpublic RouteLocator customRouteLocator(RouteLocatorBuilder builder) {return builder.routes().route("path_route", r -> r.path("/csdn").uri("https://blog.csdn.net")).build();}}
Routing configuration method combined with registry
The schema protocol part of the uri is a custom lb: type, which means that the service is subscribed from the microservice registry (such as Eureka), and the service is routed through load balancing.code show as below.
server:port: 8080spring:application:name: api-gatewaycloud:gateway:routes:- id: service1# uri: http://127.0.0.1:9001uri: lb://cloud-payment-servicepredicates:- Path=/payment/**eureka:client:service-url:defaultZone: http://127.0.0.1:9004/eureka
Note: Here cloud-payment-service is a pre-registered service, and two ports 9000 and 9001 are open for use.
The routing configuration method combined with the registry is actually very different from the routing configuration of a single URI, only the schema protocol of the URI is different.The schema protocol of the address of a single URI, usually the http or https protocol.Start multiple payment microservices, and you will find that ports 9000 and 9001 appear in turn.
Let me introduce myself first. The editor graduated from Shanghai Jiaotong University in 2013. I worked in a small company and went to big factories such as Huawei and OPPO. I joined Alibaba in 2018, until now.I know that most junior and intermediate java engineers want to upgrade their skills, they often need to explore their own growth or sign up to study, but for training institutions, the tuition fee is nearly 10,000 yuan, which is really stressful.Self-learning that is not systematic is very inefficient and lengthy, and it is easy to hit the ceiling and the technology stops.Therefore, I collected a copy of "a complete set of learning materials for java development" for everyone. The original intention is also very simple. I hope to help friends who want to learn by themselves but don't know where to start, and at the same time reduce everyone's burden.Add the business card below to get a full set of learning materials
边栏推荐
- Basic Parameters of RF Devices 2
- Crawler text data cleaning
- 《实战》基于情感词典的文本情感分析与LDA主题分析
- The Meta Metaverse Division lost 2.8 billion in the second quarter, still want to continue to bet?Metaverse development has yet to see a way out
- 软件测试要达到一个什么水平才能找到一份9K的工作?
- pycharm重命名后无法运行(报错: can‘t open file......No such file or directory)
- Chi-square distribution of digital image steganography
- 【flask入门系列】Flask-SQLAlchemy的使用
- 斩获BAT、TMD技术专家Offer,我都经历了什么?
- MySql的初识感悟,以及sql语句中的DDL和DML和DQL的基本语法
猜你喜欢
关于Redis相关内容的基础学习
Google官方控件ShapeableImageView使用
两个有序数组间相加和的Topk问题
VSCode插件:嵌套注释
"Real" emotions dictionary based on the text sentiment analysis and LDA theme analysis
pycharm cannot run after renaming (error: can't open file...No such file or directory)
GCC Rust is approved to be included in the mainline code base, or will meet you in GCC 13
Multiplication, DFS order
Basic Parameters of RF Devices 1
斩获BAT、TMD技术专家Offer,我都经历了什么?
随机推荐
计算S=a+aa+…+aa…a
prometheus 监控概述
JPEG Steganalysis of Digital Image Steganography
934. 最短的桥
System design. Short chain system design
Mysql:Invalid default value for TIMESTAMP
《实战》基于情感词典的文本情感分析与LDA主题分析
TiCDC 架构和数据同步链路解析
leetcode-1161:最大层内元素和
Dispatch Center xxl-Job
4G通信模块CAT1和CAT4的区别
初识C语言 -- 数组
成为比开发硬气的测试人,我都经历了什么?
case语句的综合结果,你究竟会了吗?【Verilog高级教程】
【genius_platform软件平台开发】第七十四讲:window环境下的静态库和动态库的一些使用方法(VC环境)
C语言_结构体指针数组函数选票系统
Chi-square distribution of digital image steganography
PDF split/merge
Crawler text data cleaning
【网络安全】文件上传靶场通关(1-11关)