当前位置:网站首页>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=/csdnThe 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/eurekaNote: 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
边栏推荐
- link与@import的区别
- Kyushu cloud as cloud computing standardization excellent member unit
- TiKV主要内存结构和OOM排查总结
- Xiaohei's leetcode journey: 117. Fill the next right node pointer of each node II
- keep-alive缓存组件
- MySQL的分页你还在使劲的limit?
- Are you still working hard on the limit of MySQL paging?
- Mysql:Invalid default value for TIMESTAMP
- .NET 跨平台应用开发动手教程 |用 Uno Platform 构建一个 Kanban-style Todo App
- 射频器件的基本参数1
猜你喜欢

Shell变量与赋值、变量运算、特殊变量

《实战》基于情感词典的文本情感分析与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

MySql的安装配置超详细教程与简单的建库建表方法

16、注册中心-consul

《云原生的本手、妙手和俗手》——2022全国新高考I卷作文

Bert usage and word prediction based on Keras_bert model

C语言_结构体指针数组函数选票系统

小黑leetcode之旅:104. 二叉树的最大深度

Interprocess communication study notes
随机推荐
ROS Action通信
pc端判断当前使用浏览器类型
TiDB之rawkv升级之路v5.0.4-->v6.1.0
聚簇索引和非聚簇索引到底有什么区别
leetcode-952:按公因数计算最大组件大小
case语句的综合结果,你究竟会了吗?【Verilog高级教程】
Jiuzhou Cloud was selected into the "Trusted Cloud's Latest Evaluation System and the List of Enterprises Passing the Evaluation in 2022"
Know what DTU is 4GDTU equipment
关于Redis相关内容的基础学习
Nacos
一个无经验的大学毕业生,可以转行做软件测试吗?我的真实案例
4G通信模块CAT1和CAT4的区别
.NET 跨平台应用开发动手教程 |用 Uno Platform 构建一个 Kanban-style Todo App
蓝牙mesh系统开发三 Ble Mesh 配网器 Provisioner
射频器件的基本参数1
软件测试缺陷报告---定义,组成,缺陷的生命周期,缺陷跟踪产后处理流程,缺陷跟踪处理流程,缺陷跟踪的目的,缺陷管理工具
The PC side determines the type of browser currently in use
软件测试要达到一个什么水平才能找到一份9K的工作?
link与@import的区别
Basic Parameters of RF Devices 2