当前位置:网站首页>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
边栏推荐
- rpm install postgresql12
- rpm安装postgresql12
- 软件测试缺陷报告---定义,组成,缺陷的生命周期,缺陷跟踪产后处理流程,缺陷跟踪处理流程,缺陷跟踪的目的,缺陷管理工具
- The difference between 4G communication module CAT1 and CAT4
- Nacos
- Shell 脚本循环遍历日志文件中的值进行求和并计算平均值,最大值和最小值
- 一个无经验的大学毕业生,可以转行做软件测试吗?我的真实案例
- "Actual Combat" based on part-of-speech extraction in the field of e-commerce and its decision tree model modeling
- 计算S=a+aa+…+aa…a
- 【flask入门系列】Flask-SQLAlchemy的使用
猜你喜欢
随机推荐
Overview of prometheus monitoring
想要写出好的测试用例,先要学会测试设计
【网络安全】文件上传靶场通关(1-11关)
[WeChat applet] This article takes you to understand data binding, event binding, event parameter transfer, and data synchronization
The difference between 4G communication module CAT1 and CAT4
小黑leetcode之旅:104. 二叉树的最大深度
Teach you how to configure Jenkins automated email notifications
Dispatch Center xxl-Job
The sword refers to offer17---print the n digits from 1 to the largest
coldfusion8后台计划任务拿shell
软件测试工作3年了,谈谈我是如何从刚入门进阶到自动化测试的?
MySQL (6)
蓝牙mesh系统开发二 mesh节点开发
link与@import的区别
Know what DTU is 4GDTU equipment
蛮力法/邻接表 广度优先 有向带权图 无向带权图
android的webview缓存相关知识收集
pycharm重命名后无法运行(报错: can‘t open file......No such file or directory)
什么是理想的大学生活?
keep-alive缓存组件









